@udixio/theme 1.0.0-beta.10

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 (100) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +73 -0
  3. package/dist/app.container.d.ts +5 -0
  4. package/dist/app.module.d.ts +2 -0
  5. package/dist/app.service.d.ts +13 -0
  6. package/dist/color/color.interface.d.ts +8 -0
  7. package/dist/color/color.module.d.ts +2 -0
  8. package/dist/color/entities/color.entity.d.ts +42 -0
  9. package/dist/color/entities/index.d.ts +1 -0
  10. package/dist/color/index.d.ts +5 -0
  11. package/dist/color/models/default-color.model.d.ts +3 -0
  12. package/dist/color/models/index.d.ts +1 -0
  13. package/dist/color/services/color-manager.service.d.ts +18 -0
  14. package/dist/color/services/color.service.d.ts +21 -0
  15. package/dist/color/services/index.d.ts +2 -0
  16. package/dist/config/config.interface.d.ts +13 -0
  17. package/dist/config/config.module.d.ts +2 -0
  18. package/dist/config/config.service.d.ts +12 -0
  19. package/dist/config/index.d.ts +3 -0
  20. package/dist/index.d.ts +11 -0
  21. package/dist/index.js +8 -0
  22. package/dist/main.d.ts +3 -0
  23. package/dist/material-color-utilities/contrastCurve.d.ts +46 -0
  24. package/dist/material-color-utilities/dynamic_color.d.ts +171 -0
  25. package/dist/material-color-utilities/index.d.ts +3 -0
  26. package/dist/material-color-utilities/toneDeltaPair.d.ts +60 -0
  27. package/dist/plugin/index.d.ts +3 -0
  28. package/dist/plugin/plugin.abstract.d.ts +6 -0
  29. package/dist/plugin/plugin.module.d.ts +2 -0
  30. package/dist/plugin/plugin.service.d.ts +10 -0
  31. package/dist/plugins/tailwind/Tailwind.plugin.d.ts +14 -0
  32. package/dist/plugins/tailwind/index.d.ts +3 -0
  33. package/dist/plugins/tailwind/main.d.ts +10 -0
  34. package/dist/plugins/tailwind/plugins-tailwind/index.d.ts +2 -0
  35. package/dist/plugins/tailwind/plugins-tailwind/state.d.ts +4 -0
  36. package/dist/plugins/tailwind/plugins-tailwind/themer.d.ts +4 -0
  37. package/dist/theme/entities/index.d.ts +2 -0
  38. package/dist/theme/entities/scheme.entity.d.ts +15 -0
  39. package/dist/theme/entities/variant.entity.d.ts +7 -0
  40. package/dist/theme/index.d.ts +4 -0
  41. package/dist/theme/models/index.d.ts +1 -0
  42. package/dist/theme/models/variant.model.d.ts +8 -0
  43. package/dist/theme/services/index.d.ts +3 -0
  44. package/dist/theme/services/scheme.service.d.ts +17 -0
  45. package/dist/theme/services/theme.service.d.ts +22 -0
  46. package/dist/theme/services/variant.service.d.ts +13 -0
  47. package/dist/theme/theme.module.d.ts +2 -0
  48. package/dist/theme.cjs.development.js +2193 -0
  49. package/dist/theme.cjs.development.js.map +1 -0
  50. package/dist/theme.cjs.production.min.js +2 -0
  51. package/dist/theme.cjs.production.min.js.map +1 -0
  52. package/dist/theme.esm.js +2157 -0
  53. package/dist/theme.esm.js.map +1 -0
  54. package/package.json +95 -0
  55. package/src/app.container.ts +46 -0
  56. package/src/app.module.ts +7 -0
  57. package/src/app.service.spec.ts +15 -0
  58. package/src/app.service.ts +23 -0
  59. package/src/color/color.interface.ts +13 -0
  60. package/src/color/color.module.ts +9 -0
  61. package/src/color/entities/color.entity.ts +71 -0
  62. package/src/color/entities/index.ts +1 -0
  63. package/src/color/index.ts +5 -0
  64. package/src/color/models/default-color.model.ts +300 -0
  65. package/src/color/models/index.ts +1 -0
  66. package/src/color/services/color-manager.service.ts +191 -0
  67. package/src/color/services/color.service.spec.ts +28 -0
  68. package/src/color/services/color.service.ts +75 -0
  69. package/src/color/services/index.ts +2 -0
  70. package/src/config/config.interface.ts +14 -0
  71. package/src/config/config.module.ts +7 -0
  72. package/src/config/config.service.ts +74 -0
  73. package/src/config/index.ts +3 -0
  74. package/src/index.ts +11 -0
  75. package/src/main.ts +14 -0
  76. package/src/material-color-utilities/contrastCurve.ts +63 -0
  77. package/src/material-color-utilities/dynamic_color.ts +450 -0
  78. package/src/material-color-utilities/index.ts +3 -0
  79. package/src/material-color-utilities/toneDeltaPair.ts +64 -0
  80. package/src/plugin/index.ts +3 -0
  81. package/src/plugin/plugin.abstract.ts +8 -0
  82. package/src/plugin/plugin.module.ts +7 -0
  83. package/src/plugin/plugin.service.ts +30 -0
  84. package/src/plugins/tailwind/Tailwind.plugin.ts +53 -0
  85. package/src/plugins/tailwind/index.ts +3 -0
  86. package/src/plugins/tailwind/main.ts +18 -0
  87. package/src/plugins/tailwind/plugins-tailwind/index.ts +2 -0
  88. package/src/plugins/tailwind/plugins-tailwind/state.ts +88 -0
  89. package/src/plugins/tailwind/plugins-tailwind/themer.ts +53 -0
  90. package/src/theme/entities/index.ts +2 -0
  91. package/src/theme/entities/scheme.entity.ts +44 -0
  92. package/src/theme/entities/variant.entity.ts +39 -0
  93. package/src/theme/index.ts +4 -0
  94. package/src/theme/models/index.ts +1 -0
  95. package/src/theme/models/variant.model.ts +63 -0
  96. package/src/theme/services/index.ts +3 -0
  97. package/src/theme/services/scheme.service.ts +80 -0
  98. package/src/theme/services/theme.service.ts +74 -0
  99. package/src/theme/services/variant.service.ts +52 -0
  100. package/src/theme/theme.module.ts +9 -0
