@udixio/theme 1.3.1 → 2.1.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.
Files changed (144) hide show
  1. package/CHANGELOG.md +23 -2
  2. package/dist/API.d.ts +7 -4
  3. package/dist/API.d.ts.map +1 -1
  4. package/dist/app.container.d.ts +1 -2
  5. package/dist/app.container.d.ts.map +1 -1
  6. package/dist/bin.cjs +1 -1
  7. package/dist/bin.js +1 -1
  8. package/dist/browser.cjs +23 -18
  9. package/dist/browser.js +34 -29
  10. package/dist/color/color.api.d.ts +16 -31
  11. package/dist/color/color.api.d.ts.map +1 -1
  12. package/dist/color/color.d.ts +100 -0
  13. package/dist/color/color.d.ts.map +1 -0
  14. package/dist/color/color.manager.d.ts +9 -18
  15. package/dist/color/color.manager.d.ts.map +1 -1
  16. package/dist/color/color.utils.d.ts +14 -3
  17. package/dist/color/color.utils.d.ts.map +1 -1
  18. package/dist/color/default-color.d.ts +5 -1
  19. package/dist/color/default-color.d.ts.map +1 -1
  20. package/dist/color/index.d.ts +1 -1
  21. package/dist/color/index.d.ts.map +1 -1
  22. package/dist/config/config.interface.d.ts +4 -4
  23. package/dist/config/config.interface.d.ts.map +1 -1
  24. package/dist/context/context.d.ts +41 -0
  25. package/dist/context/context.d.ts.map +1 -0
  26. package/dist/context/context.module.d.ts +3 -0
  27. package/dist/context/context.module.d.ts.map +1 -0
  28. package/dist/context/index.d.ts +3 -0
  29. package/dist/context/index.d.ts.map +1 -0
  30. package/dist/font.plugin-5Xpo-ntw.js +228 -0
  31. package/dist/font.plugin-FPU_gL1Y.cjs +227 -0
  32. package/dist/index.d.ts +6 -4
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/{load-from-path-Bo1kCfh9.js → load-from-path-CBnO8ESw.js} +1 -1
  35. package/dist/{load-from-path-DoZnR1-p.cjs → load-from-path-kuofMGN3.cjs} +2 -2
  36. package/dist/loader/loader.d.ts +1 -1
  37. package/dist/loader/loader.d.ts.map +1 -1
  38. package/dist/loader-BzsrGBu-.cjs +3905 -0
  39. package/dist/loader-CoayTlSl.js +3906 -0
  40. package/dist/material-color-utilities/dynamic_color.d.ts +0 -22
  41. package/dist/material-color-utilities/dynamic_color.d.ts.map +1 -1
  42. package/dist/material-color-utilities/toneDeltaPair.d.ts +8 -8
  43. package/dist/material-color-utilities/toneDeltaPair.d.ts.map +1 -1
  44. package/dist/node.cjs +24 -19
  45. package/dist/node.js +36 -31
  46. package/dist/palette/index.d.ts +4 -0
  47. package/dist/palette/index.d.ts.map +1 -0
  48. package/dist/palette/palette.api.d.ts +13 -0
  49. package/dist/palette/palette.api.d.ts.map +1 -0
  50. package/dist/palette/palette.d.ts +33 -0
  51. package/dist/palette/palette.d.ts.map +1 -0
  52. package/dist/palette/palette.manager.d.ts +20 -0
  53. package/dist/palette/palette.manager.d.ts.map +1 -0
  54. package/dist/palette/palette.module.d.ts +3 -0
  55. package/dist/palette/palette.module.d.ts.map +1 -0
  56. package/dist/plugins/font/font.plugin.d.ts +1 -1
  57. package/dist/plugins/font/font.plugin.d.ts.map +1 -1
  58. package/dist/variant/index.d.ts +3 -0
  59. package/dist/variant/index.d.ts.map +1 -0
  60. package/dist/variant/variant.d.ts +31 -0
  61. package/dist/variant/variant.d.ts.map +1 -0
  62. package/dist/variant/variants/expressive.variant.d.ts +2 -0
  63. package/dist/variant/variants/expressive.variant.d.ts.map +1 -0
  64. package/dist/{theme → variant}/variants/index.d.ts +1 -1
  65. package/dist/variant/variants/index.d.ts.map +1 -0
  66. package/dist/variant/variants/neutral.variant.d.ts.map +1 -0
  67. package/dist/variant/variants/tonal-spot.variant.d.ts.map +1 -0
  68. package/dist/variant/variants/udixio.variant.d.ts +3 -0
  69. package/dist/variant/variants/udixio.variant.d.ts.map +1 -0
  70. package/dist/variant/variants/vibrant.variant.d.ts.map +1 -0
  71. package/package.json +1 -1
  72. package/src/API.ts +12 -5
  73. package/src/app.container.ts +22 -11
  74. package/src/bootstrap.ts +1 -1
  75. package/src/color/color.api.ts +189 -47
  76. package/src/color/color.manager.ts +34 -189
  77. package/src/color/color.ts +295 -0
  78. package/src/color/color.utils.ts +48 -3
  79. package/src/color/default-color.ts +390 -425
  80. package/src/color/index.ts +1 -1
  81. package/src/config/config.interface.ts +5 -4
  82. package/src/context/context.module.ts +7 -0
  83. package/src/context/context.ts +169 -0
  84. package/src/context/index.ts +2 -0
  85. package/src/index.ts +6 -4
  86. package/src/loader/loader.ts +11 -24
  87. package/src/material-color-utilities/dynamic_color.ts +25 -34
  88. package/src/material-color-utilities/toneDeltaPair.ts +44 -41
  89. package/src/palette/index.ts +3 -0
  90. package/src/palette/palette.api.ts +43 -0
  91. package/src/palette/palette.manager.ts +74 -0
  92. package/src/palette/palette.module.ts +9 -0
  93. package/src/palette/palette.ts +206 -0
  94. package/src/plugins/font/font.plugin.ts +1 -1
  95. package/src/variant/index.ts +2 -0
  96. package/src/variant/variant.ts +84 -0
  97. package/src/{theme → variant}/variants/expressive.variant.ts +33 -29
  98. package/src/{theme → variant}/variants/index.ts +2 -2
  99. package/src/variant/variants/neutral.variant.ts +47 -0
  100. package/src/variant/variants/tonal-spot.variant.ts +37 -0
  101. package/src/variant/variants/udixio.variant.ts +846 -0
  102. package/src/{theme → variant}/variants/vibrant.variant.ts +23 -22
  103. package/dist/color/configurable-color.d.ts +0 -31
  104. package/dist/color/configurable-color.d.ts.map +0 -1
  105. package/dist/define-config-BasMdCqD.js +0 -430
  106. package/dist/define-config-CKSsLMnc.cjs +0 -429
  107. package/dist/loader-C8_TyOuS.js +0 -2698
  108. package/dist/loader-R7hccp8_.cjs +0 -2697
  109. package/dist/theme/index.d.ts +0 -8
  110. package/dist/theme/index.d.ts.map +0 -1
  111. package/dist/theme/scheme.d.ts +0 -20
  112. package/dist/theme/scheme.d.ts.map +0 -1
  113. package/dist/theme/scheme.manager.d.ts +0 -31
  114. package/dist/theme/scheme.manager.d.ts.map +0 -1
  115. package/dist/theme/theme.api.d.ts +0 -24
  116. package/dist/theme/theme.api.d.ts.map +0 -1
  117. package/dist/theme/theme.module.d.ts +0 -3
  118. package/dist/theme/theme.module.d.ts.map +0 -1
  119. package/dist/theme/variant.d.ts +0 -36
  120. package/dist/theme/variant.d.ts.map +0 -1
  121. package/dist/theme/variant.manager.d.ts +0 -14
  122. package/dist/theme/variant.manager.d.ts.map +0 -1
  123. package/dist/theme/variants/expressive.variant.d.ts +0 -3
  124. package/dist/theme/variants/expressive.variant.d.ts.map +0 -1
  125. package/dist/theme/variants/fidelity.variant.d.ts +0 -3
  126. package/dist/theme/variants/fidelity.variant.d.ts.map +0 -1
  127. package/dist/theme/variants/index.d.ts.map +0 -1
  128. package/dist/theme/variants/neutral.variant.d.ts.map +0 -1
  129. package/dist/theme/variants/tonal-spot.variant.d.ts.map +0 -1
  130. package/dist/theme/variants/vibrant.variant.d.ts.map +0 -1
  131. package/src/color/configurable-color.ts +0 -67
  132. package/src/theme/index.ts +0 -7
  133. package/src/theme/scheme.manager.ts +0 -100
  134. package/src/theme/scheme.ts +0 -66
  135. package/src/theme/theme.api.ts +0 -82
  136. package/src/theme/theme.module.ts +0 -11
  137. package/src/theme/variant.manager.ts +0 -58
  138. package/src/theme/variant.ts +0 -53
  139. package/src/theme/variants/fidelity.variant.ts +0 -38
  140. package/src/theme/variants/neutral.variant.ts +0 -45
  141. package/src/theme/variants/tonal-spot.variant.ts +0 -35
  142. /package/dist/{theme → variant}/variants/neutral.variant.d.ts +0 -0
  143. /package/dist/{theme → variant}/variants/tonal-spot.variant.d.ts +0 -0
  144. /package/dist/{theme → variant}/variants/vibrant.variant.d.ts +0 -0
