Skip to content

Commit 1c438b3

Browse files
committedAug 12, 2024·
fix(material/schematics): Generate more accurate tonal palettes for M3 schematic (#29536)
(cherry picked from commit dd8477c)
1 parent 5174108 commit 1c438b3

File tree

2 files changed

+152
-146
lines changed

2 files changed

+152
-146
lines changed
 

‎src/material/schematics/ng-generate/m3-theme/index.spec.ts

+136-137
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ describe('material-m3-theme-schematic', () => {
115115
);
116116

117117
expect(generatedSCSS).toBe(testSCSS);
118-
expect(transpileTheme(generatedSCSS)).toBe(transpileTheme(testSCSS));
119118
});
120119

121120
it('should generate dark theme when provided a primary color', async () => {
@@ -277,30 +276,30 @@ describe('material-m3-theme-schematic', () => {
277276
[
278277
` neutral: (`,
279278
` 0: #000000,`,
280-
` 4: #000527,`,
281-
` 6: #00073a,`,
282-
` 10: #000c61,`,
283-
` 12: #051166,`,
284-
` 17: #121e71,`,
285-
` 20: #1a2678,`,
286-
` 22: #1f2b7d,`,
287-
` 24: #243082,`,
288-
` 25: #273384,`,
289-
` 30: #333f90,`,
290-
` 35: #404b9c,`,
291-
` 40: #4c57a9,`,
292-
` 50: #6570c4,`,
293-
` 60: #7f8ae0,`,
294-
` 70: #9aa5fd,`,
295-
` 80: #bcc2ff,`,
296-
` 87: #d5d7ff,`,
297-
` 90: #dfe0ff,`,
298-
` 92: #e6e6ff,`,
299-
` 94: #edecff,`,
300-
` 95: #f0efff,`,
301-
` 96: #f4f2ff,`,
302-
` 98: #fbf8ff,`,
303-
` 99: #fffbff,`,
279+
` 4: #0b0b0c,`,
280+
` 6: #111012,`,
281+
` 10: #1c1b1e,`,
282+
` 12: #201f22,`,
283+
` 17: #2b2a2d,`,
284+
` 20: #313033,`,
285+
` 22: #353437,`,
286+
` 24: #3a393c,`,
287+
` 25: #3c3b3e,`,
288+
` 30: #474649,`,
289+
` 35: #535255,`,
290+
` 40: #5f5e61,`,
291+
` 50: #787679,`,
292+
` 60: #929093,`,
293+
` 70: #adaaad,`,
294+
` 80: #c8c5c9,`,
295+
` 87: #dcd9dd,`,
296+
` 90: #e5e1e5,`,
297+
` 92: #ebe7eb,`,
298+
` 94: #f0edf0,`,
299+
` 95: #f3f0f3,`,
300+
` 96: #f6f3f6,`,
301+
` 98: #fcf8fb,`,
302+
` 99: #fffbfe,`,
304303
` 100: #ffffff,`,
305304
` ),`,
306305
].join('\n'),
@@ -337,16 +336,16 @@ $_palettes: (
337336
),
338337
secondary: (
339338
0: #000000,
340-
10: #2b151c,
341-
20: #422931,
342-
25: #4e343c,
343-
30: #5a3f47,
344-
35: #674b53,
345-
40: #74565f,
346-
50: #8e6f77,
347-
60: #aa8891,
348-
70: #c6a2ab,
349-
80: #e2bdc6,
339+
10: #31101d,
340+
20: #4a2531,
341+
25: #56303c,
342+
30: #633b48,
343+
35: #704653,
344+
40: #7e525f,
345+
50: #996a78,
346+
60: #b58392,
347+
70: #d29dac,
348+
80: #efb8c7,
350349
90: #ffd9e2,
351350
95: #ffecf0,
352351
98: #fff8f8,
@@ -355,63 +354,63 @@ $_palettes: (
355354
),
356355
tertiary: (
357356
0: #000000,
358-
10: #2e1500,
359-
20: #48290c,
360-
25: #543416,
361-
30: #623f20,
362-
35: #6f4a2a,
363-
40: #7c5635,
364-
50: #986e4b,
365-
60: #b48862,
366-
70: #d1a27b,
367-
80: #efbd94,
368-
90: #ffdcc2,
369-
95: #ffeee2,
370-
98: #fff8f5,
357+
10: #331200,
358+
20: #532200,
359+
25: #642a00,
360+
30: #763300,
361+
35: #883d03,
362+
40: #974810,
363+
50: #b66028,
364+
60: #d6783e,
365+
70: #f69256,
366+
80: #ffb68e,
367+
90: #ffdbc9,
368+
95: #ffede5,
369+
98: #fff8f6,
371370
99: #fffbff,
372371
100: #ffffff,
373372
),
374373
neutral: (
375374
0: #000000,
376-
10: #201a1b,
377-
20: #352f30,
378-
25: #413a3b,
379-
30: #4c4546,
380-
35: #585052,
381-
40: #645c5e,
382-
50: #7e7576,
383-
60: #988e90,
384-
70: #b3a9aa,
385-
80: #cfc4c5,
386-
90: #ebe0e1,
387-
95: #faeeef,
375+
10: #22191c,
376+
20: #372e30,
377+
25: #43393b,
378+
30: #4f4446,
379+
35: #5b5052,
380+
40: #675b5e,
381+
50: #807477,
382+
60: #9b8d90,
383+
70: #b6a8aa,
384+
80: #d2c3c5,
385+
90: #efdfe1,
386+
95: #fdedef,
388387
98: #fff8f8,
389388
99: #fffbff,
390389
100: #ffffff,
391-
4: #120d0e,
392-
6: #171213,
393-
12: #241e1f,
394-
17: #2f282a,
395-
22: #3a3334,
396-
24: #3e3739,
397-
87: #e3d7d9,
398-
92: #f1e5e7,
399-
94: #f7ebec,
400-
96: #fdf1f2,
390+
4: #140c0e,
391+
6: #191113,
392+
12: #261d20,
393+
17: #31282a,
394+
22: #3c3235,
395+
24: #413739,
396+
87: #e6d6d9,
397+
92: #f5e4e7,
398+
94: #faeaed,
399+
96: #fff0f2,
401400
),
402401
neutral-variant: (
403402
0: #000000,
404-
10: #24191c,
405-
20: #3a2d30,
406-
25: #45383b,
407-
30: #514347,
408-
35: #5d4f52,
409-
40: #6a5b5e,
410-
50: #837377,
411-
60: #9e8c90,
412-
70: #b9a7ab,
413-
80: #d5c2c6,
414-
90: #f2dde2,
403+
10: #25181c,
404+
20: #3c2c31,
405+
25: #47373b,
406+
30: #534247,
407+
35: #604e52,
408+
40: #6c5a5e,
409+
50: #867277,
410+
60: #a18b90,
411+
70: #bca5ab,
412+
80: #d9c0c6,
413+
90: #f6dce2,
415414
95: #ffecf0,
416415
98: #fff8f8,
417416
99: #fffbff,
@@ -492,16 +491,16 @@ function getPaletteMap() {
492491
'secondary',
493492
new Map<number, string>([
494493
[0, '#000000'],
495-
[10, '#2b151c'],
496-
[20, '#422931'],
497-
[25, '#4e343c'],
498-
[30, '#5a3f47'],
499-
[35, '#674b53'],
500-
[40, '#74565f'],
501-
[50, '#8e6f77'],
502-
[60, '#aa8891'],
503-
[70, '#c6a2ab'],
504-
[80, '#e2bdc6'],
494+
[10, '#31101d'],
495+
[20, '#4a2531'],
496+
[25, '#56303c'],
497+
[30, '#633b48'],
498+
[35, '#704653'],
499+
[40, '#7e525f'],
500+
[50, '#996a78'],
501+
[60, '#b58392'],
502+
[70, '#d29dac'],
503+
[80, '#efb8c7'],
505504
[90, '#ffd9e2'],
506505
[95, '#ffecf0'],
507506
[98, '#fff8f8'],
@@ -513,19 +512,19 @@ function getPaletteMap() {
513512
'tertiary',
514513
new Map<number, string>([
515514
[0, '#000000'],
516-
[10, '#2e1500'],
517-
[20, '#48290c'],
518-
[25, '#543416'],
519-
[30, '#623f20'],
520-
[35, '#6f4a2a'],
521-
[40, '#7c5635'],
522-
[50, '#986e4b'],
523-
[60, '#b48862'],
524-
[70, '#d1a27b'],
525-
[80, '#efbd94'],
526-
[90, '#ffdcc2'],
527-
[95, '#ffeee2'],
528-
[98, '#fff8f5'],
515+
[10, '#331200'],
516+
[20, '#532200'],
517+
[25, '#642a00'],
518+
[30, '#763300'],
519+
[35, '#883d03'],
520+
[40, '#974810'],
521+
[50, '#b66028'],
522+
[60, '#d6783e'],
523+
[70, '#f69256'],
524+
[80, '#ffb68e'],
525+
[90, '#ffdbc9'],
526+
[95, '#ffede5'],
527+
[98, '#fff8f6'],
529528
[99, '#fffbff'],
530529
[100, '#ffffff'],
531530
]),
@@ -534,48 +533,48 @@ function getPaletteMap() {
534533
'neutral',
535534
new Map<number, string>([
536535
[0, '#000000'],
537-
[10, '#201a1b'],
538-
[20, '#352f30'],
539-
[25, '#413a3b'],
540-
[30, '#4c4546'],
541-
[35, '#585052'],
542-
[40, '#645c5e'],
543-
[50, '#7e7576'],
544-
[60, '#988e90'],
545-
[70, '#b3a9aa'],
546-
[80, '#cfc4c5'],
547-
[90, '#ebe0e1'],
548-
[95, '#faeeef'],
536+
[10, '#22191c'],
537+
[20, '#372e30'],
538+
[25, '#43393b'],
539+
[30, '#4f4446'],
540+
[35, '#5b5052'],
541+
[40, '#675b5e'],
542+
[50, '#807477'],
543+
[60, '#9b8d90'],
544+
[70, '#b6a8aa'],
545+
[80, '#d2c3c5'],
546+
[90, '#efdfe1'],
547+
[95, '#fdedef'],
549548
[98, '#fff8f8'],
550549
[99, '#fffbff'],
551550
[100, '#ffffff'],
552-
[4, '#120d0e'],
553-
[6, '#171213'],
554-
[12, '#241e1f'],
555-
[17, '#2f282a'],
556-
[22, '#3a3334'],
557-
[24, '#3e3739'],
558-
[87, '#e3d7d9'],
559-
[92, '#f1e5e7'],
560-
[94, '#f7ebec'],
561-
[96, '#fdf1f2'],
551+
[4, '#140c0e'],
552+
[6, '#191113'],
553+
[12, '#261d20'],
554+
[17, '#31282a'],
555+
[22, '#3c3235'],
556+
[24, '#413739'],
557+
[87, '#e6d6d9'],
558+
[92, '#f5e4e7'],
559+
[94, '#faeaed'],
560+
[96, '#fff0f2'],
562561
]),
563562
],
564563
[
565564
'neutral-variant',
566565
new Map<number, string>([
567566
[0, '#000000'],
568-
[10, '#24191c'],
569-
[20, '#3a2d30'],
570-
[25, '#45383b'],
571-
[30, '#514347'],
572-
[35, '#5d4f52'],
573-
[40, '#6a5b5e'],
574-
[50, '#837377'],
575-
[60, '#9e8c90'],
576-
[70, '#b9a7ab'],
577-
[80, '#d5c2c6'],
578-
[90, '#f2dde2'],
567+
[10, '#25181c'],
568+
[20, '#3c2c31'],
569+
[25, '#47373b'],
570+
[30, '#534247'],
571+
[35, '#604e52'],
572+
[40, '#6c5a5e'],
573+
[50, '#867277'],
574+
[60, '#a18b90'],
575+
[70, '#bca5ab'],
576+
[80, '#d9c0c6'],
577+
[90, '#f6dce2'],
579578
[95, '#ffecf0'],
580579
[98, '#fff8f8'],
581580
[99, '#fffbff'],

‎src/material/schematics/ng-generate/m3-theme/index.ts

+16-9
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import {Rule, SchematicContext, Tree} from '@angular-devkit/schematics';
1010
import {Schema} from './schema';
1111
import {
1212
argbFromHex,
13-
themeFromSourceColor,
1413
hexFromArgb,
1514
TonalPalette,
15+
Hct,
16+
SchemeContent,
1617
} from '@material/material-color-utilities';
1718

1819
// For each color tonal palettes are created using the following hue tones. The
@@ -54,14 +55,20 @@ function getMaterialTonalPalettes(color: string): {
5455
} {
5556
try {
5657
let argbColor = argbFromHex(color);
57-
const theme = themeFromSourceColor(argbColor, [
58-
{
59-
name: 'm3-theme',
60-
value: argbColor,
61-
blend: true,
62-
},
63-
]);
64-
return theme.palettes;
58+
const scheme = new SchemeContent(
59+
Hct.fromInt(argbColor),
60+
false, // Tonal palettes are the same for light and dark themes
61+
0.0,
62+
);
63+
64+
return {
65+
primary: scheme.primaryPalette,
66+
secondary: scheme.secondaryPalette,
67+
tertiary: scheme.tertiaryPalette,
68+
neutral: scheme.neutralPalette,
69+
neutralVariant: scheme.neutralVariantPalette,
70+
error: scheme.errorPalette,
71+
};
6572
} catch (e) {
6673
throw new Error(
6774
'Cannot parse the specified color ' +

0 commit comments

Comments
 (0)
Please sign in to comment.