@udixio/theme 1.2.0 → 1.3.0
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/CHANGELOG.md +10 -0
- package/dist/bin.cjs +1 -1
- package/dist/bin.js +1 -1
- package/dist/browser.cjs +3 -4
- package/dist/browser.js +11 -12
- package/dist/color/color.manager.d.ts.map +1 -1
- package/dist/color/default-color.d.ts.map +1 -1
- package/dist/{define-config-CGG8l3fb.js → define-config-B1QPKKY_.js} +32 -2
- package/dist/{define-config-BFo7Sy7c.cjs → define-config-BGgVazsr.cjs} +32 -2
- package/dist/{load-from-path-CFpw2P_Y.js → load-from-path-BSrT4DOj.js} +1 -1
- package/dist/{load-from-path-BvdfXUD0.cjs → load-from-path-BuN8RpOs.cjs} +2 -2
- package/dist/loader/loader.d.ts.map +1 -1
- package/dist/{loader-C_BIrsO2.js → loader-Bc0bstAD.js} +129 -119
- package/dist/{loader-TksB6_mM.cjs → loader-YNN5hAF3.cjs} +121 -111
- package/dist/material-color-utilities/dynamic_color.d.ts +9 -15
- package/dist/material-color-utilities/dynamic_color.d.ts.map +1 -1
- package/dist/material-color-utilities/toneDeltaPair.d.ts +9 -2
- package/dist/material-color-utilities/toneDeltaPair.d.ts.map +1 -1
- package/dist/node.cjs +4 -5
- package/dist/node.js +13 -14
- package/dist/theme/scheme.d.ts +1 -1
- package/dist/theme/scheme.d.ts.map +1 -1
- package/dist/theme/variants/fidelity.variant.d.ts +3 -0
- package/dist/theme/variants/fidelity.variant.d.ts.map +1 -0
- package/dist/theme/variants/index.d.ts +1 -0
- package/dist/theme/variants/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/color/color.manager.ts +10 -8
- package/src/color/default-color.ts +82 -34
- package/src/loader/loader.ts +1 -5
- package/src/material-color-utilities/dynamic_color.ts +18 -120
- package/src/material-color-utilities/toneDeltaPair.ts +91 -2
- package/src/theme/scheme.ts +7 -1
- package/src/theme/variants/fidelity.variant.ts +38 -0
- package/src/theme/variants/index.ts +2 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheme.d.ts","sourceRoot":"","sources":["../../src/theme/scheme.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,GAAG,EAAE,MAAM,iCAAiC,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,WAAW,aAAa;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACpC,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,qBAAa,MAAM;IACL,QAAQ,CAAC,OAAO,EAAE,aAAa;gBAAtB,OAAO,EAAE,aAAa;IAE3C,IAAI,OAAO,
|
|
1
|
+
{"version":3,"file":"scheme.d.ts","sourceRoot":"","sources":["../../src/theme/scheme.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,GAAG,EAAE,MAAM,iCAAiC,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,WAAW,aAAa;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACpC,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,qBAAa,MAAM;IACL,QAAQ,CAAC,OAAO,EAAE,aAAa;gBAAtB,OAAO,EAAE,aAAa;IAE3C,IAAI,OAAO,IACP,YAAY,GACZ,SAAS,GACT,WAAW,GACX,SAAS,GACT,UAAU,GACV,MAAM,CAET;IAED,IAAI,aAAa,WAKhB;IAED,IAAI,MAAM,YAKT;IAED,IAAI,cAAc,QAKjB;IAED,UAAU,CACR,GAAG,EACC,SAAS,GACT,WAAW,GACX,UAAU,GACV,SAAS,GACT,gBAAgB,GAChB,OAAO,GACP,MAAM,GACT,YAAY;CAUhB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fidelity.variant.d.ts","sourceRoot":"","sources":["../../../src/theme/variants/fidelity.variant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,OAAO,EAAE,MAAM,YAAY,CAAC;AAGrE,eAAO,MAAM,eAAe,EAAE,OAkC7B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/theme/variants/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/theme/variants/index.ts"],"names":[],"mappings":"AAMA,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAElC,eAAO,MAAM,QAAQ;;;;;;CAMpB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DynamicColor,
|
|
1
|
+
import { DynamicColor, toneDeltaPair } from '../material-color-utilities';
|
|
2
2
|
import { Scheme, SchemeManager } from '../theme';
|
|
3
3
|
|
|
4
4
|
import { ColorOptions, ConfigurableColor } from './configurable-color';
|
|
@@ -91,6 +91,8 @@ export class ColorManager {
|
|
|
91
91
|
const onColorContainerKey = ('on' +
|
|
92
92
|
ColorKey +
|
|
93
93
|
'Container') as DynamicColorKey;
|
|
94
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
95
|
+
// @ts-expect-error
|
|
94
96
|
const inverseColorKey = ('inverse' + ColorKey) as DynamicColorKey;
|
|
95
97
|
const colorFixedKey = (colorKey + 'Fixed') as DynamicColorKey;
|
|
96
98
|
const colorFixedDimKey = (colorKey + 'FixedDim') as DynamicColorKey;
|
|
@@ -115,8 +117,8 @@ export class ColorManager {
|
|
|
115
117
|
isBackground: true,
|
|
116
118
|
background: (s) => highestSurface(s, this),
|
|
117
119
|
contrastCurve: (s) => getCurve(4.5),
|
|
118
|
-
|
|
119
|
-
|
|
120
|
+
adjustTone: (s) =>
|
|
121
|
+
toneDeltaPair(
|
|
120
122
|
this.get(colorContainerKey).getMaterialColor(),
|
|
121
123
|
this.get(colorKey).getMaterialColor(),
|
|
122
124
|
5,
|
|
@@ -137,8 +139,8 @@ export class ColorManager {
|
|
|
137
139
|
isBackground: true,
|
|
138
140
|
background: (s) => this.get('surfaceContainerHigh').getMaterialColor(),
|
|
139
141
|
contrastCurve: (s) => getCurve(4.5),
|
|
140
|
-
|
|
141
|
-
|
|
142
|
+
adjustTone: (s) =>
|
|
143
|
+
toneDeltaPair(
|
|
142
144
|
this.get(colorDimKey).getMaterialColor(),
|
|
143
145
|
this.get(colorKey).getMaterialColor(),
|
|
144
146
|
5,
|
|
@@ -167,7 +169,7 @@ export class ColorManager {
|
|
|
167
169
|
},
|
|
168
170
|
isBackground: true,
|
|
169
171
|
background: (s) => highestSurface(s, this),
|
|
170
|
-
|
|
172
|
+
adjustTone: (s) => undefined,
|
|
171
173
|
contrastCurve: (s) => (s.contrastLevel > 0 ? getCurve(1.5) : undefined),
|
|
172
174
|
});
|
|
173
175
|
this.createOrUpdate(onColorContainerKey, {
|
|
@@ -189,8 +191,8 @@ export class ColorManager {
|
|
|
189
191
|
palette: (s) => s.getPalette(colorKey),
|
|
190
192
|
tone: (s) => this.get(colorFixedKey).getMaterialColor().getTone(s),
|
|
191
193
|
isBackground: true,
|
|
192
|
-
|
|
193
|
-
|
|
194
|
+
adjustTone: (s) =>
|
|
195
|
+
toneDeltaPair(
|
|
194
196
|
this.get(colorFixedDimKey).getMaterialColor(),
|
|
195
197
|
this.get(colorFixedKey).getMaterialColor(),
|
|
196
198
|
5,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { toneDeltaPair } from '../material-color-utilities';
|
|
2
2
|
import { DynamicColor } from '../material-color-utilities/dynamic_color';
|
|
3
3
|
import { highestSurface } from './color.manager';
|
|
4
4
|
import { AddColorsOptions, ColorApi } from './color.api';
|
|
@@ -6,6 +6,11 @@ import { Hct } from '../material-color-utilities/htc';
|
|
|
6
6
|
import { ColorOptions } from './configurable-color';
|
|
7
7
|
import { Scheme } from '../theme';
|
|
8
8
|
import { DynamicColorKey, getCurve, tMaxC, tMinC } from './color.utils';
|
|
9
|
+
import { Contrast } from '@material/material-color-utilities';
|
|
10
|
+
|
|
11
|
+
const inverseTone = (tone: number) => {
|
|
12
|
+
return 100 - tone;
|
|
13
|
+
};
|
|
9
14
|
|
|
10
15
|
export const defaultColors: AddColorsOptions = (colorService: ColorApi) => {
|
|
11
16
|
const getColor = (key: DynamicColorKey) => {
|
|
@@ -26,6 +31,9 @@ export const defaultColors: AddColorsOptions = (colorService: ColorApi) => {
|
|
|
26
31
|
if (s.isDark) {
|
|
27
32
|
return 4;
|
|
28
33
|
} else {
|
|
34
|
+
if (s.variant == 'fidelity') {
|
|
35
|
+
return 100;
|
|
36
|
+
}
|
|
29
37
|
if (Hct.isYellow(s.getPalette('neutral').hue)) {
|
|
30
38
|
return 99;
|
|
31
39
|
} else if (s.variant === 'vibrant') {
|
|
@@ -347,6 +355,8 @@ export const defaultColors: AddColorsOptions = (colorService: ColorApi) => {
|
|
|
347
355
|
? 88
|
|
348
356
|
: 98,
|
|
349
357
|
);
|
|
358
|
+
} else if (s.variant == 'fidelity') {
|
|
359
|
+
return s.sourceColorHct.tone;
|
|
350
360
|
} else {
|
|
351
361
|
return tMaxC(
|
|
352
362
|
s.getPalette('primary'),
|
|
@@ -358,15 +368,34 @@ export const defaultColors: AddColorsOptions = (colorService: ColorApi) => {
|
|
|
358
368
|
isBackground: true,
|
|
359
369
|
background: (s) => highestSurface(s, colorService),
|
|
360
370
|
contrastCurve: (s) => getCurve(4.5),
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
371
|
+
adjustTone: (s) =>
|
|
372
|
+
s.variant == 'fidelity'
|
|
373
|
+
? () => {
|
|
374
|
+
const surfaceTone = colorService
|
|
375
|
+
.getColor('surface')
|
|
376
|
+
.getMaterialColor()
|
|
377
|
+
.tone(s);
|
|
378
|
+
const primaryTone = colorService
|
|
379
|
+
.getColor('primary')
|
|
380
|
+
.getMaterialColor()
|
|
381
|
+
.tone(s);
|
|
382
|
+
let selfTone = primaryTone;
|
|
383
|
+
if (Contrast.ratioOfTones(surfaceTone, selfTone) < 3) {
|
|
384
|
+
const result = inverseTone(primaryTone);
|
|
385
|
+
if (Contrast.ratioOfTones(surfaceTone, result) >= 3) {
|
|
386
|
+
selfTone = result;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
return selfTone;
|
|
390
|
+
}
|
|
391
|
+
: toneDeltaPair(
|
|
392
|
+
colorService.getColor('primaryContainer').getMaterialColor(),
|
|
393
|
+
colorService.getColor('primary').getMaterialColor(),
|
|
394
|
+
5,
|
|
395
|
+
'relative_lighter',
|
|
396
|
+
true,
|
|
397
|
+
'farther',
|
|
398
|
+
),
|
|
370
399
|
},
|
|
371
400
|
primaryDim: {
|
|
372
401
|
palette: (s) => s.getPalette('primary'),
|
|
@@ -382,8 +411,8 @@ export const defaultColors: AddColorsOptions = (colorService: ColorApi) => {
|
|
|
382
411
|
isBackground: true,
|
|
383
412
|
background: (s) => getColor('surfaceContainerHigh'),
|
|
384
413
|
contrastCurve: (s) => getCurve(4.5),
|
|
385
|
-
|
|
386
|
-
|
|
414
|
+
adjustTone: (s) =>
|
|
415
|
+
toneDeltaPair(
|
|
387
416
|
colorService.getColor('primaryDim').getMaterialColor(),
|
|
388
417
|
colorService.getColor('primary').getMaterialColor(),
|
|
389
418
|
5,
|
|
@@ -414,6 +443,15 @@ export const defaultColors: AddColorsOptions = (colorService: ColorApi) => {
|
|
|
414
443
|
78,
|
|
415
444
|
Hct.isCyan(s.getPalette('primary').hue) ? 88 : 90,
|
|
416
445
|
);
|
|
446
|
+
}
|
|
447
|
+
if (s.variant == 'fidelity') {
|
|
448
|
+
return s.isDark
|
|
449
|
+
? tMaxC(s.getPalette('primary'), 30, 93)
|
|
450
|
+
: tMaxC(
|
|
451
|
+
s.getPalette('primary'),
|
|
452
|
+
78,
|
|
453
|
+
Hct.isCyan(s.getPalette('primary').hue) ? 88 : 90,
|
|
454
|
+
);
|
|
417
455
|
} else {
|
|
418
456
|
// VIBRANT
|
|
419
457
|
return s.isDark
|
|
@@ -427,7 +465,17 @@ export const defaultColors: AddColorsOptions = (colorService: ColorApi) => {
|
|
|
427
465
|
},
|
|
428
466
|
isBackground: true,
|
|
429
467
|
background: (s) => highestSurface(s, colorService),
|
|
430
|
-
|
|
468
|
+
adjustTone: (s) =>
|
|
469
|
+
s.variant == 'fidelity'
|
|
470
|
+
? toneDeltaPair(
|
|
471
|
+
colorService.getColor('primary').getMaterialColor(),
|
|
472
|
+
colorService.getColor('primaryContainer').getMaterialColor(),
|
|
473
|
+
15,
|
|
474
|
+
'relative_darker',
|
|
475
|
+
true,
|
|
476
|
+
'farther',
|
|
477
|
+
)
|
|
478
|
+
: undefined,
|
|
431
479
|
contrastCurve: (s) => (s.contrastLevel > 0 ? getCurve(1.5) : undefined),
|
|
432
480
|
},
|
|
433
481
|
onPrimaryContainer: {
|
|
@@ -457,8 +505,8 @@ export const defaultColors: AddColorsOptions = (colorService: ColorApi) => {
|
|
|
457
505
|
tone: (s) =>
|
|
458
506
|
colorService.getColor('primaryFixed').getMaterialColor().getTone(s),
|
|
459
507
|
isBackground: true,
|
|
460
|
-
|
|
461
|
-
|
|
508
|
+
adjustTone: (s) =>
|
|
509
|
+
toneDeltaPair(
|
|
462
510
|
getColor('primaryFixedDim'),
|
|
463
511
|
getColor('primaryFixed'),
|
|
464
512
|
5,
|
|
@@ -509,8 +557,8 @@ export const defaultColors: AddColorsOptions = (colorService: ColorApi) => {
|
|
|
509
557
|
isBackground: true,
|
|
510
558
|
background: (s) => highestSurface(s, colorService),
|
|
511
559
|
contrastCurve: (s) => getCurve(4.5),
|
|
512
|
-
|
|
513
|
-
|
|
560
|
+
adjustTone: (s) =>
|
|
561
|
+
toneDeltaPair(
|
|
514
562
|
getColor('secondaryContainer'),
|
|
515
563
|
getColor('secondary'),
|
|
516
564
|
5,
|
|
@@ -531,8 +579,8 @@ export const defaultColors: AddColorsOptions = (colorService: ColorApi) => {
|
|
|
531
579
|
isBackground: true,
|
|
532
580
|
background: (s) => getColor('surfaceContainerHigh'),
|
|
533
581
|
contrastCurve: (s) => getCurve(4.5),
|
|
534
|
-
|
|
535
|
-
|
|
582
|
+
adjustTone: (s) =>
|
|
583
|
+
toneDeltaPair(
|
|
536
584
|
getColor('secondaryDim'),
|
|
537
585
|
getColor('secondary'),
|
|
538
586
|
5,
|
|
@@ -561,7 +609,7 @@ export const defaultColors: AddColorsOptions = (colorService: ColorApi) => {
|
|
|
561
609
|
},
|
|
562
610
|
isBackground: true,
|
|
563
611
|
background: (s) => highestSurface(s, colorService),
|
|
564
|
-
|
|
612
|
+
adjustTone: (s) => undefined,
|
|
565
613
|
contrastCurve: (s) => (s.contrastLevel > 0 ? getCurve(1.5) : undefined),
|
|
566
614
|
},
|
|
567
615
|
onSecondaryContainer: {
|
|
@@ -589,8 +637,8 @@ export const defaultColors: AddColorsOptions = (colorService: ColorApi) => {
|
|
|
589
637
|
palette: (s) => s.getPalette('secondary'),
|
|
590
638
|
tone: (s) => getColor('secondaryFixed').getTone(s),
|
|
591
639
|
isBackground: true,
|
|
592
|
-
|
|
593
|
-
|
|
640
|
+
adjustTone: (s) =>
|
|
641
|
+
toneDeltaPair(
|
|
594
642
|
getColor('secondaryFixedDim'),
|
|
595
643
|
getColor('secondaryFixed'),
|
|
596
644
|
5,
|
|
@@ -634,8 +682,8 @@ export const defaultColors: AddColorsOptions = (colorService: ColorApi) => {
|
|
|
634
682
|
isBackground: true,
|
|
635
683
|
background: (s) => highestSurface(s, colorService),
|
|
636
684
|
contrastCurve: (s) => getCurve(4.5),
|
|
637
|
-
|
|
638
|
-
|
|
685
|
+
adjustTone: (s) =>
|
|
686
|
+
toneDeltaPair(
|
|
639
687
|
getColor('tertiaryContainer'),
|
|
640
688
|
getColor('tertiary'),
|
|
641
689
|
5,
|
|
@@ -656,8 +704,8 @@ export const defaultColors: AddColorsOptions = (colorService: ColorApi) => {
|
|
|
656
704
|
isBackground: true,
|
|
657
705
|
background: (s) => getColor('surfaceContainerHigh'),
|
|
658
706
|
contrastCurve: (s) => getCurve(4.5),
|
|
659
|
-
|
|
660
|
-
|
|
707
|
+
adjustTone: (s) =>
|
|
708
|
+
toneDeltaPair(
|
|
661
709
|
getColor('tertiaryDim'),
|
|
662
710
|
getColor('tertiary'),
|
|
663
711
|
5,
|
|
@@ -695,7 +743,7 @@ export const defaultColors: AddColorsOptions = (colorService: ColorApi) => {
|
|
|
695
743
|
},
|
|
696
744
|
isBackground: true,
|
|
697
745
|
background: (s) => highestSurface(s, colorService),
|
|
698
|
-
|
|
746
|
+
adjustTone: (s) => undefined,
|
|
699
747
|
contrastCurve: (s) => (s.contrastLevel > 0 ? getCurve(1.5) : undefined),
|
|
700
748
|
},
|
|
701
749
|
onTertiaryContainer: {
|
|
@@ -723,8 +771,8 @@ export const defaultColors: AddColorsOptions = (colorService: ColorApi) => {
|
|
|
723
771
|
palette: (s) => s.getPalette('tertiary'),
|
|
724
772
|
tone: (s) => getColor('tertiaryFixed').getTone(s),
|
|
725
773
|
isBackground: true,
|
|
726
|
-
|
|
727
|
-
|
|
774
|
+
adjustTone: (s) =>
|
|
775
|
+
toneDeltaPair(
|
|
728
776
|
getColor('tertiaryFixedDim'),
|
|
729
777
|
getColor('tertiaryFixed'),
|
|
730
778
|
5,
|
|
@@ -760,8 +808,8 @@ export const defaultColors: AddColorsOptions = (colorService: ColorApi) => {
|
|
|
760
808
|
isBackground: true,
|
|
761
809
|
background: (s) => highestSurface(s, colorService),
|
|
762
810
|
contrastCurve: (s) => getCurve(4.5),
|
|
763
|
-
|
|
764
|
-
|
|
811
|
+
adjustTone: (s) =>
|
|
812
|
+
toneDeltaPair(
|
|
765
813
|
colorService.getColor('errorContainer').getMaterialColor(),
|
|
766
814
|
colorService.getColor('error').getMaterialColor(),
|
|
767
815
|
5,
|
|
@@ -776,8 +824,8 @@ export const defaultColors: AddColorsOptions = (colorService: ColorApi) => {
|
|
|
776
824
|
isBackground: true,
|
|
777
825
|
background: (s) => getColor('surfaceContainerHigh'),
|
|
778
826
|
contrastCurve: (s) => getCurve(4.5),
|
|
779
|
-
|
|
780
|
-
|
|
827
|
+
adjustTone: (s) =>
|
|
828
|
+
toneDeltaPair(
|
|
781
829
|
getColor('errorDim'),
|
|
782
830
|
getColor('error'),
|
|
783
831
|
5,
|
|
@@ -800,7 +848,7 @@ export const defaultColors: AddColorsOptions = (colorService: ColorApi) => {
|
|
|
800
848
|
},
|
|
801
849
|
isBackground: true,
|
|
802
850
|
background: (s) => highestSurface(s, colorService),
|
|
803
|
-
|
|
851
|
+
adjustTone: (s) => undefined,
|
|
804
852
|
contrastCurve: (s) => (s.contrastLevel > 0 ? getCurve(1.5) : undefined),
|
|
805
853
|
},
|
|
806
854
|
onErrorContainer: {
|
package/src/loader/loader.ts
CHANGED
|
@@ -15,9 +15,12 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
clampDouble,
|
|
20
|
+
Contrast,
|
|
21
|
+
TonalPalette,
|
|
22
|
+
} from '@material/material-color-utilities';
|
|
19
23
|
import { ContrastCurve } from './contrastCurve';
|
|
20
|
-
import { ToneDeltaPair } from './toneDeltaPair';
|
|
21
24
|
import { Scheme } from '../theme/scheme';
|
|
22
25
|
import { Hct } from './htc';
|
|
23
26
|
|
|
@@ -42,7 +45,7 @@ import { Hct } from './htc';
|
|
|
42
45
|
* against its background should behave in various contrast levels options.
|
|
43
46
|
* Must used together with `background`. When not provided or resolved as
|
|
44
47
|
* undefined, the contrast curve is calculated based on other constraints.
|
|
45
|
-
* @param
|
|
48
|
+
* @param adjustTone A `AdjustTone` object specifying a tone delta
|
|
46
49
|
* constraint between two colors. One of them must be the color being
|
|
47
50
|
* constructed. When not provided or resolved as undefined, the tone is
|
|
48
51
|
* calculated based on other constraints.
|
|
@@ -56,48 +59,13 @@ export interface FromPaletteOptions {
|
|
|
56
59
|
background?: (scheme: Scheme) => DynamicColor | undefined;
|
|
57
60
|
secondBackground?: (scheme: Scheme) => DynamicColor | undefined;
|
|
58
61
|
contrastCurve?: (scheme: Scheme) => ContrastCurve | undefined;
|
|
59
|
-
|
|
62
|
+
adjustTone?: (scheme: Scheme) => AdjustTone | undefined;
|
|
60
63
|
}
|
|
61
64
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
* @param originlColor The original color.
|
|
67
|
-
* @param specVersion The spec version to extend.
|
|
68
|
-
* @param extendedColor The color with the values to extend.
|
|
69
|
-
*/
|
|
70
|
-
export function extendSpecVersion(
|
|
71
|
-
originlColor: DynamicColor,
|
|
72
|
-
extendedColor: DynamicColor,
|
|
73
|
-
): DynamicColor {
|
|
74
|
-
return DynamicColor.fromPalette({
|
|
75
|
-
name: originlColor.name,
|
|
76
|
-
palette: (s) => extendedColor.palette(s),
|
|
77
|
-
tone: (s) => extendedColor.tone(s),
|
|
78
|
-
isBackground: originlColor.isBackground,
|
|
79
|
-
chromaMultiplier: (s) => {
|
|
80
|
-
const chromaMultiplier = extendedColor.chromaMultiplier;
|
|
81
|
-
return chromaMultiplier !== undefined ? chromaMultiplier(s) : 1;
|
|
82
|
-
},
|
|
83
|
-
background: (s) => {
|
|
84
|
-
const background = extendedColor.background;
|
|
85
|
-
return background !== undefined ? background(s) : undefined;
|
|
86
|
-
},
|
|
87
|
-
secondBackground: (s) => {
|
|
88
|
-
const secondBackground = extendedColor.secondBackground;
|
|
89
|
-
return secondBackground !== undefined ? secondBackground(s) : undefined;
|
|
90
|
-
},
|
|
91
|
-
contrastCurve: (s) => {
|
|
92
|
-
const contrastCurve = extendedColor.contrastCurve;
|
|
93
|
-
return contrastCurve !== undefined ? contrastCurve(s) : undefined;
|
|
94
|
-
},
|
|
95
|
-
toneDeltaPair: (s) => {
|
|
96
|
-
const toneDeltaPair = extendedColor.toneDeltaPair;
|
|
97
|
-
return toneDeltaPair !== undefined ? toneDeltaPair(s) : undefined;
|
|
98
|
-
},
|
|
99
|
-
});
|
|
100
|
-
}
|
|
65
|
+
export type AdjustTone = (args: {
|
|
66
|
+
scheme: Scheme;
|
|
67
|
+
dynamicColor: DynamicColor;
|
|
68
|
+
}) => number;
|
|
101
69
|
|
|
102
70
|
/**
|
|
103
71
|
* A color that adjusts itself based on UI state provided by DynamicScheme.
|
|
@@ -142,7 +110,7 @@ export class DynamicColor {
|
|
|
142
110
|
* @param contrastCurve A `ContrastCurve` object specifying how its contrast
|
|
143
111
|
* against its background should behave in various contrast levels
|
|
144
112
|
* options.
|
|
145
|
-
* @param
|
|
113
|
+
* @param adjustTone A `AdjustTone` object specifying a tone delta
|
|
146
114
|
* constraint between two colors. One of them must be the color being
|
|
147
115
|
* constructed.
|
|
148
116
|
*/
|
|
@@ -155,7 +123,7 @@ export class DynamicColor {
|
|
|
155
123
|
readonly background?: (scheme: Scheme) => DynamicColor | undefined,
|
|
156
124
|
readonly secondBackground?: (scheme: Scheme) => DynamicColor | undefined,
|
|
157
125
|
readonly contrastCurve?: (scheme: Scheme) => ContrastCurve | undefined,
|
|
158
|
-
readonly
|
|
126
|
+
readonly adjustTone?: (scheme: Scheme) => AdjustTone | undefined,
|
|
159
127
|
) {
|
|
160
128
|
if (!background && secondBackground) {
|
|
161
129
|
throw new Error(
|
|
@@ -193,7 +161,7 @@ export class DynamicColor {
|
|
|
193
161
|
args.background,
|
|
194
162
|
args.secondBackground,
|
|
195
163
|
args.contrastCurve,
|
|
196
|
-
args.
|
|
164
|
+
args.adjustTone,
|
|
197
165
|
);
|
|
198
166
|
}
|
|
199
167
|
|
|
@@ -298,7 +266,7 @@ export class DynamicColor {
|
|
|
298
266
|
background: this.background,
|
|
299
267
|
secondBackground: this.secondBackground,
|
|
300
268
|
contrastCurve: this.contrastCurve,
|
|
301
|
-
|
|
269
|
+
adjustTone: this.adjustTone,
|
|
302
270
|
});
|
|
303
271
|
}
|
|
304
272
|
|
|
@@ -349,81 +317,11 @@ export class DynamicColor {
|
|
|
349
317
|
* contrast level is.
|
|
350
318
|
*/
|
|
351
319
|
getTone(scheme: Scheme): number {
|
|
352
|
-
const
|
|
353
|
-
? this.toneDeltaPair(scheme)
|
|
354
|
-
: undefined;
|
|
320
|
+
const adjustTone = this.adjustTone ? this.adjustTone(scheme) : undefined;
|
|
355
321
|
|
|
356
322
|
// Case 0: tone delta constraint.
|
|
357
|
-
if (
|
|
358
|
-
|
|
359
|
-
const roleB = toneDeltaPair.roleB;
|
|
360
|
-
const polarity = toneDeltaPair.polarity;
|
|
361
|
-
const constraint = toneDeltaPair.constraint;
|
|
362
|
-
const absoluteDelta =
|
|
363
|
-
polarity === 'darker' ||
|
|
364
|
-
(polarity === 'relative_lighter' && scheme.isDark) ||
|
|
365
|
-
(polarity === 'relative_darker' && !scheme.isDark)
|
|
366
|
-
? -toneDeltaPair.delta
|
|
367
|
-
: toneDeltaPair.delta;
|
|
368
|
-
|
|
369
|
-
const amRoleA = this.name === roleA.name;
|
|
370
|
-
const selfRole = amRoleA ? roleA : roleB;
|
|
371
|
-
const refRole = amRoleA ? roleB : roleA;
|
|
372
|
-
let selfTone = selfRole.tone(scheme);
|
|
373
|
-
const refTone = refRole.getTone(scheme);
|
|
374
|
-
const relativeDelta = absoluteDelta * (amRoleA ? 1 : -1);
|
|
375
|
-
|
|
376
|
-
if (constraint === 'exact') {
|
|
377
|
-
selfTone = clampDouble(0, 100, refTone + relativeDelta);
|
|
378
|
-
} else if (constraint === 'nearer') {
|
|
379
|
-
if (relativeDelta > 0) {
|
|
380
|
-
selfTone = clampDouble(
|
|
381
|
-
0,
|
|
382
|
-
100,
|
|
383
|
-
clampDouble(refTone, refTone + relativeDelta, selfTone),
|
|
384
|
-
);
|
|
385
|
-
} else {
|
|
386
|
-
selfTone = clampDouble(
|
|
387
|
-
0,
|
|
388
|
-
100,
|
|
389
|
-
clampDouble(refTone + relativeDelta, refTone, selfTone),
|
|
390
|
-
);
|
|
391
|
-
}
|
|
392
|
-
} else if (constraint === 'farther') {
|
|
393
|
-
if (relativeDelta > 0) {
|
|
394
|
-
selfTone = clampDouble(refTone + relativeDelta, 100, selfTone);
|
|
395
|
-
} else {
|
|
396
|
-
selfTone = clampDouble(0, refTone + relativeDelta, selfTone);
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
if (this.background && this.contrastCurve) {
|
|
401
|
-
const background = this.background(scheme);
|
|
402
|
-
const contrastCurve = this.contrastCurve(scheme);
|
|
403
|
-
if (background && contrastCurve) {
|
|
404
|
-
// Adjust the tones for contrast, if background and contrast curve
|
|
405
|
-
// are defined.
|
|
406
|
-
const bgTone = background.getTone(scheme);
|
|
407
|
-
const selfContrast = contrastCurve.get(scheme.contrastLevel);
|
|
408
|
-
selfTone =
|
|
409
|
-
Contrast.ratioOfTones(bgTone, selfTone) >= selfContrast &&
|
|
410
|
-
scheme.contrastLevel >= 0
|
|
411
|
-
? selfTone
|
|
412
|
-
: DynamicColor.foregroundTone(bgTone, selfContrast);
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
// This can avoid the awkward tones for background colors including the
|
|
417
|
-
// access fixed colors. Accent fixed dim colors should not be adjusted.
|
|
418
|
-
if (this.isBackground && !this.name.endsWith('_fixed_dim')) {
|
|
419
|
-
if (selfTone >= 57) {
|
|
420
|
-
selfTone = clampDouble(65, 100, selfTone);
|
|
421
|
-
} else {
|
|
422
|
-
selfTone = clampDouble(0, 49, selfTone);
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
return selfTone;
|
|
323
|
+
if (adjustTone) {
|
|
324
|
+
return adjustTone({ scheme, dynamicColor: this });
|
|
427
325
|
} else {
|
|
428
326
|
// Case 1: No tone delta pair; just solve for itself.
|
|
429
327
|
let answer = this.tone(scheme);
|
|
@@ -15,7 +15,9 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import { DynamicColor } from './dynamic_color';
|
|
18
|
+
import { AdjustTone, DynamicColor } from './dynamic_color';
|
|
19
|
+
import { clampDouble, Contrast } from '@material/material-color-utilities';
|
|
20
|
+
import { Scheme } from '../theme';
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
* Describes the different in tone between colors.
|
|
@@ -43,7 +45,7 @@ export type DeltaConstraint = 'exact' | 'nearer' | 'farther';
|
|
|
43
45
|
* designers want tonal distance, literally contrast, between two colors that
|
|
44
46
|
* don't have a background / foreground relationship or a contrast guarantee.
|
|
45
47
|
*/
|
|
46
|
-
|
|
48
|
+
class ToneDeltaPair {
|
|
47
49
|
/**
|
|
48
50
|
* Documents a constraint in tone distance between two DynamicColors.
|
|
49
51
|
*
|
|
@@ -79,4 +81,91 @@ export class ToneDeltaPair {
|
|
|
79
81
|
) {
|
|
80
82
|
this.constraint = constraint ?? 'exact';
|
|
81
83
|
}
|
|
84
|
+
|
|
85
|
+
adjustedTone({
|
|
86
|
+
scheme,
|
|
87
|
+
dynamicColor,
|
|
88
|
+
}: {
|
|
89
|
+
scheme: Scheme;
|
|
90
|
+
dynamicColor: DynamicColor;
|
|
91
|
+
}) {
|
|
92
|
+
const roleA = this.roleA;
|
|
93
|
+
const roleB = this.roleB;
|
|
94
|
+
const polarity = this.polarity;
|
|
95
|
+
const constraint = this.constraint;
|
|
96
|
+
const absoluteDelta =
|
|
97
|
+
polarity === 'darker' ||
|
|
98
|
+
(polarity === 'relative_lighter' && scheme.isDark) ||
|
|
99
|
+
(polarity === 'relative_darker' && !scheme.isDark)
|
|
100
|
+
? -this.delta
|
|
101
|
+
: this.delta;
|
|
102
|
+
|
|
103
|
+
const amRoleA = dynamicColor.name === roleA.name;
|
|
104
|
+
const selfRole = amRoleA ? roleA : roleB;
|
|
105
|
+
const refRole = amRoleA ? roleB : roleA;
|
|
106
|
+
let selfTone = selfRole.tone(scheme);
|
|
107
|
+
const refTone = refRole.getTone(scheme);
|
|
108
|
+
const relativeDelta = absoluteDelta * (amRoleA ? 1 : -1);
|
|
109
|
+
|
|
110
|
+
if (constraint === 'exact') {
|
|
111
|
+
selfTone = clampDouble(0, 100, refTone + relativeDelta);
|
|
112
|
+
} else if (constraint === 'nearer') {
|
|
113
|
+
if (relativeDelta > 0) {
|
|
114
|
+
selfTone = clampDouble(
|
|
115
|
+
0,
|
|
116
|
+
100,
|
|
117
|
+
clampDouble(refTone, refTone + relativeDelta, selfTone),
|
|
118
|
+
);
|
|
119
|
+
} else {
|
|
120
|
+
selfTone = clampDouble(
|
|
121
|
+
0,
|
|
122
|
+
100,
|
|
123
|
+
clampDouble(refTone + relativeDelta, refTone, selfTone),
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
} else if (constraint === 'farther') {
|
|
127
|
+
if (relativeDelta > 0) {
|
|
128
|
+
selfTone = clampDouble(refTone + relativeDelta, 100, selfTone);
|
|
129
|
+
} else {
|
|
130
|
+
selfTone = clampDouble(0, refTone + relativeDelta, selfTone);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (dynamicColor.background && dynamicColor.contrastCurve) {
|
|
135
|
+
const background = dynamicColor.background(scheme);
|
|
136
|
+
const contrastCurve = dynamicColor.contrastCurve(scheme);
|
|
137
|
+
if (background && contrastCurve) {
|
|
138
|
+
// Adjust the tones for contrast, if background and contrast curve
|
|
139
|
+
// are defined.
|
|
140
|
+
const bgTone = background.getTone(scheme);
|
|
141
|
+
const selfContrast = contrastCurve.get(scheme.contrastLevel);
|
|
142
|
+
selfTone =
|
|
143
|
+
Contrast.ratioOfTones(bgTone, selfTone) >= selfContrast &&
|
|
144
|
+
scheme.contrastLevel >= 0
|
|
145
|
+
? selfTone
|
|
146
|
+
: DynamicColor.foregroundTone(bgTone, selfContrast);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// This can avoid the awkward tones for background colors including the
|
|
151
|
+
// access fixed colors. Accent fixed dim colors should not be adjusted.
|
|
152
|
+
if (
|
|
153
|
+
dynamicColor.isBackground &&
|
|
154
|
+
!dynamicColor.name.endsWith('_fixed_dim')
|
|
155
|
+
) {
|
|
156
|
+
if (selfTone >= 57) {
|
|
157
|
+
selfTone = clampDouble(65, 100, selfTone);
|
|
158
|
+
} else {
|
|
159
|
+
selfTone = clampDouble(0, 49, selfTone);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return selfTone;
|
|
164
|
+
}
|
|
82
165
|
}
|
|
166
|
+
|
|
167
|
+
export const toneDeltaPair = (
|
|
168
|
+
...params: ConstructorParameters<typeof ToneDeltaPair>
|
|
169
|
+
): AdjustTone => {
|
|
170
|
+
return (args) => new ToneDeltaPair(...params).adjustedTone(args);
|
|
171
|
+
};
|
package/src/theme/scheme.ts
CHANGED
|
@@ -13,7 +13,13 @@ export interface SchemeOptions {
|
|
|
13
13
|
export class Scheme {
|
|
14
14
|
constructor(readonly options: SchemeOptions) {}
|
|
15
15
|
|
|
16
|
-
get variant():
|
|
16
|
+
get variant():
|
|
17
|
+
| 'expressive'
|
|
18
|
+
| 'neutral'
|
|
19
|
+
| 'tonalSpot'
|
|
20
|
+
| 'vibrant'
|
|
21
|
+
| 'fidelity'
|
|
22
|
+
| string {
|
|
17
23
|
return this.options.variant.name;
|
|
18
24
|
}
|
|
19
25
|
|