@@ -1,75 +1,217 @@
1
- import { ColorOptions, ConfigurableColor } from './configurable-color';
1
+ import { Color, ColorOptions } from './color';
2
2
  import { ColorManager } from './color.manager';
3
- import { DynamicColorKey } from './color.utils';
3
+ import { DynamicColorKey, getCurve, tMaxC, tMinC } from './color.utils';
4
+ import { API } from '../API';
5
+ import { toneDeltaPair } from '../material-color-utilities';
6
+ import { Context } from 'src/context';
7
+ import { highestSurface } from './default-color';
4
8
 
5
- export type AddColors = {
6
- colors?: Record<
7
- DynamicColorKey | string,
8
- | (Partial<ColorOptions> & { alias?: never })
9
- | { alias: string; palette?: never; tone?: never }
10
- >;
11
- fromPalettes?: string[] | string;
12
- };
9
+ export function capitalizeFirstLetter(string: string) {
10
+ return string.charAt(0).toUpperCase() + string.slice(1);
11
+ }
13
12
 
14
13
  export type AddColorsOptions =
15
- | AddColors
16
- | ((colorService: ColorApi) => AddColors);
14
+ | ((args: API) => Record<string, ColorOptions>)
15
+ | Record<string, ColorOptions>;
17
16
 
