Skip to content

Commit 2fa9df5

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 644b513 + 0b25f4a commit 2fa9df5

File tree

4 files changed

+59
-46
lines changed

4 files changed

+59
-46
lines changed

projects/material-css-vars/src/lib/material-css-vars.service.ts

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ interface CssVariable {
1717
val: string;
1818
}
1919

20+
interface Color {
21+
rgb: Numberify<RGBA>;
22+
isLight: boolean;
23+
}
24+
2025
// @see: https://github.com/angular/angular/issues/20351
2126
/** @dynamic */
2227
@Injectable({
@@ -26,20 +31,18 @@ export class MaterialCssVarsService {
2631
private static CONTRAST_PREFIX = 'contrast-';
2732
private static DARK_TEXT_VAR = '--dark-primary-text';
2833
private static LIGHT_TEXT_VAR = '--light-primary-text';
29-
30-
private renderer: Renderer2;
31-
private ROOT: HTMLElement;
32-
3334
// This should be readonly from the outside
3435
cfg: MaterialCssVariablesConfig;
35-
primary: string;
36-
accent: string;
37-
warn: string;
38-
isDarkTheme: boolean;
36+
primary = '#03a9f4';
37+
accent = '#e91e63';
38+
warn = '#f44336';
39+
isDarkTheme = false; // ToDo: make this attribute optional in next major version
3940
contrastColorThresholdPrimary: HueValue = '400';
4041
contrastColorThresholdAccent: HueValue = '400';
4142
contrastColorThresholdWarn: HueValue = '400';
4243
isAutoContrast = false;
44+
private renderer: Renderer2;
45+
private ROOT: HTMLElement;
4346

4447
constructor(
4548
rendererFactory: RendererFactory2,
@@ -203,6 +206,31 @@ export class MaterialCssVarsService {
203206
}
204207
}
205208

209+
getPaletteWithContrastForColor(hex: string): MatCssHueColorContrastMapItem[] {
210+
const lightText = this._getCssVarValue(MaterialCssVarsService.LIGHT_TEXT_VAR);
211+
const darkText = this._getCssVarValue(MaterialCssVarsService.DARK_TEXT_VAR);
212+
const palette = this.getPaletteForColor(hex);
213+
214+
// TODO handle non auto case
215+
return palette.map((item) => {
216+
const contrastStr = item.isLight
217+
? lightText
218+
: darkText;
219+
220+
const sLight = this._replaceNoRgbValue('', contrastStr)
221+
.split(',')
222+
.map((v) => +v);
223+
const cco = {r: sLight[0], g: sLight[1], b: sLight[2], a: 1};
224+
return {
225+
...item,
226+
contrast: {
227+
...cco,
228+
str: `${cco.r},${cco.g},${cco.b}`
229+
},
230+
};
231+
});
232+
}
233+
206234
private getTraditionalPaletteForColor(hex: string): MatCssHueColorMapItem[] {
207235
return this.cfg.colorMap.map(item => {
208236
const mappedColor = new TinyColor(hex)
@@ -235,31 +263,6 @@ export class MaterialCssVarsService {
235263
});
236264
}
237265

238-
getPaletteWithContrastForColor(hex: string): MatCssHueColorContrastMapItem[] {
239-
const lightText = this._getCssVarValue(MaterialCssVarsService.LIGHT_TEXT_VAR);
240-
const darkText = this._getCssVarValue(MaterialCssVarsService.DARK_TEXT_VAR);
241-
const palette = this.getPaletteForColor(hex);
242-
243-
// TODO handle non auto case
244-
return palette.map((item) => {
245-
const contrastStr = item.isLight
246-
? lightText
247-
: darkText;
248-
249-
const sLight = this._replaceNoRgbValue('', contrastStr)
250-
.split(',')
251-
.map((v) => +v);
252-
const cco = {r: sLight[0], g: sLight[1], b: sLight[2], a: 1};
253-
return {
254-
...item,
255-
contrast: {
256-
...cco,
257-
str: `${cco.r},${cco.g},${cco.b}`
258-
},
259-
};
260-
});
261-
}
262-
263266
private _computePaletteColors(prefix: MatCssPalettePrefix, hex: string): CssVariable[] {
264267
return this.getPaletteForColor(hex).map(item => {
265268
const c = item.color;
@@ -336,11 +339,11 @@ export class MaterialCssVarsService {
336339
* Compute pallet colors based on a Triad (Constantin)
337340
* see: https://github.com/mbitson/mcg
338341
*/
339-
private computePalletTriad(hex: string, hue: HueValue) {
342+
private computePalletTriad(hex: string, hue: HueValue): Color {
340343
const baseLight = new TinyColor('#ffffff');
341344
const baseDark = this.multiply(new TinyColor(hex).toRgb(), new TinyColor(hex).toRgb());
342345
const baseTriad = new TinyColor(hex).tetrad();
343-
let color: { rgb: Numberify<RGBA>, isLight: boolean };
346+
let color: Color;
344347

345348
switch (hue) {
346349
case '50':
@@ -385,8 +388,6 @@ export class MaterialCssVarsService {
385388
case 'A700':
386389
color = this.getColorObject(baseDark.mix(baseTriad[4], 15).saturate(100).lighten(40));
387390
break;
388-
default:
389-
break;
390391
}
391392
return color;
392393
}
@@ -398,7 +399,7 @@ export class MaterialCssVarsService {
398399
return new TinyColor('rgb ' + rgb1.r + ' ' + rgb1.g + ' ' + rgb1.b);
399400
}
400401

401-
private getColorObject(value: TinyColor) {
402+
private getColorObject(value: TinyColor): Color {
402403
const c = new TinyColor(value);
403404
return {rgb: c.toRgb(), isLight: c.isLight()};
404405
}

src/app/app.component.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {MatDialog} from '@angular/material/dialog';
44
import {MatSnackBar} from '@angular/material/snack-bar';
55
import {MaterialCssVarsService} from '../../projects/material-css-vars/src/lib/material-css-vars.service';
66
import {HueValue, MatCssHueColorContrastMapItem} from '../../projects/material-css-vars/src/lib/model';
7+
import {ProgressSpinnerMode} from '@angular/material/progress-spinner';
78

89
export interface Task {
910
name: string;
@@ -18,10 +19,10 @@ export interface Task {
1819
})
1920
export class AppComponent {
2021
isDarkTheme = false;
21-
threshold: HueValue;
22+
threshold?: HueValue;
2223
isAlternativeColorAlgorithm = false;
2324

24-
palettePrimary: MatCssHueColorContrastMapItem[];
25+
palettePrimary?: MatCssHueColorContrastMapItem[];
2526

2627
hues = [
2728
{value: '50', viewValue: '50'},
@@ -40,9 +41,9 @@ export class AppComponent {
4041
{value: 'A700', viewValue: 'A700'},
4142
];
4243

43-
spinnerMode = 'indeterminate';
44+
spinnerMode: ProgressSpinnerMode = 'indeterminate';
4445
spinnerValue: number = 25;
45-
spinnerColor = 'primary';
46+
spinnerColor: ThemePalette = 'primary';
4647
availableSpinnerColors = [
4748
{name: 'none', color: ''},
4849
{name: 'Primary', color: 'primary'},
@@ -51,7 +52,7 @@ export class AppComponent {
5152
];
5253

5354
progress = 0;
54-
55+
5556
task: Task = {
5657
name: 'Indeterminate',
5758
completed: false,

src/main.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@ if (environment.production) {
1111

1212
platformBrowserDynamic().bootstrapModule(AppModule)
1313
.catch(err => console.error(err));
14+
15+
declare global {
16+
interface Window {
17+
_app_base?: string;
18+
}
19+
}

tsconfig.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"moduleResolution": "node",
1212
"importHelpers": true,
1313
"target": "ES2022",
14+
"strict": true,
15+
"forceConsistentCasingInFileNames": true,
16+
"noImplicitReturns": true,
17+
"noFallthroughCasesInSwitch": true,
1418
"typeRoots": [
1519
"node_modules/@types"
1620
],
@@ -35,7 +39,8 @@
3539
"useDefineForClassFields": false
3640
},
3741
"angularCompilerOptions": {
38-
"fullTemplateTypeCheck": true,
39-
"strictInjectionParameters": true
42+
"strictTemplates": true,
43+
"strictInjectionParameters": true,
44+
"strictInputAccessModifiers": true
4045
}
41-
}
46+
}

0 commit comments

Comments
 (0)