@udixio/theme 1.0.0-beta.6 → 1.0.0-beta.8
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/app.service.d.ts +6 -3
- package/dist/color/color.interface.d.ts +1 -2
- package/dist/color/entities/color.entity.d.ts +6 -1
- package/dist/color/index.d.ts +1 -2
- package/dist/color/models/default-color.model.d.ts +2 -3
- package/dist/color/services/color-manager.service.d.ts +18 -0
- package/dist/color/services/color.service.d.ts +21 -0
- package/dist/color/services/index.d.ts +2 -0
- package/dist/config/config.interface.d.ts +14 -0
- package/dist/config/config.module.d.ts +2 -0
- package/dist/config/config.service.d.ts +12 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/index.d.ts +3 -0
- package/dist/main.d.ts +2 -1
- package/dist/plugin/plugin.abstract.d.ts +6 -0
- package/dist/plugin/plugin.module.d.ts +2 -0
- package/dist/plugin/plugin.service.d.ts +9 -0
- package/dist/theme/entities/variant.entity.d.ts +2 -1
- package/dist/theme/services/scheme.service.d.ts +7 -2
- package/dist/theme/services/theme.service.d.ts +10 -4
- package/dist/theme/services/variant.service.d.ts +4 -0
- package/dist/theme.cjs.development.js +1077 -506
- 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 +1073 -507
- package/dist/theme.esm.js.map +1 -1
- package/package.json +3 -5
- package/src/app.container.ts +9 -1
- package/src/app.service.ts +8 -2
- package/src/color/color.interface.ts +1 -3
- package/src/color/color.module.ts +2 -2
- package/src/color/entities/color.entity.ts +13 -1
- package/src/color/index.ts +1 -2
- package/src/color/models/default-color.model.ts +205 -202
- package/src/color/{color-manager.service.ts → services/color-manager.service.ts} +17 -10
- package/src/color/{color.service.spec.ts → services/color.service.spec.ts} +1 -1
- package/src/color/{color.service.ts → services/color.service.ts} +33 -21
- package/src/color/services/index.ts +2 -0
- package/src/config/config.interface.ts +15 -0
- package/src/config/config.module.ts +7 -0
- package/src/config/config.service.ts +68 -0
- package/src/config/index.ts +2 -0
- package/src/index.ts +3 -0
- package/src/main.ts +9 -1
- package/src/plugin/plugin.abstract.ts +7 -0
- package/src/plugin/plugin.module.ts +7 -0
- package/src/plugin/plugin.service.ts +26 -0
- package/src/theme/entities/variant.entity.ts +2 -1
- package/src/theme/models/variant.model.ts +7 -0
- package/src/theme/services/scheme.service.ts +39 -9
- package/src/theme/services/theme.service.ts +18 -8
- package/src/theme/services/variant.service.ts +36 -2
- package/dist/color/color-manager.service.d.ts +0 -17
- package/dist/color/color.service.d.ts +0 -16
package/src/app.container.ts
CHANGED
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
import { ColorModule } from './color/color.module';
|
|
9
9
|
import { ThemeModule } from './theme/theme.module';
|
|
10
10
|
import { AppModule } from './app.module';
|
|
11
|
+
import { ConfigModule } from './config/config.module';
|
|
12
|
+
import { PluginModule } from './plugin/plugin.module';
|
|
11
13
|
|
|
12
14
|
export type Module = Record<
|
|
13
15
|
string,
|
|
@@ -30,7 +32,13 @@ const AppContainer = createContainer({
|
|
|
30
32
|
injectionMode: InjectionMode.PROXY,
|
|
31
33
|
});
|
|
32
34
|
|
|
33
|
-
importContainer(AppContainer, [
|
|
35
|
+
importContainer(AppContainer, [
|
|
36
|
+
ConfigModule,
|
|
37
|
+
AppModule,
|
|
38
|
+
PluginModule,
|
|
39
|
+
ColorModule,
|
|
40
|
+
ThemeModule,
|
|
41
|
+
]);
|
|
34
42
|
|
|
35
43
|
// AppContainer.register(ColorModule.cradle);
|
|
36
44
|
// AppContainer.register(ThemeModule.cradle);
|
package/src/app.service.ts
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
import { ColorService } from './color
|
|
2
|
-
import { ThemeService } from './theme
|
|
1
|
+
import { ColorService } from './color';
|
|
2
|
+
import { ThemeService } from './theme';
|
|
3
|
+
import { PluginService } from './plugin/plugin.service';
|
|
3
4
|
|
|
4
5
|
export class AppService {
|
|
5
6
|
public colorService: ColorService;
|
|
6
7
|
public themeService: ThemeService;
|
|
8
|
+
public pluginService: PluginService;
|
|
9
|
+
|
|
7
10
|
constructor({
|
|
8
11
|
colorService,
|
|
9
12
|
themeService,
|
|
13
|
+
pluginService,
|
|
10
14
|
}: {
|
|
11
15
|
colorService: ColorService;
|
|
12
16
|
themeService: ThemeService;
|
|
17
|
+
pluginService: PluginService;
|
|
13
18
|
}) {
|
|
19
|
+
this.pluginService = pluginService;
|
|
14
20
|
this.colorService = colorService;
|
|
15
21
|
this.themeService = themeService;
|
|
16
22
|
}
|
|
@@ -9,7 +9,5 @@ export interface ColorInterface {
|
|
|
9
9
|
|
|
10
10
|
updateColor(key: string, newColor: ColorOptions): ColorEntity;
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
addColors(colors: Record<string, ColorOptions>): ColorEntity[];
|
|
12
|
+
getColors(): ReadonlyMap<string, ColorEntity>;
|
|
15
13
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ColorService } from './color.service';
|
|
2
|
-
import { ColorManagerService } from './color-manager.service';
|
|
1
|
+
import { ColorService } from './services/color.service';
|
|
2
|
+
import { ColorManagerService } from './services/color-manager.service';
|
|
3
3
|
import { asClass } from 'awilix';
|
|
4
4
|
import { Module } from '../app.container';
|
|
5
5
|
|
|
@@ -3,7 +3,7 @@ import { SchemeEntity } from '../../theme/entities/scheme.entity';
|
|
|
3
3
|
import { DynamicColor } from '../../material-color-utilities/dynamic_color';
|
|
4
4
|
import { ContrastCurve } from '../../material-color-utilities';
|
|
5
5
|
import { SchemeService } from '../../theme/services/scheme.service';
|
|
6
|
-
import { ColorManagerService } from '../color-manager.service';
|
|
6
|
+
import { ColorManagerService } from '../services/color-manager.service';
|
|
7
7
|
|
|
8
8
|
export interface ColorOptions {
|
|
9
9
|
palette: (scheme: SchemeEntity) => TonalPalette;
|
|
@@ -21,6 +21,14 @@ export interface ColorOptions {
|
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
function argbToRgb(argb: number): { r: number; g: number; b: number } {
|
|
25
|
+
return {
|
|
26
|
+
r: (argb >> 16) & 0xff,
|
|
27
|
+
g: (argb >> 8) & 0xff,
|
|
28
|
+
b: argb & 0xff,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
24
32
|
export class ColorEntity {
|
|
25
33
|
private dynamicColor: DynamicColor | null = null;
|
|
26
34
|
|
|
@@ -43,6 +51,10 @@ export class ColorEntity {
|
|
|
43
51
|
return this.getDynamicColor().getArgb(this.schemeService.get());
|
|
44
52
|
}
|
|
45
53
|
|
|
54
|
+
getRgb() {
|
|
55
|
+
return argbToRgb(this.getArgb());
|
|
56
|
+
}
|
|
57
|
+
|
|
46
58
|
getName(): string {
|
|
47
59
|
return this.option.name.replace(/([A-Z])/g, '_$1').toLowerCase();
|
|
48
60
|
}
|
package/src/color/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DislikeAnalyzer, Hct } from '@material/material-color-utilities';
|
|
2
2
|
import { ContrastCurve, ToneDeltaPair } from '../../material-color-utilities';
|
|
3
3
|
import { DynamicColor } from '../../material-color-utilities/dynamic_color';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { highestSurface } from '../services/color-manager.service';
|
|
5
|
+
import { AddColorsOptions, ColorService } from '../services/color.service';
|
|
6
6
|
|
|
7
7
|
export type DynamicColorKey =
|
|
8
8
|
| 'background'
|
|
@@ -88,210 +88,213 @@ function findDesiredChromaByTone(
|
|
|
88
88
|
return answer;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
export const defaultColors = (
|
|
92
|
-
|
|
93
|
-
)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
palette: (s) => s.getPalette('neutral'),
|
|
101
|
-
tone: (s) => (s.isDark ? 90 : 10),
|
|
102
|
-
background: (s) => colorManagerService.get('background').getDynamicColor(),
|
|
103
|
-
contrastCurve: new ContrastCurve(3, 3, 4.5, 7),
|
|
104
|
-
},
|
|
105
|
-
surface: {
|
|
106
|
-
palette: (s) => s.getPalette('neutral'),
|
|
107
|
-
tone: (s) => (s.isDark ? 6 : 98),
|
|
108
|
-
isBackground: true,
|
|
109
|
-
},
|
|
110
|
-
surfaceDim: {
|
|
111
|
-
palette: (s) => s.getPalette('neutral'),
|
|
112
|
-
tone: (s) => (s.isDark ? 6 : 87),
|
|
113
|
-
isBackground: true,
|
|
114
|
-
},
|
|
115
|
-
surfaceBright: {
|
|
116
|
-
palette: (s) => s.getPalette('neutral'),
|
|
117
|
-
tone: (s) => (s.isDark ? 24 : 98),
|
|
118
|
-
isBackground: true,
|
|
119
|
-
},
|
|
120
|
-
surfaceContainerLowest: {
|
|
121
|
-
palette: (s) => s.getPalette('neutral'),
|
|
122
|
-
tone: (s) => (s.isDark ? 4 : 100),
|
|
123
|
-
isBackground: true,
|
|
124
|
-
},
|
|
125
|
-
surfaceContainerLow: {
|
|
126
|
-
palette: (s) => s.getPalette('neutral'),
|
|
127
|
-
tone: (s) => (s.isDark ? 10 : 96),
|
|
128
|
-
isBackground: true,
|
|
129
|
-
},
|
|
130
|
-
surfaceContainer: {
|
|
131
|
-
palette: (s) => s.getPalette('neutral'),
|
|
132
|
-
tone: (s) => (s.isDark ? 12 : 94),
|
|
133
|
-
isBackground: true,
|
|
134
|
-
},
|
|
135
|
-
surfaceContainerHigh: {
|
|
136
|
-
palette: (s) => s.getPalette('neutral'),
|
|
137
|
-
tone: (s) => (s.isDark ? 17 : 92),
|
|
138
|
-
isBackground: true,
|
|
139
|
-
},
|
|
140
|
-
surfaceContainerHighest: {
|
|
141
|
-
palette: (s) => s.getPalette('neutral'),
|
|
142
|
-
tone: (s) => (s.isDark ? 22 : 90),
|
|
143
|
-
isBackground: true,
|
|
144
|
-
},
|
|
145
|
-
onSurface: {
|
|
146
|
-
palette: (s) => s.getPalette('neutral'),
|
|
147
|
-
tone: (s) => (s.isDark ? 90 : 10),
|
|
148
|
-
background: (s) => highestSurface(s, colorManagerService),
|
|
149
|
-
contrastCurve: new ContrastCurve(4.5, 7, 11, 21),
|
|
150
|
-
},
|
|
151
|
-
surfaceVariant: {
|
|
152
|
-
palette: (s) => s.getPalette('neutralVariant'),
|
|
153
|
-
tone: (s) => (s.isDark ? 30 : 90),
|
|
154
|
-
isBackground: true,
|
|
155
|
-
},
|
|
156
|
-
onSurfaceVariant: {
|
|
157
|
-
palette: (s) => s.getPalette('neutralVariant'),
|
|
158
|
-
tone: (s) => (s.isDark ? 80 : 30),
|
|
159
|
-
background: (s) => highestSurface(s, colorManagerService),
|
|
160
|
-
contrastCurve: new ContrastCurve(3, 4.5, 7, 11),
|
|
161
|
-
},
|
|
162
|
-
inverseSurface: {
|
|
163
|
-
palette: (s) => s.getPalette('neutral'),
|
|
164
|
-
tone: (s) => (s.isDark ? 90 : 20),
|
|
165
|
-
},
|
|
166
|
-
inverseOnSurface: {
|
|
167
|
-
palette: (s) => s.getPalette('neutral'),
|
|
168
|
-
tone: (s) => (s.isDark ? 20 : 95),
|
|
169
|
-
background: (s) =>
|
|
170
|
-
colorManagerService.get('inverseSurface').getDynamicColor(),
|
|
171
|
-
contrastCurve: new ContrastCurve(4.5, 7, 11, 21),
|
|
172
|
-
},
|
|
173
|
-
outline: {
|
|
174
|
-
palette: (s) => s.getPalette('neutralVariant'),
|
|
175
|
-
tone: (s) => (s.isDark ? 60 : 50),
|
|
176
|
-
background: (s) => highestSurface(s, colorManagerService),
|
|
177
|
-
contrastCurve: new ContrastCurve(1.5, 3, 4.5, 7),
|
|
178
|
-
},
|
|
179
|
-
outlineVariant: {
|
|
180
|
-
palette: (s) => s.getPalette('neutralVariant'),
|
|
181
|
-
tone: (s) => (s.isDark ? 30 : 80),
|
|
182
|
-
background: (s) => highestSurface(s, colorManagerService),
|
|
183
|
-
contrastCurve: new ContrastCurve(1, 1, 3, 7),
|
|
184
|
-
},
|
|
185
|
-
shadow: {
|
|
186
|
-
palette: (s) => s.getPalette('neutral'),
|
|
187
|
-
tone: (s) => 0,
|
|
188
|
-
},
|
|
189
|
-
scrim: {
|
|
190
|
-
palette: (s) => s.getPalette('neutral'),
|
|
191
|
-
tone: (s) => 0,
|
|
192
|
-
},
|
|
193
|
-
surfaceTint: {
|
|
194
|
-
palette: (s) => s.getPalette('neutral'),
|
|
195
|
-
tone: (s) => (s.isDark ? 80 : 40),
|
|
196
|
-
isBackground: true,
|
|
197
|
-
},
|
|
198
|
-
secondaryContainer: {
|
|
199
|
-
tone: (s) => {
|
|
200
|
-
const initialTone = s.isDark ? 30 : 90;
|
|
201
|
-
return findDesiredChromaByTone(
|
|
202
|
-
s.getPalette('secondary').hue,
|
|
203
|
-
s.getPalette('secondary').chroma,
|
|
204
|
-
initialTone,
|
|
205
|
-
!s.isDark
|
|
206
|
-
);
|
|
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,
|
|
207
100
|
},
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
4.5
|
|
214
|
-
);
|
|
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),
|
|
215
106
|
},
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
const proposedHct = s
|
|
221
|
-
.getPalette('tertiary')
|
|
222
|
-
.getHct(s.sourceColorHct.tone);
|
|
223
|
-
return DislikeAnalyzer.fixIfDisliked(proposedHct).tone;
|
|
107
|
+
surface: {
|
|
108
|
+
palette: (s) => s.getPalette('neutral'),
|
|
109
|
+
tone: (s) => (s.isDark ? 6 : 98),
|
|
110
|
+
isBackground: true,
|
|
224
111
|
},
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
)
|
|
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),
|
|
233
279
|
},
|
|
234
|
-
},
|
|
235
|
-
error: {
|
|
236
|
-
palette: (s) => s.getPalette('error'),
|
|
237
|
-
tone: (s) => (s.isDark ? 80 : 40),
|
|
238
|
-
isBackground: true,
|
|
239
|
-
background: (s) => highestSurface(s, colorManagerService),
|
|
240
|
-
contrastCurve: new ContrastCurve(3, 4.5, 7, 11),
|
|
241
|
-
toneDeltaPair: (s) =>
|
|
242
|
-
new ToneDeltaPair(
|
|
243
|
-
colorManagerService.get('errorContainer').getDynamicColor(),
|
|
244
|
-
colorManagerService.get('error').getDynamicColor(),
|
|
245
|
-
15,
|
|
246
|
-
'nearer',
|
|
247
|
-
false
|
|
248
|
-
),
|
|
249
|
-
},
|
|
250
|
-
onError: {
|
|
251
|
-
palette: (s) => s.getPalette('error'),
|
|
252
|
-
tone: (s) => (s.isDark ? 20 : 100),
|
|
253
|
-
background: (s) => colorManagerService.get('error').getDynamicColor(),
|
|
254
|
-
contrastCurve: new ContrastCurve(4.5, 7, 11, 21),
|
|
255
|
-
},
|
|
256
|
-
errorContainer: {
|
|
257
|
-
palette: (s) => s.getPalette('error'),
|
|
258
|
-
tone: (s) => (s.isDark ? 30 : 90),
|
|
259
|
-
isBackground: true,
|
|
260
|
-
background: (s) => highestSurface(s, colorManagerService),
|
|
261
|
-
contrastCurve: new ContrastCurve(1, 1, 3, 7),
|
|
262
|
-
toneDeltaPair: (s) =>
|
|
263
|
-
new ToneDeltaPair(
|
|
264
|
-
colorManagerService.get('errorContainer').getDynamicColor(),
|
|
265
|
-
colorManagerService.get('error').getDynamicColor(),
|
|
266
|
-
15,
|
|
267
|
-
'nearer',
|
|
268
|
-
false
|
|
269
|
-
),
|
|
270
|
-
},
|
|
271
|
-
onErrorContainer: {
|
|
272
|
-
palette: (s) => s.getPalette('error'),
|
|
273
|
-
tone: (s) => (s.isDark ? 90 : 10),
|
|
274
|
-
background: (s) =>
|
|
275
|
-
colorManagerService.get('errorContainer').getDynamicColor(),
|
|
276
|
-
contrastCurve: new ContrastCurve(4.5, 7, 11, 21),
|
|
277
|
-
},
|
|
278
280
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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
|
+
},
|
|
296
299
|
},
|
|
297
300
|
});
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { ContrastCurve, ToneDeltaPair } from '
|
|
2
|
-
import { DynamicColor } from '
|
|
3
|
-
import { SchemeEntity } from '
|
|
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
4
|
|
|
5
|
-
import { ColorEntity, ColorOptions } from '
|
|
6
|
-
import { SchemeService } from '
|
|
7
|
-
import { DynamicColorKey } from '
|
|
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';
|
|
8
9
|
|
|
9
10
|
function capitalizeFirstLetter(string: string) {
|
|
10
11
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
@@ -12,11 +13,17 @@ function capitalizeFirstLetter(string: string) {
|
|
|
12
13
|
|
|
13
14
|
export const highestSurface = (
|
|
14
15
|
s: SchemeEntity,
|
|
15
|
-
|
|
16
|
+
colorService: ColorManagerService | ColorService
|
|
16
17
|
): DynamicColor => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
+
}
|
|
20
27
|
};
|
|
21
28
|
|
|
22
29
|
export class ColorManagerService {
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { ColorManagerService } from './color-manager.service';
|
|
2
|
-
import { ColorInterface } from '
|
|
3
|
-
import { ColorEntity, ColorOptions } from '
|
|
4
|
-
|
|
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);
|
|
5
13
|
|
|
6
14
|
export class ColorService implements ColorInterface {
|
|
7
15
|
private readonly colorManagerService: ColorManagerService;
|
|
@@ -13,7 +21,7 @@ export class ColorService implements ColorInterface {
|
|
|
13
21
|
this.colorManagerService = colorManagerService;
|
|
14
22
|
}
|
|
15
23
|
|
|
16
|
-
|
|
24
|
+
getColors() {
|
|
17
25
|
return this.colorManagerService.getAll();
|
|
18
26
|
}
|
|
19
27
|
|
|
@@ -27,26 +35,30 @@ export class ColorService implements ColorInterface {
|
|
|
27
35
|
// return colors;
|
|
28
36
|
// }
|
|
29
37
|
|
|
30
|
-
|
|
31
|
-
this.colorManagerService.addFromPalette('primary');
|
|
32
|
-
this.colorManagerService.addFromPalette('secondary');
|
|
33
|
-
this.colorManagerService.addFromPalette('tertiary');
|
|
34
|
-
|
|
35
|
-
const colors = defaultColors(this.colorManagerService);
|
|
36
|
-
Object.keys(colors).map((key) => {
|
|
37
|
-
const color: Partial<ColorOptions> | undefined =
|
|
38
|
-
colors[key as DynamicColorKey];
|
|
39
|
-
if (!color) return;
|
|
40
|
-
return this.colorManagerService.createOrUpdate(key, color);
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
addColor(key: string, color: ColorOptions): ColorEntity {
|
|
38
|
+
addColor(key: string, color: Partial<ColorOptions>): ColorEntity {
|
|
45
39
|
return this.colorManagerService.createOrUpdate(key, color);
|
|
46
40
|
}
|
|
47
41
|
|
|
48
|
-
addColors(
|
|
49
|
-
|
|
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
|
+
});
|
|
50
62
|
}
|
|
51
63
|
|
|
52
64
|
getColor(key: string): ColorEntity {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { VariantEntity } from '../theme';
|
|
2
|
+
import { AddColorsOptions } from '../color';
|
|
3
|
+
import { PluginAbstract } from '../plugin/plugin.abstract';
|
|
4
|
+
import { AppService } from '../app.service';
|
|
5
|
+
|
|
6
|
+
export interface ConfigInterface {
|
|
7
|
+
sourceColor: string;
|
|
8
|
+
contrastLevel?: 0;
|
|
9
|
+
isDark?: boolean;
|
|
10
|
+
variant?: VariantEntity;
|
|
11
|
+
colors?: AddColorsOptions | AddColorsOptions[];
|
|
12
|
+
useDefaultColors?: boolean;
|
|
13
|
+
palettes?: Record<string, string>;
|
|
14
|
+
plugins?: (new (appService: AppService) => PluginAbstract)[];
|
|
15
|
+
}
|