@udixio/theme 1.2.0 → 1.3.1

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 (38) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/bin.cjs +1 -1
  3. package/dist/bin.js +1 -1
  4. package/dist/browser.cjs +3 -4
  5. package/dist/browser.js +11 -12
  6. package/dist/color/color.manager.d.ts.map +1 -1
  7. package/dist/color/default-color.d.ts.map +1 -1
  8. package/dist/{define-config-CGG8l3fb.js → define-config-BasMdCqD.js} +32 -2
  9. package/dist/{define-config-BFo7Sy7c.cjs → define-config-CKSsLMnc.cjs} +32 -2
  10. package/dist/{load-from-path-CFpw2P_Y.js → load-from-path-Bo1kCfh9.js} +1 -1
  11. package/dist/{load-from-path-BvdfXUD0.cjs → load-from-path-DoZnR1-p.cjs} +2 -2
  12. package/dist/loader/loader.d.ts.map +1 -1
  13. package/dist/{loader-C_BIrsO2.js → loader-C8_TyOuS.js} +132 -119
  14. package/dist/{loader-TksB6_mM.cjs → loader-R7hccp8_.cjs} +124 -111
  15. package/dist/material-color-utilities/dynamic_color.d.ts +9 -15
  16. package/dist/material-color-utilities/dynamic_color.d.ts.map +1 -1
  17. package/dist/material-color-utilities/toneDeltaPair.d.ts +9 -2
  18. package/dist/material-color-utilities/toneDeltaPair.d.ts.map +1 -1
  19. package/dist/node.cjs +4 -5
  20. package/dist/node.js +13 -14
  21. package/dist/theme/scheme.d.ts +1 -1
  22. package/dist/theme/scheme.d.ts.map +1 -1
  23. package/dist/theme/theme.api.d.ts +1 -0
  24. package/dist/theme/theme.api.d.ts.map +1 -1
  25. package/dist/theme/variants/fidelity.variant.d.ts +3 -0
  26. package/dist/theme/variants/fidelity.variant.d.ts.map +1 -0
  27. package/dist/theme/variants/index.d.ts +1 -0
  28. package/dist/theme/variants/index.d.ts.map +1 -1
  29. package/package.json +1 -1
  30. package/src/color/color.manager.ts +10 -8
  31. package/src/color/default-color.ts +82 -34
  32. package/src/loader/loader.ts +1 -5
  33. package/src/material-color-utilities/dynamic_color.ts +18 -120
  34. package/src/material-color-utilities/toneDeltaPair.ts +91 -2
  35. package/src/theme/scheme.ts +7 -1
  36. package/src/theme/theme.api.ts +4 -0
  37. package/src/theme/variants/fidelity.variant.ts +38 -0
  38. package/src/theme/variants/index.ts +2 -0