@@ -0,0 +1,5 @@
1
+ export * from './color.interface';
2
+ export * from './color.module';
3
+ export * from './entities';
4
+ export * from './models';
5
+ export * from './services';
@@ -0,0 +1,300 @@
1
+ import { DislikeAnalyzer, Hct } from '@material/material-color-utilities';
2
+ import { ContrastCurve, ToneDeltaPair } from '../../material-color-utilities';
3
+ import { DynamicColor } from '../../material-color-utilities/dynamic_color';
4
+ import { highestSurface } from '../services/color-manager.service';
5
+ import { AddColorsOptions, ColorService } from '../services/color.service';
6
+
7
+ export type DynamicColorKey =
8
+ | 'background'
9
+ | 'onBackground'
10
+ | 'surface'
11
+ | 'surfaceDim'
12
+ | 'surfaceBright'
13
+ | 'surfaceContainerLowest'
14
+ | 'surfaceContainerLow'
15
+ | 'surfaceContainer'
16
+ | 'surfaceContainerHigh'
17
+ | 'surfaceContainerHighest'
18
+ | 'onSurface'
19
+ | 'surfaceVariant'
20
+ | 'onSurfaceVariant'
21
+ | 'inverseSurface'
22
+ | 'inverseOnSurface'
23
+ | 'outline'
24
+ | 'outlineVariant'
25
+ | 'shadow'
26
+ | 'scrim'
27
+ | 'surfaceTint'
28
+ | 'primary'
29
+ | 'onPrimary'
30
+ | 'primaryContainer'
31
+ | 'onPrimaryContainer'
32
+ | 'inversePrimary'
33
+ | 'secondary'
34
+ | 'onSecondary'
35
+ | 'secondaryContainer'
36
+ | 'onSecondaryContainer'
37
+ | 'tertiary'
38
+ | 'onTertiary'
39
+ | 'tertiaryContainer'
40
+ | 'onTertiaryContainer'
41
+ | 'error'
42
+ | 'onError'
43
+ | 'errorContainer'
44
+ | 'onErrorContainer'
45
+ | 'primaryFixed'
46
+ | 'primaryFixedDim'
47
+ | 'onPrimaryFixed'
48
+ | 'onPrimaryFixedVariant'
49
+ | 'secondaryFixed'
50
+ | 'secondaryFixedDim'
51
+ | 'onSecondaryFixed'
52
+ | 'onSecondaryFixedVariant'
53
+ | 'tertiaryFixed'
54
+ | 'tertiaryFixedDim'
55
+ | 'onTertiaryFixed'
56
+ | 'onTertiaryFixedVariant';
57
+
58
+ function findDesiredChromaByTone(
59
+ hue: number,
60
+ chroma: number,
61
+ tone: number,
62
+ byDecreasingTone: boolean
63
+ ): number {
64
+ let answer = tone;
65
+
66
+ let closestToChroma = Hct.from(hue, chroma, tone);
67
+ if (closestToChroma.chroma < chroma) {
68
+ let chromaPeak = closestToChroma.chroma;
69
+ while (closestToChroma.chroma < chroma) {
70
+ answer += byDecreasingTone ? -1.0 : 1.0;
71
+ const potentialSolution = Hct.from(hue, chroma, answer);
72
+ if (chromaPeak > potentialSolution.chroma) {
73
+ break;
74
+ }
75
+ if (Math.abs(potentialSolution.chroma - chroma) < 0.4) {
76
+ break;
77
+ }
78
+
79
+ const potentialDelta = Math.abs(potentialSolution.chroma - chroma);
80
+ const currentDelta = Math.abs(closestToChroma.chroma - chroma);
81
+ if (potentialDelta < currentDelta) {
82
+ closestToChroma = potentialSolution;
83
+ }
84
+ chromaPeak = Math.max(chromaPeak, potentialSolution.chroma);
85
+ }
86
+ }
87
+
88
+ return answer;
89
+ }
90
+
91
+ export const defaultColors: AddColorsOptions = (
92
+ colorService: ColorService
93
+ ) => ({
94
+ fromPalettes: ['primary', 'secondary', 'tertiary'],
95
+ colors: {
96
+ background: {
97
+ palette: (s) => s.getPalette('neutral'),
98
+ tone: (s) => (s.isDark ? 6 : 98),
99
+ isBackground: true,
100
+ },
101
+ onBackground: {
102
+ palette: (s) => s.getPalette('neutral'),
103
+ tone: (s) => (s.isDark ? 90 : 10),
104
+ background: (s) => colorService.getColor('background').getDynamicColor(),
105
+ contrastCurve: new ContrastCurve(3, 3, 4.5, 7),
106
+ },
107
+ surface: {
108
+ palette: (s) => s.getPalette('neutral'),
109
+ tone: (s) => (s.isDark ? 6 : 98),
110
+ isBackground: true,
111
+ },
112
+ surfaceDim: {
113
+ palette: (s) => s.getPalette('neutral'),
114
+ tone: (s) => (s.isDark ? 6 : 87),
115
+ isBackground: true,
116
+ },
117
+ surfaceBright: {
118
+ palette: (s) => s.getPalette('neutral'),
119
+ tone: (s) => (s.isDark ? 24 : 98),
120
+ isBackground: true,
121
+ },
122
+ surfaceContainerLowest: {
123
+ palette: (s) => s.getPalette('neutral'),
124
+ tone: (s) => (s.isDark ? 4 : 100),
125
+ isBackground: true,
126
+ },
127
+ surfaceContainerLow: {
128
+ palette: (s) => s.getPalette('neutral'),
129
+ tone: (s) => (s.isDark ? 10 : 96),
130
+ isBackground: true,
131
+ },
132
+ surfaceContainer: {
133
+ palette: (s) => s.getPalette('neutral'),
134
+ tone: (s) => (s.isDark ? 12 : 94),
135
+ isBackground: true,
136
+ },
137
+ surfaceContainerHigh: {
138
+ palette: (s) => s.getPalette('neutral'),
139
+ tone: (s) => (s.isDark ? 17 : 92),
140
+ isBackground: true,
141
+ },
142
+ surfaceContainerHighest: {
143
+ palette: (s) => s.getPalette('neutral'),
144
+ tone: (s) => (s.isDark ? 22 : 90),
145
+ isBackground: true,
146
+ },
147
+ onSurface: {
148
+ palette: (s) => s.getPalette('neutral'),
149
+ tone: (s) => (s.isDark ? 90 : 10),
150
+ background: (s) => highestSurface(s, colorService),
151
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21),
152
+ },
153
+ surfaceVariant: {
154
+ palette: (s) => s.getPalette('neutralVariant'),
155
+ tone: (s) => (s.isDark ? 30 : 90),
156
+ isBackground: true,
157
+ },
158
+ onSurfaceVariant: {
159
+ palette: (s) => s.getPalette('neutralVariant'),
160
+ tone: (s) => (s.isDark ? 80 : 30),
161
+ background: (s) => highestSurface(s, colorService),
162
+ contrastCurve: new ContrastCurve(3, 4.5, 7, 11),
163
+ },
164
+ inverseSurface: {
165
+ palette: (s) => s.getPalette('neutral'),
166
+ tone: (s) => (s.isDark ? 90 : 20),
167
+ },
168
+ inverseOnSurface: {
169
+ palette: (s) => s.getPalette('neutral'),
170
+ tone: (s) => (s.isDark ? 20 : 95),
171
+ background: (s) =>
172
+ colorService.getColor('inverseSurface').getDynamicColor(),
173
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21),
174
+ },
175
+ outline: {
176
+ palette: (s) => s.getPalette('neutralVariant'),
177
+ tone: (s) => (s.isDark ? 60 : 50),
178
+ background: (s) => highestSurface(s, colorService),
179
+ contrastCurve: new ContrastCurve(1.5, 3, 4.5, 7),
180
+ },
181
+ outlineVariant: {
182
+ palette: (s) => s.getPalette('neutralVariant'),
183
+ tone: (s) => (s.isDark ? 30 : 80),
184
+ background: (s) => highestSurface(s, colorService),
185
+ contrastCurve: new ContrastCurve(1, 1, 3, 7),
186
+ },
187
+ shadow: {
188
+ palette: (s) => s.getPalette('neutral'),
189
+ tone: (s) => 0,
190
+ },
191
+ scrim: {
192
+ palette: (s) => s.getPalette('neutral'),
193
+ tone: (s) => 0,
194
+ },
195
+ surfaceTint: {
196
+ palette: (s) => s.getPalette('neutral'),
197
+ tone: (s) => (s.isDark ? 80 : 40),
198
+ isBackground: true,
199
+ },
200
+ secondaryContainer: {
201
+ tone: (s) => {
202
+ const initialTone = s.isDark ? 30 : 90;
203
+ return findDesiredChromaByTone(
204
+ s.getPalette('secondary').hue,
205
+ s.getPalette('secondary').chroma,
206
+ initialTone,
207
+ !s.isDark
208
+ );
209
+ },
210
+ },
211
+ onSecondaryContainer: {
212
+ tone: (s) => {
213
+ return DynamicColor.foregroundTone(
214
+ colorService.getColor('secondaryContainer').getDynamicColor().tone(s),
215
+ 4.5
216
+ );
217
+ },
218
+ },
219
+ tertiaryContainer: {
220
+ palette: (s) => s.getPalette('tertiary'),
221
+ tone: (s) => {
222
+ const proposedHct = s
223
+ .getPalette('tertiary')
224
+ .getHct(s.sourceColorHct.tone);
225
+ return DislikeAnalyzer.fixIfDisliked(proposedHct).tone;
226
+ },
227
+ },
228
+ onTertiaryContainer: {
229
+ palette: (s) => s.getPalette('tertiary'),
230
+ tone: (s) => {
231
+ return DynamicColor.foregroundTone(
232
+ colorService.getColor('tertiaryContainer').getDynamicColor().tone(s),
233
+ 4.5
234
+ );
235
+ },
236
+ },
237
+ error: {
238
+ palette: (s) => s.getPalette('error'),
239
+ tone: (s) => (s.isDark ? 80 : 40),
240
+ isBackground: true,
241
+ background: (s) => highestSurface(s, colorService),
242
+ contrastCurve: new ContrastCurve(3, 4.5, 7, 11),
243
+ toneDeltaPair: (s) =>
244
+ new ToneDeltaPair(
245
+ colorService.getColor('errorContainer').getDynamicColor(),
246
+ colorService.getColor('error').getDynamicColor(),
247
+ 15,
248
+ 'nearer',
249
+ false
250
+ ),
251
+ },
252
+ onError: {
253
+ palette: (s) => s.getPalette('error'),
254
+ tone: (s) => (s.isDark ? 20 : 100),
255
+ background: (s) => colorService.getColor('error').getDynamicColor(),
256
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21),
257
+ },
258
+ errorContainer: {
259
+ palette: (s) => s.getPalette('error'),
260
+ tone: (s) => (s.isDark ? 30 : 90),
261
+ isBackground: true,
262
+ background: (s) => highestSurface(s, colorService),
263
+ contrastCurve: new ContrastCurve(1, 1, 3, 7),
264
+ toneDeltaPair: (s) =>
265
+ new ToneDeltaPair(
266
+ colorService.getColor('errorContainer').getDynamicColor(),
267
+ colorService.getColor('error').getDynamicColor(),
268
+ 15,
269
+ 'nearer',
270
+ false
271
+ ),
272
+ },
273
+ onErrorContainer: {
274
+ palette: (s) => s.getPalette('error'),
275
+ tone: (s) => (s.isDark ? 90 : 10),
276
+ background: (s) =>
277
+ colorService.getColor('errorContainer').getDynamicColor(),
278
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21),
279
+ },
280
+
281
+ onTertiaryFixed: {
282
+ palette: (s) => s.getPalette('tertiary'),
283
+ tone: (s) => 10.0,
284
+ background: (s) =>
285
+ colorService.getColor('tertiaryFixedDim').getDynamicColor(),
286
+ secondBackground: (s) =>
287
+ colorService.getColor('tertiaryFixed').getDynamicColor(),
288
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21),
289
+ },
290
+ onTertiaryFixedVariant: {
291
+ palette: (s) => s.getPalette('tertiary'),
292
+ tone: (s) => 30.0,
293
+ background: (s) =>
294
+ colorService.getColor('tertiaryFixedDim').getDynamicColor(),
295
+ secondBackground: (s) =>
296
+ colorService.getColor('tertiaryFixed').getDynamicColor(),
297
+ contrastCurve: new ContrastCurve(3, 4.5, 7, 11),
298
+ },
299
+ },
300
+ });
@@ -0,0 +1 @@
1
+ export * from './default-color.model';
@@ -0,0 +1,191 @@
1
+ import { ContrastCurve, ToneDeltaPair } from '../../material-color-utilities';
2
+ import { DynamicColor } from '../../material-color-utilities/dynamic_color';
3
+ import { SchemeEntity } from '../../theme/entities/scheme.entity';
4
+
5
+ import { ColorEntity, ColorOptions } from '../entities/color.entity';
6
+ import { SchemeService } from '../../theme/services/scheme.service';
7
+ import { DynamicColorKey } from '../models/default-color.model';
8
+ import { ColorService } from './color.service';
9
+
10
+ function capitalizeFirstLetter(string: string) {
11
+ return string.charAt(0).toUpperCase() + string.slice(1);
12
+ }
13
+
14
+ export const highestSurface = (
15
+ s: SchemeEntity,
16
+ colorService: ColorManagerService | ColorService
17
+ ): DynamicColor => {
18
+ if (colorService instanceof ColorService) {
19
+ return s.isDark
20
+ ? colorService.getColor('surfaceBright').getDynamicColor()
21
+ : colorService.getColor('surfaceDim').getDynamicColor();
22
+ } else {
23
+ return s.isDark
24
+ ? colorService.get('surfaceBright').getDynamicColor()
25
+ : colorService.get('surfaceDim').getDynamicColor();
26
+ }
27
+ };
28
+
29
+ export class ColorManagerService {
30
+ private colorMap = new Map<string, ColorEntity>();
31
+ private readonly schemeService: SchemeService;
32
+ constructor({ schemeService }: { schemeService: SchemeService }) {
33
+ this.schemeService = schemeService;
34
+ }
35
+
36
+ createOrUpdate(key: string, args: Partial<ColorOptions>): ColorEntity {
37
+ let colorEntity = this.colorMap.get(key);
38
+ if (!colorEntity) {
39
+ const { palette, tone } = args;
40
+ if (palette && tone) {
41
+ colorEntity = new ColorEntity(
42
+ { ...args, palette, tone, name: key },
43
+ this.schemeService,
44
+ this
45
+ );
46
+ this.colorMap.set(key, colorEntity);
47
+ } else {
48
+ throw new Error(`Palette ${key} does not exist`);
49
+ }
50
+ } else {
51
+ colorEntity.update({ ...args, name: key });
52
+ this.colorMap.set(key, colorEntity);
53
+ }
54
+ return colorEntity;
55
+ }
56
+
57
+ public remove(key: string) {
58
+ return this.colorMap.delete(key);
59
+ }
60
+
61
+ public get(key: string): ColorEntity {
62
+ const colorEntity = this.colorMap.get(key);
63
+ if (colorEntity) {
64
+ return colorEntity;
65
+ } else {
66
+ throw new Error(`Color ${key} does not exist`);
67
+ }
68
+ }
69
+
70
+ public getAll(): ReadonlyMap<string, ColorEntity> {
71
+ return this.colorMap;
72
+ }
73
+
74
+ addFromPalette(key: string): void {
75
+ const colorKey = key as DynamicColorKey;
76
+ const ColorKey = capitalizeFirstLetter(key);
77
+ const onColorKey = ('on' + ColorKey) as DynamicColorKey;
78
+ const colorKeyContainer = (colorKey + 'Container') as DynamicColorKey;
79
+ const onColorKeyContainer = ('on' +
80
+ ColorKey +
81
+ 'Container') as DynamicColorKey;
82
+ const inverseColorKey = ('inverse' + ColorKey) as DynamicColorKey;
83
+ const colorKeyFixed = (colorKey + 'Fixed') as DynamicColorKey;
84
+ const colorKeyFixedDim = (colorKey + 'FixedDim') as DynamicColorKey;
85
+ const onColorKeyFixed = ('on' + ColorKey + 'Fixed') as DynamicColorKey;
86
+ const onColorKeyFixedVariant = ('on' +
87
+ ColorKey +
88
+ 'FixedVariant') as DynamicColorKey;
89
+
90
+ this.createOrUpdate(colorKey, {
91
+ palette: (s) => s.getPalette(key),
92
+ tone: (s) => {
93
+ return s.isDark ? 80 : 40;
94
+ },
95
+ isBackground: true,
96
+ background: (s) => highestSurface(s, this),
97
+ contrastCurve: new ContrastCurve(3, 4.5, 7, 11),
98
+ toneDeltaPair: (s) =>
99
+ new ToneDeltaPair(
100
+ this.get(colorKeyContainer).getDynamicColor(),
101
+ this.get(colorKey).getDynamicColor(),
102
+ 15,
103
+ 'nearer',
104
+ false
105
+ ),
106
+ });
107
+ this.createOrUpdate(onColorKey, {
108
+ palette: (s) => s.getPalette(key),
109
+ tone: (s) => {
110
+ return s.isDark ? 20 : 100;
111
+ },
112
+ background: (s) => this.get(colorKey).getDynamicColor(),
113
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21),
114
+ });
115
+ this.createOrUpdate(colorKeyContainer, {
116
+ palette: (s) => s.getPalette(key),
117
+ tone: (s) => {
118
+ return s.isDark ? 30 : 90;
119
+ },
120
+ isBackground: true,
121
+ background: (s) => highestSurface(s, this),
122
+ contrastCurve: new ContrastCurve(1, 1, 3, 7),
123
+ toneDeltaPair: (s) =>
124
+ new ToneDeltaPair(
125
+ this.get(colorKeyContainer).getDynamicColor(),
126
+ this.get(colorKey).getDynamicColor(),
127
+ 15,
128
+ 'nearer',
129
+ false
130
+ ),
131
+ });
132
+ this.createOrUpdate(onColorKeyContainer, {
133
+ palette: (s) => s.getPalette(key),
134
+ tone: (s) => {
135
+ return s.isDark ? 90 : 10;
136
+ },
137
+ background: (s) => this.get(colorKeyContainer).getDynamicColor(),
138
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21),
139
+ });
140
+ this.createOrUpdate(inverseColorKey, {
141
+ palette: (s) => s.getPalette(key),
142
+ tone: (s) => (s.isDark ? 40 : 80),
143
+ background: (s) => this.get('inverseSurface').getDynamicColor(),
144
+ contrastCurve: new ContrastCurve(3, 4.5, 7, 11),
145
+ });
146
+ this.createOrUpdate(colorKeyFixed, {
147
+ palette: (s) => s.getPalette(key),
148
+ tone: (s) => 90.0,
149
+ isBackground: true,
150
+ background: (s) => highestSurface(s, this),
151
+ contrastCurve: new ContrastCurve(1, 1, 3, 7),
152
+ toneDeltaPair: (s) =>
153
+ new ToneDeltaPair(
154
+ this.get(colorKeyFixed).getDynamicColor(),
155
+ this.get(colorKeyFixedDim).getDynamicColor(),
156
+ 10,
157
+ 'lighter',
158
+ true
159
+ ),
160
+ });
161
+ this.createOrUpdate(colorKeyFixedDim, {
162
+ palette: (s) => s.getPalette(key),
163
+ tone: (s) => 80.0,
164
+ isBackground: true,
165
+ background: (s) => highestSurface(s, this),
166
+ contrastCurve: new ContrastCurve(1, 1, 3, 7),
167
+ toneDeltaPair: (s) =>
168
+ new ToneDeltaPair(
169
+ this.get(colorKeyFixed).getDynamicColor(),
170
+ this.get(colorKeyFixedDim).getDynamicColor(),
171
+ 10,
172
+ 'lighter',
173
+ true
174
+ ),
175
+ });
176
+ this.createOrUpdate(onColorKeyFixed, {
177
+ palette: (s) => s.getPalette(key),
178
+ tone: (s) => 10.0,
179
+ background: (s) => this.get(colorKeyFixedDim).getDynamicColor(),
180
+ secondBackground: (s) => this.get(colorKeyFixed).getDynamicColor(),
181
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21),
182
+ });
183
+ this.createOrUpdate(onColorKeyFixedVariant, {
184
+ palette: (s) => s.getPalette(key),
185
+ tone: (s) => 30.0,
186
+ background: (s) => this.get(colorKeyFixedDim).getDynamicColor(),
187
+ secondBackground: (s) => this.get(colorKeyFixed).getDynamicColor(),
188
+ contrastCurve: new ContrastCurve(3, 4.5, 7, 11),
189
+ });
190
+ }
191
+ }
@@ -0,0 +1,28 @@
1
+ import { ColorService } from './color.service';
2
+ import { ColorModule } from '../color.module';
3
+ import { Test } from '@nestjs/testing';
4
+
5
+ describe('ColorService', () => {
6
+ let colorService: ColorService;
7
+
8
+ beforeEach(async () => {
9
+ const moduleRef = await Test.createTestingModule({
10
+ imports: [ColorModule],
11
+ }).compile();
12
+
13
+ colorService = moduleRef.get(ColorService);
14
+ });
15
+
16
+ it('should return an array of cats', async () => {
17
+ const result = colorService['dynamicColorService']['colorMap'].entries();
18
+ console.log(result);
19
+
20
+ colorService.addBaseColors();
21
+ // for (const [key, value] of Object.entries(defaultColorModel.colors)) {
22
+ // colorService.update(key, value);
23
+ // }
24
+
25
+ console.dir(result, { depth: null });
26
+ // expect(await catsController.findAll()).toBe(result);
27
+ });
28
+ });
@@ -0,0 +1,75 @@
1
+ import { ColorManagerService } from './color-manager.service';
2
+ import { ColorInterface } from '../color.interface';
3
+ import { ColorEntity, ColorOptions } from '../entities';
4
+
5
+ type AddColors = {
6
+ colors?: Record<string, Partial<ColorOptions>>;
7
+ fromPalettes?: string[] | string;
8
+ };
9
+
10
+ export type AddColorsOptions =
11
+ | AddColors
12
+ | ((colorService: ColorService) => AddColors);
13
+
14
+ export class ColorService implements ColorInterface {
15
+ private readonly colorManagerService: ColorManagerService;
16
+ constructor({
17
+ colorManagerService,
18
+ }: {
19
+ colorManagerService: ColorManagerService;
20
+ }) {
21
+ this.colorManagerService = colorManagerService;
22
+ }
23
+
24
+ getColors() {
25
+ return this.colorManagerService.getAll();
26
+ }
27
+
28
+ // getColors() {
29
+ // const colors: Record<string, string> = {};
30
+ //
31
+ // for (const [key, value] of this.colorManagerService.getAll()) {
32
+ // colors[key] = hexFromArgb(value.getArgb(this.schemeService.get()));
33
+ // }
34
+ //
35
+ // return colors;
36
+ // }
37
+
38
+ addColor(key: string, color: Partial<ColorOptions>): ColorEntity {
39
+ return this.colorManagerService.createOrUpdate(key, color);
40
+ }
41
+
42
+ addColors(args: AddColorsOptions | AddColorsOptions[]) {
43
+ const colorsEntity: ColorEntity[] = [];
44
+ if (!Array.isArray(args)) args = [args];
45
+ args.forEach((args) => {
46
+ if (typeof args === 'function') {
47
+ args = args(this);
48
+ }
49
+ if (args.fromPalettes) {
50
+ if (!Array.isArray(args.fromPalettes))
51
+ args.fromPalettes = [args.fromPalettes];
52
+ args.fromPalettes.map((paletteKey) => {
53
+ this.colorManagerService.addFromPalette(paletteKey);
54
+ });
55
+ }
56
+ if (args.colors) {
57
+ Object.keys(args.colors).map((key) =>
58
+ this.addColor(key, args.colors![key])
59
+ );
60
+ }
61
+ });
62
+ }
63
+
64
+ getColor(key: string): ColorEntity {
65
+ return this.colorManagerService.get(key);
66
+ }
67
+
68
+ removeColor(key: string): boolean {
69
+ return this.colorManagerService.remove(key);
70
+ }
71
+
72
+ updateColor(key: string, newColor: Partial<ColorOptions>): ColorEntity {
73
+ return this.colorManagerService.createOrUpdate(key, newColor);
74
+ }
75
+ }
@@ -0,0 +1,2 @@
1
+ export * from './color-manager.service';
2
+ export * from './color.service';
@@ -0,0 +1,14 @@
1
+ import { VariantEntity } from '../theme';
2
+ import { AddColorsOptions } from '../color';
3
+ import { PluginConstructor } from '../plugin/plugin.service';
4
+
5
+ export interface ConfigInterface {
6
+ sourceColor: string;
7
+ contrastLevel?: 0;
8
+ isDark?: boolean;
9
+ variant?: VariantEntity;
10
+ colors?: AddColorsOptions | AddColorsOptions[];
11
+ useDefaultColors?: boolean;
12
+ palettes?: Record<string, string>;
13
+ plugins?: (PluginConstructor | [PluginConstructor, object])[];
14
+ }
@@ -0,0 +1,7 @@
1
+ import { asClass } from 'awilix';
2
+ import { Module } from '../app.container';
3
+ import { ConfigService } from './config.service';
4
+
5
+ export const ConfigModule: Module = {
6
+ configService: asClass(ConfigService).singleton(),
7
+ };