18
17
  export class ColorApi {
19
18
  private readonly colorManager: ColorManager;
19
+ private readonly context: Context;
20
+ public api?: API;
20
21
 
21
- constructor({ colorManager }: { colorManager: ColorManager }) {
22
+ constructor({
23
+ colorManager,
24
+ context,
25
+ }: {
26
+ colorManager: ColorManager;
27
+ context: Context;
28
+ }) {
29
+ this.context = context;
22
30
  this.colorManager = colorManager;
31
+
32
+ this.context.onUpdate((changed) => {
33
+ if (changed.includes('variant')) {
34
+ this.colorManager.clear();
35
+ this.addColors(this.context.variant.colors);
36
+ }
37
+ });
23
38
  }
24
39
 
25
- getColors() {
40
+ getAll() {
26
41
  return this.colorManager.getAll();
27
42
  }
28
43
 
29
- addColor(
30
- key: string,
31
- color:
32
- | (Partial<ColorOptions> & { alias?: never })
33
- | { alias: string; palette?: never; tone?: never },
34
- ): ConfigurableColor {
44
+ addColor(key: string, color: ColorOptions): Color {
35
45
  return this.colorManager.createOrUpdate(key, color);
36
46
  }
37
47
 
38
- addColors(args: AddColorsOptions | AddColorsOptions[]) {
39
- if (!Array.isArray(args)) args = [args];
40
- args.forEach((args) => {
41
- if (typeof args === 'function') {
42
- args = args(this);
43
- }
44
- if (args.fromPalettes) {
45
- if (!Array.isArray(args.fromPalettes))
46
- args.fromPalettes = [args.fromPalettes];
47
- args.fromPalettes.map((paletteKey) => {
48
- this.colorManager.addFromPalette(paletteKey);
49
- });
50
- }
51
- if (args.colors) {
52
- Object.keys(args.colors).map((key) =>
53
- this.addColor(key, args.colors![key]),
54
- );
55
- }
56
- });
48
+ addColors(args: AddColorsOptions) {
49
+ if (!this.api)
50
+ throw new Error(
51
+ 'The API is not initialized. Please call bootstrap() before calling addColors().',
52
+ );
53
+
54
+ if (typeof args === 'function') {
55
+ args = args(this.api);
56
+ }
57
+ if (args) {
58
+ Object.entries(args).forEach(([name, colorOption]) => {
59
+ this.addColor(name, colorOption);
60
+ });
61
+ }
57
62
  }
58
63
 
59
- getColor(key: DynamicColorKey | string): ConfigurableColor {
64
+ get(key: DynamicColorKey | string): Color {
60
65
  return this.colorManager.get(key);
61
66
  }
62
67
 
63
- removeColor(key: string): boolean {
68
+ remove(key: string): boolean {
64
69
  return this.colorManager.remove(key);
65
70
  }
66
71
 
67
- updateColor(
68
- key: string,
69
- newColor:
70
- | (Partial<ColorOptions> & { alias?: never })
71
- | { alias: string; palette?: never; tone?: never },
72
- ): ConfigurableColor {
72
+ update(key: string, newColor: ColorOptions): Color {
73
73
  return this.colorManager.createOrUpdate(key, newColor);
74
74
  }
75
+
76
+ addFromCustomPalette(key: string): void {
77
+ if (this.context.variant.colorsFromCustomPalette) {
78
+ return this.addColors(this.context.variant.colorsFromCustomPalette(key));
79
+ }
80
+
81
+ const colorKey = key as DynamicColorKey;
82
+ const colorDimKey = (colorKey + 'Dim') as DynamicColorKey;
83
+ const ColorKey = capitalizeFirstLetter(key);
84
+ const onColorKey = ('on' + ColorKey) as DynamicColorKey;
85
+ const colorContainerKey = (colorKey + 'Container') as DynamicColorKey;
86
+ const onColorContainerKey = ('on' +
87
+ ColorKey +
88
+ 'Container') as DynamicColorKey;
89
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
90
+ // @ts-expect-error
91
+ const inverseColorKey = ('inverse' + ColorKey) as DynamicColorKey;
92
+ const colorFixedKey = (colorKey + 'Fixed') as DynamicColorKey;
93
+ const colorFixedDimKey = (colorKey + 'FixedDim') as DynamicColorKey;
94
+ const onColorFixedKey = ('on' + ColorKey + 'Fixed') as DynamicColorKey;
95
+ const onColorFixedVariantKey = ('on' +
96
+ ColorKey +
97
+ 'FixedVariant') as DynamicColorKey;
98
+ const colors: AddColorsOptions = ({ palettes, colors, context: ctx }) => ({
99
+ [colorKey]: {
100
+ palette: () => palettes.get(colorKey),
101
+ tone: () => {
102
+ if (ctx.variant.name === 'neutral') {
103
+ return ctx.isDark
104
+ ? tMinC(palettes.get(colorKey), 0, 98)
105
+ : tMaxC(palettes.get(colorKey));
106
+ } else if (ctx.variant.name === 'vibrant') {
107
+ return tMaxC(palettes.get(colorKey), 0, ctx.isDark ? 90 : 98);
108
+ } else {
109
+ return ctx.isDark ? 80 : tMaxC(palettes.get(colorKey));
110
+ }
111
+ },
112
+ isBackground: true,
113
+ background: () => highestSurface(ctx, this),
114
+ contrastCurve: () => getCurve(4.5),
115
+ adjustTone: () =>
116
+ toneDeltaPair(
117
+ colors.get(colorContainerKey),
118
+ colors.get(colorKey),
119
+ 5,
120
+ 'relative_lighter',
121
+ true,
122
+ 'farther',
123
+ ),
124
+ },
125
+ [colorDimKey]: {
126
+ palette: () => palettes.get(colorKey),
127
+ tone: () => {
128
+ if (ctx.variant.name === 'neutral') {
129
+ return 85;
130
+ } else {
131
+ return tMaxC(palettes.get(colorKey), 0, 90);
132
+ }
133
+ },
134
+ isBackground: true,
135
+ background: () => this.get('surfaceContainerHigh'),
136
+ contrastCurve: () => getCurve(4.5),
137
+ adjustTone: () =>
138
+ toneDeltaPair(
139
+ this.get(colorDimKey),
140
+ this.get(colorKey),
141
+ 5,
142
+ 'darker',
143
+ true,
144
+ 'farther',
145
+ ),
146
+ },
147
+ [onColorKey]: {
148
+ palette: () => palettes.get(colorKey),
149
+ background: () => this.get(colorKey),
150
+ contrastCurve: () => getCurve(6),
151
+ },
152
+ [colorContainerKey]: {
153
+ palette: () => palettes.get(colorKey),
154
+ tone: () => {
155
+ if (ctx.variant.name === 'vibrant') {
156
+ return ctx.isDark
157
+ ? tMinC(palettes.get(colorKey), 30, 40)
158
+ : tMaxC(palettes.get(colorKey), 84, 90);
159
+ } else if (ctx.variant.name === 'expressive') {
160
+ return ctx.isDark ? 15 : tMaxC(palettes.get(colorKey), 90, 95);
161
+ } else {
162
+ return ctx.isDark ? 25 : 90;
163
+ }
164
+ },
165
+ isBackground: true,
166
+ background: () => highestSurface(ctx, this),
167
+ adjustTone: () => undefined,
168
+ contrastCurve: () =>
169
+ ctx.contrastLevel > 0 ? getCurve(1.5) : undefined,
170
+ },
171
+ [onColorContainerKey]: {
172
+ palette: () => palettes.get(colorKey),
173
+ background: () => this.get(colorContainerKey),
174
+ contrastCurve: () => getCurve(6),
175
+ },
176
+ [colorFixedKey]: {
177
+ palette: () => palettes.get(colorKey),
178
+ tone: () => {
179
+ return ctx.temp({ isDark: false, contrastLevel: 0 }, () => {
180
+ const color = this.get(colorContainerKey);
181
+ return color.getTone();
182
+ });
183
+ },
184
+ isBackground: true,
185
+ background: () => highestSurface(ctx, this),
186
+ contrastCurve: () =>
187
+ ctx.contrastLevel > 0 ? getCurve(1.5) : undefined,
188
+ },
189
+ [colorFixedDimKey]: {
190
+ palette: () => palettes.get(colorKey),
191
+ tone: () => this.get(colorFixedKey).getTone(),
192
+ isBackground: true,
193
+ adjustTone: () =>
194
+ toneDeltaPair(
195
+ this.get(colorFixedDimKey),
196
+ this.get(colorFixedKey),
197
+ 5,
198
+ 'darker',
199
+ true,
200
+ 'exact',
201
+ ),
202
+ },
203
+ [onColorFixedKey]: {
204
+ palette: () => palettes.get(colorKey),
205
+ background: () => this.get(colorFixedDimKey),
206
+ contrastCurve: () => getCurve(7),
207
+ },
208
+ [onColorFixedVariantKey]: {
209
+ palette: () => palettes.get(colorKey),
210
+ background: () => this.get(colorFixedDimKey),
211
+ contrastCurve: () => getCurve(4.5),
212
+ },
213
+ });
214
+
215
+ this.addColors(colors);
216
+ }
75
217
  }
@@ -1,67 +1,39 @@
1
- import { DynamicColor, toneDeltaPair } from '../material-color-utilities';
2
- import { Scheme, SchemeManager } from '../theme';
3
-
4
- import { ColorOptions, ConfigurableColor } from './configurable-color';
5
- import { DynamicColorKey, getCurve, tMaxC, tMinC } from './color.utils';
6
- import { ColorApi } from './color.api';
7
-
8
- function capitalizeFirstLetter(string: string) {
9
- return string.charAt(0).toUpperCase() + string.slice(1);
10
- }
11
-
12
- export const highestSurface = (
13
- s: Scheme,
14
- colorService: ColorManager | ColorApi,
15
- ): DynamicColor => {
16
- if (colorService instanceof ColorApi) {
17
- return s.isDark
18
- ? colorService.getColor('surfaceBright').getMaterialColor()
19
- : colorService.getColor('surfaceDim').getMaterialColor();
20
- } else {
21
- return s.isDark
22
- ? colorService.get('surfaceBright').getMaterialColor()
23
- : colorService.get('surfaceDim').getMaterialColor();
24
- }
25
- };
1
+ import {
2
+ Color,
3
+ ColorAlias,
4
+ ColorFromHex,
5
+ ColorFromPalette,
6
+ ColorOptions,
7
+ } from './color';
8
+ import { Context } from '../context';
26
9
 
27
10
  export class ColorManager {
28
- private colorMap = new Map<string, ConfigurableColor>();
29
- private readonly schemeManager: SchemeManager;
11
+ private colorMap = new Map<string, Color>();
12
+ private readonly context: Context;
30
13
 
31
- constructor({ schemeManager }: { schemeManager: SchemeManager }) {
32
- this.schemeManager = schemeManager;
14
+ constructor(args: { context: Context }) {
15
+ this.context = args.context;
33
16
  }
34
17
 
35
- createOrUpdate(
36
- key: string,
37
- args:
38
- | (Partial<ColorOptions> & { alias?: never })
39
- | { alias: string; palette?: never; tone?: never },
40
- ): ConfigurableColor {
18
+ createOrUpdate(key: string, args: ColorOptions): Color {
41
19
  let colorEntity = this.colorMap.get(key);
42
- if (!colorEntity) {
43
- const { palette, alias } = args;
44
- if (palette) {
45
- colorEntity = new ConfigurableColor(
46
- { ...args, palette: palette, name: key },
47
- this.schemeManager,
48
- this,
49
- );
50
- this.colorMap.set(key, colorEntity);
51
- } else if (alias) {
52
- colorEntity = new ConfigurableColor(
53
- { ...args, alias: alias, name: key },
54
- this.schemeManager,
55
- this,
56
- );
57
- this.colorMap.set(key, colorEntity);
58
- } else {
59
- throw new Error(`Palette ${palette} does not exist from ${key}`);
60
- }
20
+ if ('alias' in args) {
21
+ colorEntity = new ColorAlias(key, args.alias, this);
22
+ } else if ('hex' in args) {
23
+ colorEntity = new ColorFromHex(key, args.hex);
61
24
  } else {
62
- colorEntity.update({ ...args, name: key });
63
- this.colorMap.set(key, colorEntity);
25
+ try {
26
+ if (colorEntity instanceof ColorFromPalette) {
27
+ colorEntity.update(args);
28
+ } else {
29
+ colorEntity = new ColorFromPalette(key, args, this.context);
30
+ }
31
+ } catch (e) {
32
+ console.error(e);
33
+ throw new Error(`Invalid color options provided for ${key}`);
34
+ }
64
35
  }
36
+ this.colorMap.set(key, colorEntity);
65
37
  return colorEntity;
66
38
  }
67
39
 
@@ -69,7 +41,11 @@ export class ColorManager {
69
41
  return this.colorMap.delete(key);
70
42
  }
71
43
 
72
- public get(key: string): ConfigurableColor {
44
+ public clear() {
45
+ this.colorMap.clear();
46
+ }
47
+
48
+ public get(key: string): Color {
73
49
  const colorEntity = this.colorMap.get(key);
74
50
  if (colorEntity) {
75
51
  return colorEntity;
@@ -78,138 +54,7 @@ export class ColorManager {
78
54
  }
79
55
  }
80
56
 
81
- public getAll(): ReadonlyMap<string, ConfigurableColor> {
57
+ public getAll(): ReadonlyMap<string, Color> {
82
58
  return this.colorMap;
83
59
  }
84
-
85
- addFromPalette(key: string): void {
86
- const colorKey = key as DynamicColorKey;
87
- const colorDimKey = (colorKey + 'Dim') as DynamicColorKey;
88
- const ColorKey = capitalizeFirstLetter(key);
89
- const onColorKey = ('on' + ColorKey) as DynamicColorKey;
90
- const colorContainerKey = (colorKey + 'Container') as DynamicColorKey;
91
- const onColorContainerKey = ('on' +
92
- ColorKey +
93
- 'Container') as DynamicColorKey;
94
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
95
- // @ts-expect-error
96
- const inverseColorKey = ('inverse' + ColorKey) as DynamicColorKey;
97
- const colorFixedKey = (colorKey + 'Fixed') as DynamicColorKey;
98
- const colorFixedDimKey = (colorKey + 'FixedDim') as DynamicColorKey;
99
- const onColorFixedKey = ('on' + ColorKey + 'Fixed') as DynamicColorKey;
100
- const onColorFixedVariantKey = ('on' +
101
- ColorKey +
102
- 'FixedVariant') as DynamicColorKey;
103
-
104
- this.createOrUpdate(colorKey, {
105
- palette: (s) => s.getPalette(colorKey),
106
- tone: (s) => {
107
- if (s.variant === 'neutral') {
108
- return s.isDark
109
- ? tMinC(s.getPalette(colorKey), 0, 98)
110
- : tMaxC(s.getPalette(colorKey));
111
- } else if (s.variant === 'vibrant') {
112
- return tMaxC(s.getPalette(colorKey), 0, s.isDark ? 90 : 98);
113
- } else {
114
- return s.isDark ? 80 : tMaxC(s.getPalette(colorKey));
115
- }
116
- },
117
- isBackground: true,
118
- background: (s) => highestSurface(s, this),
119
- contrastCurve: (s) => getCurve(4.5),
120
- adjustTone: (s) =>
121
- toneDeltaPair(
122
- this.get(colorContainerKey).getMaterialColor(),
123
- this.get(colorKey).getMaterialColor(),
124
- 5,
125
- 'relative_lighter',
126
- true,
127
- 'farther',
128
- ),
129
- });
130
- this.createOrUpdate(colorDimKey, {
131
- palette: (s) => s.getPalette(colorKey),
132
- tone: (s) => {
133
- if (s.variant === 'neutral') {
134
- return 85;
135
- } else {
136
- return tMaxC(s.getPalette(colorKey), 0, 90);
137
- }
138
- },
139
- isBackground: true,
140
- background: (s) => this.get('surfaceContainerHigh').getMaterialColor(),
141
- contrastCurve: (s) => getCurve(4.5),
142
- adjustTone: (s) =>
143
- toneDeltaPair(
144
- this.get(colorDimKey).getMaterialColor(),
145
- this.get(colorKey).getMaterialColor(),
146
- 5,
147
- 'darker',
148
- true,
149
- 'farther',
150
- ),
151
- });
152
- this.createOrUpdate(onColorKey, {
153
- palette: (s) => s.getPalette(colorKey),
154
- background: (s) => this.get(colorKey).getMaterialColor(),
155
- contrastCurve: (s) => getCurve(6),
156
- });
157
- this.createOrUpdate(colorContainerKey, {
158
- palette: (s) => s.getPalette(colorKey),
159
- tone: (s) => {
160
- if (s.variant === 'vibrant') {
161
- return s.isDark
162
- ? tMinC(s.getPalette(colorKey), 30, 40)
163
- : tMaxC(s.getPalette(colorKey), 84, 90);
164
- } else if (s.variant === 'expressive') {
165
- return s.isDark ? 15 : tMaxC(s.getPalette(colorKey), 90, 95);
166
- } else {
167
- return s.isDark ? 25 : 90;
168
- }
169
- },
170
- isBackground: true,
171
- background: (s) => highestSurface(s, this),
172
- adjustTone: (s) => undefined,
173
- contrastCurve: (s) => (s.contrastLevel > 0 ? getCurve(1.5) : undefined),
174
- });
175
- this.createOrUpdate(onColorContainerKey, {
176
- palette: (s) => s.getPalette(colorKey),
177
- background: (s) => this.get(colorContainerKey).getMaterialColor(),
178
- contrastCurve: (s) => getCurve(6),
179
- });
180
- this.createOrUpdate(colorFixedKey, {
181
- palette: (s) => s.getPalette(colorKey),
182
- tone: (s) => {
183
- const tempS = Object.assign({}, s, { isDark: false, contrastLevel: 0 });
184
- return this.get(colorContainerKey).getMaterialColor().getTone(tempS);
185
- },
186
- isBackground: true,
187
- background: (s) => highestSurface(s, this),
188
- contrastCurve: (s) => (s.contrastLevel > 0 ? getCurve(1.5) : undefined),
189
- });
190
- this.createOrUpdate(colorFixedDimKey, {
191
- palette: (s) => s.getPalette(colorKey),
192
- tone: (s) => this.get(colorFixedKey).getMaterialColor().getTone(s),
193
- isBackground: true,
194
- adjustTone: (s) =>
195
- toneDeltaPair(
196
- this.get(colorFixedDimKey).getMaterialColor(),
197
- this.get(colorFixedKey).getMaterialColor(),
198
- 5,
199
- 'darker',
200
- true,
201
- 'exact',
202
- ),
203
- });
204
- this.createOrUpdate(onColorFixedKey, {
205
- palette: (s) => s.getPalette(colorKey),
206
- background: (s) => this.get(colorFixedDimKey).getMaterialColor(),
207
- contrastCurve: (s) => getCurve(7),
208
- });
209
- this.createOrUpdate(onColorFixedVariantKey, {
210
- palette: (s) => s.getPalette(colorKey),
211
- background: (s) => this.get(colorFixedDimKey).getMaterialColor(),
212
- contrastCurve: (s) => getCurve(4.5),
213
- });
214
- }
215
60
  }