@@ -11,7 +11,7 @@ export interface SchemeOptions {
11
11
  export declare class Scheme {
12
12
  readonly options: SchemeOptions;
13
13
  constructor(options: SchemeOptions);
14
- get variant(): 'expressive' | 'neutral' | 'tonalSpot' | 'vibrant' | string;
14
+ get variant(): 'expressive' | 'neutral' | 'tonalSpot' | 'vibrant' | 'fidelity' | string;
15
15
  get contrastLevel(): number;
16
16
  get isDark(): boolean;
17
17
  get sourceColorHct(): Hct;
@@ -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,IAAI,YAAY,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,MAAM,CAEzE;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"}
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"}
@@ -11,6 +11,7 @@ export declare class ThemeApi {
11
11
  schemeManager: SchemeManager;
12
12
  variantManager: VariantManager;
13
13
  });
14
+ get sourceColorHex(): import('../material-color-utilities/htc').Hct;
14
15
  create(options: ThemeOptions & {
15
16
  variant: Variant;
16
17
  }): void;
@@ -1 +1 @@
1
- {"version":3,"file":"theme.api.d.ts","sourceRoot":"","sources":["../../src/theme/theme.api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,KAAK,YAAY,GAAG,IAAI,CACtB,oBAAoB,EACpB,UAAU,GAAG,iBAAiB,CAC/B,GAAG;IAAE,cAAc,EAAE,MAAM,CAAA;CAAE,CAAC;AAQ/B,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAC9C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAiB;gBAEpC,EACV,aAAa,EACb,cAAc,GACf,EAAE;QACD,aAAa,EAAE,aAAa,CAAC;QAC7B,cAAc,EAAE,cAAc,CAAC;KAChC;IA4BD,MAAM,CAAC,OAAO,EAAE,YAAY,GAAG;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE;IAQnD,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG;QAAE,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE;IAQ7D,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAO/C"}
1
+ {"version":3,"file":"theme.api.d.ts","sourceRoot":"","sources":["../../src/theme/theme.api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,KAAK,YAAY,GAAG,IAAI,CACtB,oBAAoB,EACpB,UAAU,GAAG,iBAAiB,CAC/B,GAAG;IAAE,cAAc,EAAE,MAAM,CAAA;CAAE,CAAC;AAQ/B,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAC9C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAiB;gBAEpC,EACV,aAAa,EACb,cAAc,GACf,EAAE;QACD,aAAa,EAAE,aAAa,CAAC;QAC7B,cAAc,EAAE,cAAc,CAAC;KAChC;IA4BD,IAAI,cAAc,kDAEjB;IAED,MAAM,CAAC,OAAO,EAAE,YAAY,GAAG;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE;IAQnD,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG;QAAE,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE;IAQ7D,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAO/C"}
@@ -0,0 +1,3 @@
1
+ import { Variant } from '../variant';
2
+ export declare const fidelityVariant: Variant;
3
+ //# sourceMappingURL=fidelity.variant.d.ts.map
@@ -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"}
@@ -7,5 +7,6 @@ export declare const Variants: {
7
7
  Neutral: import('..').Variant;
8
8
  TonalSpot: import('..').Variant;
9
9
  Vibrant: import('..').Variant;
10
+ Fidelity: import('..').Variant;
10
11
  };
11
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/theme/variants/index.ts"],"names":[],"mappings":"AAKA,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAElC,eAAO,MAAM,QAAQ;;;;;CAKpB,CAAC"}
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@udixio/theme",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "type": "module",
5
5
  "main": "./dist/node.js",
6
6
  "module": "./dist/node.js",
@@ -1,4 +1,4 @@
1
- import { DynamicColor, ToneDeltaPair } from '../material-color-utilities';
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
- toneDeltaPair: (s) =>
119
- new ToneDeltaPair(
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
- toneDeltaPair: (s) =>
141
- new ToneDeltaPair(
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
- toneDeltaPair: (s) => undefined,
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
- toneDeltaPair: (s) =>
193
- new ToneDeltaPair(
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 { ToneDeltaPair } from '../material-color-utilities';
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
- toneDeltaPair: (s) =>
362
- new ToneDeltaPair(
363
- colorService.getColor('primaryContainer').getMaterialColor(),
364
- colorService.getColor('primary').getMaterialColor(),
365
- 5,
366
- 'relative_lighter',
367
- true,
368
- 'farther',
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
- toneDeltaPair: (s) =>
386
- new ToneDeltaPair(
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
- toneDeltaPair: (s) => undefined,
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
- toneDeltaPair: (s) =>
461
- new ToneDeltaPair(
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
- toneDeltaPair: (s) =>
513
- new ToneDeltaPair(
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
- toneDeltaPair: (s) =>
535
- new ToneDeltaPair(
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
- toneDeltaPair: (s) => undefined,
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
- toneDeltaPair: (s) =>
593
- new ToneDeltaPair(
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
- toneDeltaPair: (s) =>
638
- new ToneDeltaPair(
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
- toneDeltaPair: (s) =>
660
- new ToneDeltaPair(
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
- toneDeltaPair: (s) => undefined,
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
- toneDeltaPair: (s) =>
727
- new ToneDeltaPair(
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
- toneDeltaPair: (s) =>
764
- new ToneDeltaPair(
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
- toneDeltaPair: (s) =>
780
- new ToneDeltaPair(
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
- toneDeltaPair: (s) => undefined,
851
+ adjustTone: (s) => undefined,
804
852
  contrastCurve: (s) => (s.contrastLevel > 0 ? getCurve(1.5) : undefined),
805
853
  },
806
854
  onErrorContainer: {
@@ -52,12 +52,8 @@ export const loader = async (config: ConfigInterface) => {
52
52
  }
53
53
  };
54
54
 
55
- const load = async () => {
56
- await api.plugins.loadPlugins();
57
- };
58
-
59
55
  init();
60
- await load();
56
+ await api.load();
61
57
 
62
58
  return api;
63
59
  };
@@ -15,9 +15,12 @@
15
15
  * limitations under the License.
16
16
  */
17
17
 
18
- import { clampDouble, Contrast, TonalPalette } from '@material/material-color-utilities';
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 toneDeltaPair A `ToneDeltaPair` object specifying a tone delta
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
- toneDeltaPair?: (scheme: Scheme) => ToneDeltaPair | undefined;
62
+ adjustTone?: (scheme: Scheme) => AdjustTone | undefined;
60
63
  }
61
64
 
62
- /**
63
- * Returns a new DynamicColor that is the same as the original color, but with
64
- * the extended dynamic color's constraints for the given spec version.
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 toneDeltaPair A `ToneDeltaPair` object specifying a tone delta
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 toneDeltaPair?: (scheme: Scheme) => ToneDeltaPair | undefined,
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.toneDeltaPair,
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
- toneDeltaPair: this.toneDeltaPair,
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 toneDeltaPair = this.toneDeltaPair
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 (toneDeltaPair) {
358
- const roleA = toneDeltaPair.roleA;
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);