@udixio/theme 1.3.1 → 2.0.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 +8 -3
- package/dist/API.d.ts +7 -4
- package/dist/API.d.ts.map +1 -1
- package/dist/app.container.d.ts +1 -2
- package/dist/app.container.d.ts.map +1 -1
- package/dist/bin.cjs +1 -1
- package/dist/bin.js +1 -1
- package/dist/browser.cjs +22 -18
- package/dist/browser.js +32 -28
- package/dist/color/color.api.d.ts +11 -30
- package/dist/color/color.api.d.ts.map +1 -1
- package/dist/color/color.d.ts +99 -0
- package/dist/color/color.d.ts.map +1 -0
- package/dist/color/color.manager.d.ts +9 -17
- package/dist/color/color.manager.d.ts.map +1 -1
- package/dist/color/color.utils.d.ts +14 -3
- package/dist/color/color.utils.d.ts.map +1 -1
- package/dist/color/default-color.d.ts.map +1 -1
- package/dist/color/index.d.ts +1 -1
- package/dist/color/index.d.ts.map +1 -1
- package/dist/config/config.interface.d.ts +4 -4
- package/dist/config/config.interface.d.ts.map +1 -1
- package/dist/context/context.d.ts +41 -0
- package/dist/context/context.d.ts.map +1 -0
- package/dist/context/context.module.d.ts +3 -0
- package/dist/context/context.module.d.ts.map +1 -0
- package/dist/context/index.d.ts +3 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/font.plugin-BZ-TTeTo.cjs +227 -0
- package/dist/font.plugin-DZtMajJV.js +228 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/{load-from-path-DoZnR1-p.cjs → load-from-path-DZ35yiXK.cjs} +2 -2
- package/dist/{load-from-path-Bo1kCfh9.js → load-from-path-Dobe0beV.js} +1 -1
- package/dist/loader/loader.d.ts +1 -1
- package/dist/loader/loader.d.ts.map +1 -1
- package/dist/{loader-C8_TyOuS.js → loader-BS_Esfwg.js} +1408 -908
- package/dist/{loader-R7hccp8_.cjs → loader-C8LnOoqg.cjs} +1392 -892
- package/dist/material-color-utilities/dynamic_color.d.ts +0 -22
- package/dist/material-color-utilities/dynamic_color.d.ts.map +1 -1
- package/dist/material-color-utilities/toneDeltaPair.d.ts +8 -8
- package/dist/material-color-utilities/toneDeltaPair.d.ts.map +1 -1
- package/dist/node.cjs +23 -19
- package/dist/node.js +34 -30
- package/dist/palette/index.d.ts +4 -0
- package/dist/palette/index.d.ts.map +1 -0
- package/dist/palette/palette.api.d.ts +13 -0
- package/dist/palette/palette.api.d.ts.map +1 -0
- package/dist/palette/palette.d.ts +33 -0
- package/dist/palette/palette.d.ts.map +1 -0
- package/dist/palette/palette.manager.d.ts +20 -0
- package/dist/palette/palette.manager.d.ts.map +1 -0
- package/dist/palette/palette.module.d.ts +3 -0
- package/dist/palette/palette.module.d.ts.map +1 -0
- package/dist/plugins/font/font.plugin.d.ts +1 -1
- package/dist/plugins/font/font.plugin.d.ts.map +1 -1
- package/dist/variant/index.d.ts +3 -0
- package/dist/variant/index.d.ts.map +1 -0
- package/dist/variant/variant.d.ts +29 -0
- package/dist/variant/variant.d.ts.map +1 -0
- package/dist/variant/variants/expressive.variant.d.ts +2 -0
- package/dist/variant/variants/expressive.variant.d.ts.map +1 -0
- package/dist/variant/variants/fidelity.variant.d.ts.map +1 -0
- package/dist/variant/variants/index.d.ts.map +1 -0
- package/dist/variant/variants/neutral.variant.d.ts.map +1 -0
- package/dist/variant/variants/tonal-spot.variant.d.ts.map +1 -0
- package/dist/variant/variants/vibrant.variant.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/API.ts +12 -5
- package/src/app.container.ts +22 -11
- package/src/bootstrap.ts +1 -1
- package/src/color/color.api.ts +168 -47
- package/src/color/color.manager.ts +38 -181
- package/src/color/color.ts +291 -0
- package/src/color/color.utils.ts +48 -3
- package/src/color/default-color.ts +395 -396
- package/src/color/index.ts +1 -1
- package/src/config/config.interface.ts +5 -4
- package/src/context/context.module.ts +7 -0
- package/src/context/context.ts +169 -0
- package/src/context/index.ts +2 -0
- package/src/index.ts +6 -4
- package/src/loader/loader.ts +14 -23
- package/src/material-color-utilities/dynamic_color.ts +25 -34
- package/src/material-color-utilities/toneDeltaPair.ts +44 -41
- package/src/palette/index.ts +3 -0
- package/src/palette/palette.api.ts +43 -0
- package/src/palette/palette.manager.ts +74 -0
- package/src/palette/palette.module.ts +9 -0
- package/src/palette/palette.ts +207 -0
- package/src/plugins/font/font.plugin.ts +1 -1
- package/src/variant/index.ts +2 -0
- package/src/variant/variant.ts +81 -0
- package/src/{theme → variant}/variants/expressive.variant.ts +31 -29
- package/src/variant/variants/fidelity.variant.ts +46 -0
- package/src/{theme → variant}/variants/neutral.variant.ts +18 -18
- package/src/variant/variants/tonal-spot.variant.ts +35 -0
- package/src/{theme → variant}/variants/vibrant.variant.ts +21 -22
- package/dist/color/configurable-color.d.ts +0 -31
- package/dist/color/configurable-color.d.ts.map +0 -1
- package/dist/define-config-BasMdCqD.js +0 -430
- package/dist/define-config-CKSsLMnc.cjs +0 -429
- package/dist/theme/index.d.ts +0 -8
- package/dist/theme/index.d.ts.map +0 -1
- package/dist/theme/scheme.d.ts +0 -20
- package/dist/theme/scheme.d.ts.map +0 -1
- package/dist/theme/scheme.manager.d.ts +0 -31
- package/dist/theme/scheme.manager.d.ts.map +0 -1
- package/dist/theme/theme.api.d.ts +0 -24
- package/dist/theme/theme.api.d.ts.map +0 -1
- package/dist/theme/theme.module.d.ts +0 -3
- package/dist/theme/theme.module.d.ts.map +0 -1
- package/dist/theme/variant.d.ts +0 -36
- package/dist/theme/variant.d.ts.map +0 -1
- package/dist/theme/variant.manager.d.ts +0 -14
- package/dist/theme/variant.manager.d.ts.map +0 -1
- package/dist/theme/variants/expressive.variant.d.ts +0 -3
- package/dist/theme/variants/expressive.variant.d.ts.map +0 -1
- package/dist/theme/variants/fidelity.variant.d.ts.map +0 -1
- package/dist/theme/variants/index.d.ts.map +0 -1
- package/dist/theme/variants/neutral.variant.d.ts.map +0 -1
- package/dist/theme/variants/tonal-spot.variant.d.ts.map +0 -1
- package/dist/theme/variants/vibrant.variant.d.ts.map +0 -1
- package/src/color/configurable-color.ts +0 -67
- package/src/theme/index.ts +0 -7
- package/src/theme/scheme.manager.ts +0 -100
- package/src/theme/scheme.ts +0 -66
- package/src/theme/theme.api.ts +0 -82
- package/src/theme/theme.module.ts +0 -11
- package/src/theme/variant.manager.ts +0 -58
- package/src/theme/variant.ts +0 -53
- package/src/theme/variants/fidelity.variant.ts +0 -38
- package/src/theme/variants/tonal-spot.variant.ts +0 -35
- /package/dist/{theme → variant}/variants/fidelity.variant.d.ts +0 -0
- /package/dist/{theme → variant}/variants/index.d.ts +0 -0
- /package/dist/{theme → variant}/variants/neutral.variant.d.ts +0 -0
- /package/dist/{theme → variant}/variants/tonal-spot.variant.d.ts +0 -0
- /package/dist/{theme → variant}/variants/vibrant.variant.d.ts +0 -0
- /package/src/{theme → variant}/variants/index.ts +0 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { Context } from '../context';
|
|
2
|
+
import { Hct } from '../material-color-utilities/htc';
|
|
3
|
+
|
|
4
|
+
export type PaletteCallback = (context: Context) => {
|
|
5
|
+
hue: number;
|
|
6
|
+
chroma: number;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export class Palette {
|
|
10
|
+
private readonly cache = new Map<number, number>();
|
|
11
|
+
private hueCache: number | null = null;
|
|
12
|
+
private chromaCache: number | null = null;
|
|
13
|
+
|
|
14
|
+
private dependencies: (keyof Context)[] | null = null;
|
|
15
|
+
|
|
16
|
+
constructor(
|
|
17
|
+
public name: string,
|
|
18
|
+
public callback: PaletteCallback,
|
|
19
|
+
public context: Context,
|
|
20
|
+
) {
|
|
21
|
+
this.update([]);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static fromVariant(name: string, color: Hct, ctx: Context): Palette {
|
|
25
|
+
const callback: PaletteCallback = (context) => {
|
|
26
|
+
return context.variant.customPalettes(context, color);
|
|
27
|
+
};
|
|
28
|
+
return new Palette(name, callback, ctx);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
update(change: Partial<keyof Context>[]): void {
|
|
32
|
+
let result: {
|
|
33
|
+
hue: number;
|
|
34
|
+
chroma: number;
|
|
35
|
+
} | null = null;
|
|
36
|
+
|
|
37
|
+
if (this.dependencies == null) {
|
|
38
|
+
const trackDependencies = Context.trackDependencies(this.context, (ctx) =>
|
|
39
|
+
this.callback(ctx),
|
|
40
|
+
);
|
|
41
|
+
this.dependencies = trackDependencies.dependencies;
|
|
42
|
+
result = trackDependencies.result;
|
|
43
|
+
} else if (
|
|
44
|
+
change.length > 0 &&
|
|
45
|
+
change.some((c) => this.dependencies?.includes(c))
|
|
46
|
+
) {
|
|
47
|
+
result = this.callback(this.context);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (
|
|
51
|
+
result &&
|
|
52
|
+
this.hueCache !== result.hue &&
|
|
53
|
+
this.chromaCache !== result.chroma
|
|
54
|
+
) {
|
|
55
|
+
this.clearCache();
|
|
56
|
+
this.hueCache = result.hue;
|
|
57
|
+
this.chromaCache = result.chroma;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private clearCache() {
|
|
62
|
+
this.cache.clear();
|
|
63
|
+
this.hueCache = null;
|
|
64
|
+
this.chromaCache = null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @param tone HCT tone, measured from 0 to 100.
|
|
69
|
+
* @return ARGB representation of a color with that tone.
|
|
70
|
+
*/
|
|
71
|
+
tone(tone: number): number {
|
|
72
|
+
const hue = this.hueCache;
|
|
73
|
+
const chroma = this.chromaCache;
|
|
74
|
+
|
|
75
|
+
if (hue == null || chroma == null)
|
|
76
|
+
throw new Error('Palette must be updated before using tone');
|
|
77
|
+
|
|
78
|
+
let argb = this.cache.get(tone);
|
|
79
|
+
if (argb === undefined) {
|
|
80
|
+
if (tone == 99 && Hct.isYellow(hue)) {
|
|
81
|
+
argb = this.averageArgb(this.tone(98), this.tone(100));
|
|
82
|
+
} else {
|
|
83
|
+
argb = Hct.from(hue, chroma, tone).toInt();
|
|
84
|
+
}
|
|
85
|
+
this.cache.set(tone, argb);
|
|
86
|
+
}
|
|
87
|
+
return argb;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @param tone HCT tone.
|
|
92
|
+
* @return HCT representation of a color with that tone.
|
|
93
|
+
*/
|
|
94
|
+
getHct(tone: number): Hct {
|
|
95
|
+
return Hct.fromInt(this.tone(tone));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
get hue(): number {
|
|
99
|
+
const hue = this.hueCache;
|
|
100
|
+
if (hue == null) {
|
|
101
|
+
throw new Error(`Palette ${this.name} must be updated before using hue`);
|
|
102
|
+
}
|
|
103
|
+
return hue;
|
|
104
|
+
}
|
|
105
|
+
get chroma(): number {
|
|
106
|
+
const chroma = this.chromaCache;
|
|
107
|
+
if (chroma == null) {
|
|
108
|
+
throw new Error(`Palette ${this.name} must be updated before using hue`);
|
|
109
|
+
}
|
|
110
|
+
return chroma;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
private averageArgb(argb1: number, argb2: number): number {
|
|
114
|
+
const red1 = (argb1 >>> 16) & 0xff;
|
|
115
|
+
const green1 = (argb1 >>> 8) & 0xff;
|
|
116
|
+
const blue1 = argb1 & 0xff;
|
|
117
|
+
const red2 = (argb2 >>> 16) & 0xff;
|
|
118
|
+
const green2 = (argb2 >>> 8) & 0xff;
|
|
119
|
+
const blue2 = argb2 & 0xff;
|
|
120
|
+
const red = Math.round((red1 + red2) / 2);
|
|
121
|
+
const green = Math.round((green1 + green2) / 2);
|
|
122
|
+
const blue = Math.round((blue1 + blue2) / 2);
|
|
123
|
+
return (
|
|
124
|
+
((255 << 24) |
|
|
125
|
+
((red & 255) << 16) |
|
|
126
|
+
((green & 255) << 8) |
|
|
127
|
+
(blue & 255)) >>>
|
|
128
|
+
0
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// /**
|
|
134
|
+
// * Key color is a color that represents the hue and chroma of a tonal palette
|
|
135
|
+
// */
|
|
136
|
+
// class KeyColor {
|
|
137
|
+
// // Cache that maps tone to max chroma to avoid duplicated HCT calculation.
|
|
138
|
+
// private readonly chromaCache = new Map<number, number>();
|
|
139
|
+
// private readonly maxChromaValue = 200.0;
|
|
140
|
+
//
|
|
141
|
+
// constructor(
|
|
142
|
+
// readonly hue: number,
|
|
143
|
+
// readonly requestedChroma: number,
|
|
144
|
+
// ) {}
|
|
145
|
+
//
|
|
146
|
+
// /**
|
|
147
|
+
// * Creates a key color from a [hue] and a [chroma].
|
|
148
|
+
// * The key color is the first tone, starting from T50, matching the given hue
|
|
149
|
+
// * and chroma.
|
|
150
|
+
// *
|
|
151
|
+
// * @return Key color [Hct]
|
|
152
|
+
// */
|
|
153
|
+
// create(): Hct {
|
|
154
|
+
// // Pivot around T50 because T50 has the most chroma available, on
|
|
155
|
+
// // average. Thus it is most likely to have a direct answer.
|
|
156
|
+
// const pivotTone = 50;
|
|
157
|
+
// const toneStepSize = 1;
|
|
158
|
+
// // Epsilon to accept values slightly higher than the requested chroma.
|
|
159
|
+
// const epsilon = 0.01;
|
|
160
|
+
//
|
|
161
|
+
// // Binary search to find the tone that can provide a chroma that is closest
|
|
162
|
+
// // to the requested chroma.
|
|
163
|
+
// let lowerTone = 0;
|
|
164
|
+
// let upperTone = 100;
|
|
165
|
+
// while (lowerTone < upperTone) {
|
|
166
|
+
// const midTone = Math.floor((lowerTone + upperTone) / 2);
|
|
167
|
+
// const isAscending =
|
|
168
|
+
// this.maxChroma(midTone) < this.maxChroma(midTone + toneStepSize);
|
|
169
|
+
// const sufficientChroma =
|
|
170
|
+
// this.maxChroma(midTone) >= this.requestedChroma - epsilon;
|
|
171
|
+
//
|
|
172
|
+
// if (sufficientChroma) {
|
|
173
|
+
// // Either range [lowerTone, midTone] or [midTone, upperTone] has
|
|
174
|
+
// // the answer, so search in the range that is closer the pivot tone.
|
|
175
|
+
// if (Math.abs(lowerTone - pivotTone) < Math.abs(upperTone - pivotTone)) {
|
|
176
|
+
// upperTone = midTone;
|
|
177
|
+
// } else {
|
|
178
|
+
// if (lowerTone === midTone) {
|
|
179
|
+
// return Hct.from(this.hue, this.requestedChroma, lowerTone);
|
|
180
|
+
// }
|
|
181
|
+
// lowerTone = midTone;
|
|
182
|
+
// }
|
|
183
|
+
// } else {
|
|
184
|
+
// // As there is no sufficient chroma in the midTone, follow the direction
|
|
185
|
+
// // to the chroma peak.
|
|
186
|
+
// if (isAscending) {
|
|
187
|
+
// lowerTone = midTone + toneStepSize;
|
|
188
|
+
// } else {
|
|
189
|
+
// // Keep midTone for potential chroma peak.
|
|
190
|
+
// upperTone = midTone;
|
|
191
|
+
// }
|
|
192
|
+
// }
|
|
193
|
+
// }
|
|
194
|
+
//
|
|
195
|
+
// return Hct.from(this.hue, this.requestedChroma, lowerTone);
|
|
196
|
+
// }
|
|
197
|
+
//
|
|
198
|
+
// // Find the maximum chroma for a given tone
|
|
199
|
+
// private maxChroma(tone: number): number {
|
|
200
|
+
// if (this.chromaCache.has(tone)) {
|
|
201
|
+
// return this.chromaCache.get(tone)!;
|
|
202
|
+
// }
|
|
203
|
+
// const chroma = Hct.from(this.hue, this.maxChromaValue, tone).chroma;
|
|
204
|
+
// this.chromaCache.set(tone, chroma);
|
|
205
|
+
// return chroma;
|
|
206
|
+
// }
|
|
207
|
+
// }
|
|
@@ -13,7 +13,7 @@ export type FontStyle = {
|
|
|
13
13
|
};
|
|
14
14
|
export type FontRole = 'display' | 'headline' | 'title' | 'label' | 'body';
|
|
15
15
|
export type FontSize = 'large' | 'medium' | 'small';
|
|
16
|
-
interface FontPluginOptions {
|
|
16
|
+
export interface FontPluginOptions {
|
|
17
17
|
fontFamily?: {
|
|
18
18
|
expressive?: string[];
|
|
19
19
|
neutral?: string[];
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { sanitizeDegreesDouble } from '@material/material-color-utilities';
|
|
2
|
+
import { Hct } from '../material-color-utilities/htc';
|
|
3
|
+
import { Palette } from '../palette/palette';
|
|
4
|
+
import { AddColorsOptions } from '../color';
|
|
5
|
+
import { Context } from '../context';
|
|
6
|
+
import { AddPaletteOptions } from '../palette/palette.api';
|
|
7
|
+
|
|
8
|
+
export const getPiecewiseHue = (
|
|
9
|
+
sourceColor: Hct,
|
|
10
|
+
hueBreakpoints: number[],
|
|
11
|
+
hues: number[],
|
|
12
|
+
): number => {
|
|
13
|
+
const size = Math.min(hueBreakpoints.length - 1, hues.length);
|
|
14
|
+
const sourceHue = sourceColor.hue;
|
|
15
|
+
for (let i = 0; i < size; i++) {
|
|
16
|
+
if (sourceHue >= hueBreakpoints[i] && sourceHue < hueBreakpoints[i + 1]) {
|
|
17
|
+
return sanitizeDegreesDouble(hues[i]);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return sourceHue;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const getRotatedHue = (
|
|
24
|
+
sourceColor: Hct,
|
|
25
|
+
hueBreakpoints: number[],
|
|
26
|
+
rotations: number[],
|
|
27
|
+
): number => {
|
|
28
|
+
let rotation = getPiecewiseHue(sourceColor, hueBreakpoints, rotations);
|
|
29
|
+
if (Math.min(hueBreakpoints.length - 1, rotations.length) <= 0) {
|
|
30
|
+
rotation = 0;
|
|
31
|
+
}
|
|
32
|
+
return sanitizeDegreesDouble(sourceColor.hue + rotation);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export interface VariantOptions {
|
|
36
|
+
name: string;
|
|
37
|
+
palettes: AddPaletteOptions;
|
|
38
|
+
customPalettes: (
|
|
39
|
+
args: Context,
|
|
40
|
+
color: Hct,
|
|
41
|
+
) => {
|
|
42
|
+
hue: number;
|
|
43
|
+
chroma: number;
|
|
44
|
+
};
|
|
45
|
+
colors?: AddColorsOptions;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export class Variant {
|
|
49
|
+
public _palettes?: Record<string, Palette>;
|
|
50
|
+
public readonly customPalettes: VariantOptions['customPalettes'];
|
|
51
|
+
public readonly colors: AddColorsOptions;
|
|
52
|
+
public readonly name: string;
|
|
53
|
+
private context?: Context;
|
|
54
|
+
|
|
55
|
+
constructor(private options: VariantOptions) {
|
|
56
|
+
this.customPalettes = options.customPalettes;
|
|
57
|
+
this.colors = options.colors || {};
|
|
58
|
+
this.name = options.name;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
get palettes() {
|
|
62
|
+
if (!this._palettes) {
|
|
63
|
+
throw new Error('Variant not initialized');
|
|
64
|
+
}
|
|
65
|
+
return this._palettes;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
init(context: Context) {
|
|
69
|
+
if (this.context) return;
|
|
70
|
+
this.context = context;
|
|
71
|
+
this._palettes = Object.entries(this.options.palettes).reduce(
|
|
72
|
+
(acc, [key, callback]) => ({
|
|
73
|
+
...acc,
|
|
74
|
+
[key]: new Palette(key, callback, context),
|
|
75
|
+
}),
|
|
76
|
+
{},
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const variant = (args: VariantOptions) => new Variant(args);
|
|
@@ -1,55 +1,57 @@
|
|
|
1
|
-
import { getPiecewiseHue, getRotatedHue,
|
|
1
|
+
import { getPiecewiseHue, getRotatedHue, variant } from '../variant';
|
|
2
2
|
import { TonalPalette } from '@material/material-color-utilities';
|
|
3
3
|
import { Hct } from '../../material-color-utilities/htc';
|
|
4
4
|
|
|
5
|
-
const getExpressiveNeutralHue = (
|
|
5
|
+
const getExpressiveNeutralHue = (sourceColor: Hct): number => {
|
|
6
6
|
const hue = getRotatedHue(
|
|
7
|
-
|
|
7
|
+
sourceColor,
|
|
8
8
|
[0, 71, 124, 253, 278, 300, 360],
|
|
9
9
|
[10, 0, 10, 0, 10, 0],
|
|
10
10
|
);
|
|
11
11
|
return hue;
|
|
12
12
|
};
|
|
13
13
|
const getExpressiveNeutralChroma = (
|
|
14
|
-
|
|
14
|
+
sourceColor: Hct,
|
|
15
15
|
isDark: boolean,
|
|
16
16
|
): number => {
|
|
17
|
-
const neutralHue = getExpressiveNeutralHue(
|
|
17
|
+
const neutralHue = getExpressiveNeutralHue(sourceColor);
|
|
18
18
|
return isDark ? (Hct.isYellow(neutralHue) ? 6 : 14) : 18;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
export const expressiveVariant
|
|
21
|
+
export const expressiveVariant = variant({
|
|
22
22
|
name: 'expressive',
|
|
23
23
|
palettes: {
|
|
24
|
-
primary: ({
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
isDark ? 16 : 24,
|
|
24
|
+
primary: ({ sourceColor, isDark }) => ({
|
|
25
|
+
hue: sourceColor.hue,
|
|
26
|
+
chroma: isDark ? 36 : 48,
|
|
27
|
+
}),
|
|
28
|
+
secondary: ({ sourceColor, isDark }) => ({
|
|
29
|
+
hue: getRotatedHue(
|
|
30
|
+
sourceColor,
|
|
31
|
+
[0, 105, 140, 204, 253, 278, 300, 333, 360],
|
|
32
|
+
[-160, 155, -100, 96, -96, -156, -165, -160],
|
|
34
33
|
),
|
|
35
|
-
|
|
34
|
+
|
|
35
|
+
chroma: isDark ? 16 : 24,
|
|
36
|
+
}),
|
|
37
|
+
tertiary: ({ sourceColor }) =>
|
|
36
38
|
TonalPalette.fromHueAndChroma(
|
|
37
39
|
getRotatedHue(
|
|
38
|
-
|
|
40
|
+
sourceColor,
|
|
39
41
|
[0, 105, 140, 204, 253, 278, 300, 333, 360],
|
|
40
42
|
[-165, 160, -105, 101, -101, -160, -170, -165],
|
|
41
43
|
),
|
|
42
44
|
48,
|
|
43
45
|
),
|
|
44
|
-
neutral: ({
|
|
46
|
+
neutral: ({ sourceColor, isDark }) =>
|
|
45
47
|
TonalPalette.fromHueAndChroma(
|
|
46
|
-
getExpressiveNeutralHue(
|
|
47
|
-
getExpressiveNeutralChroma(
|
|
48
|
+
getExpressiveNeutralHue(sourceColor),
|
|
49
|
+
getExpressiveNeutralChroma(sourceColor, isDark),
|
|
48
50
|
),
|
|
49
|
-
neutralVariant: ({
|
|
50
|
-
const expressiveNeutralHue = getExpressiveNeutralHue(
|
|
51
|
+
neutralVariant: ({ sourceColor, isDark }) => {
|
|
52
|
+
const expressiveNeutralHue = getExpressiveNeutralHue(sourceColor);
|
|
51
53
|
const expressiveNeutralChroma = getExpressiveNeutralChroma(
|
|
52
|
-
|
|
54
|
+
sourceColor,
|
|
53
55
|
isDark,
|
|
54
56
|
);
|
|
55
57
|
return TonalPalette.fromHueAndChroma(
|
|
@@ -60,22 +62,22 @@ export const expressiveVariant: Variant = {
|
|
|
60
62
|
: 2.3),
|
|
61
63
|
);
|
|
62
64
|
},
|
|
63
|
-
error: ({
|
|
65
|
+
error: ({ sourceColor }) => {
|
|
64
66
|
const errorHue = getPiecewiseHue(
|
|
65
|
-
|
|
67
|
+
sourceColor,
|
|
66
68
|
[0, 3, 13, 23, 33, 43, 153, 273, 360],
|
|
67
69
|
[12, 22, 32, 12, 22, 32, 22, 12],
|
|
68
70
|
);
|
|
69
71
|
return TonalPalette.fromHueAndChroma(errorHue, 64);
|
|
70
72
|
},
|
|
71
73
|
},
|
|
72
|
-
customPalettes: ({
|
|
74
|
+
customPalettes: ({ isDark }, color) =>
|
|
73
75
|
TonalPalette.fromHueAndChroma(
|
|
74
76
|
getRotatedHue(
|
|
75
|
-
|
|
77
|
+
color,
|
|
76
78
|
[0, 105, 140, 204, 253, 278, 300, 333, 360],
|
|
77
79
|
[-160, 155, -100, 96, -96, -156, -165, -160],
|
|
78
80
|
),
|
|
79
81
|
isDark ? 16 : 24,
|
|
80
82
|
),
|
|
81
|
-
};
|
|
83
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { getPiecewiseHue, getRotatedHue, variant, Variant } from '../variant';
|
|
2
|
+
|
|
3
|
+
export const fidelityVariant: Variant = variant({
|
|
4
|
+
name: 'fidelity',
|
|
5
|
+
palettes: {
|
|
6
|
+
primary: ({ sourceColor }) => ({
|
|
7
|
+
hue: sourceColor.hue,
|
|
8
|
+
chroma: sourceColor.chroma,
|
|
9
|
+
}),
|
|
10
|
+
secondary: ({ sourceColor }) => ({
|
|
11
|
+
hue: sourceColor.hue,
|
|
12
|
+
chroma: sourceColor.chroma / 1.4,
|
|
13
|
+
}),
|
|
14
|
+
tertiary: ({ sourceColor }) => ({
|
|
15
|
+
hue: getRotatedHue(
|
|
16
|
+
sourceColor,
|
|
17
|
+
[0, 20, 71, 161, 333, 360],
|
|
18
|
+
[-40, 48, -32, 40, -32],
|
|
19
|
+
),
|
|
20
|
+
chroma: sourceColor.chroma,
|
|
21
|
+
}),
|
|
22
|
+
neutral: ({ sourceColor }) => ({
|
|
23
|
+
hue: sourceColor.hue,
|
|
24
|
+
chroma: 5,
|
|
25
|
+
}),
|
|
26
|
+
neutralVariant: ({ sourceColor }) => ({
|
|
27
|
+
hue: sourceColor.hue,
|
|
28
|
+
chroma: 5 * 1.7,
|
|
29
|
+
}),
|
|
30
|
+
error: ({ sourceColor }) => {
|
|
31
|
+
const errorHue = getPiecewiseHue(
|
|
32
|
+
sourceColor,
|
|
33
|
+
[0, 3, 13, 23, 33, 43, 153, 273, 360],
|
|
34
|
+
[12, 22, 32, 12, 22, 32, 22, 12],
|
|
35
|
+
);
|
|
36
|
+
return {
|
|
37
|
+
hue: errorHue,
|
|
38
|
+
chroma: 60,
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
customPalettes: ({ sourceColor }, colorHct) => ({
|
|
43
|
+
hue: colorHct.hue,
|
|
44
|
+
chroma: sourceColor.chroma,
|
|
45
|
+
}),
|
|
46
|
+
});
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { getPiecewiseHue, getRotatedHue, Variant } from '../variant';
|
|
1
|
+
import { getPiecewiseHue, getRotatedHue, variant, Variant } from '../variant';
|
|
2
2
|
import { TonalPalette } from '@material/material-color-utilities';
|
|
3
3
|
import { Hct } from '../../material-color-utilities/htc';
|
|
4
4
|
|
|
5
|
-
export const neutralVariant: Variant = {
|
|
5
|
+
export const neutralVariant: Variant = variant({
|
|
6
6
|
name: 'neutral',
|
|
7
7
|
palettes: {
|
|
8
|
-
primary: ({
|
|
8
|
+
primary: ({ sourceColor }) =>
|
|
9
9
|
TonalPalette.fromHueAndChroma(
|
|
10
|
-
|
|
11
|
-
Hct.isBlue(
|
|
10
|
+
sourceColor.hue,
|
|
11
|
+
Hct.isBlue(sourceColor.hue) ? 12 : 8,
|
|
12
12
|
),
|
|
13
|
-
secondary: ({
|
|
13
|
+
secondary: ({ sourceColor }) =>
|
|
14
14
|
TonalPalette.fromHueAndChroma(
|
|
15
|
-
|
|
16
|
-
Hct.isBlue(
|
|
15
|
+
sourceColor.hue,
|
|
16
|
+
Hct.isBlue(sourceColor.hue) ? 6 : 4,
|
|
17
17
|
),
|
|
18
|
-
tertiary: ({
|
|
18
|
+
tertiary: ({ sourceColor }) =>
|
|
19
19
|
TonalPalette.fromHueAndChroma(
|
|
20
20
|
getRotatedHue(
|
|
21
|
-
|
|
21
|
+
sourceColor,
|
|
22
22
|
[0, 38, 105, 161, 204, 278, 333, 360],
|
|
23
23
|
[-32, 26, 10, -39, 24, -15, -32],
|
|
24
24
|
),
|
|
25
25
|
20,
|
|
26
26
|
),
|
|
27
|
-
neutral: ({
|
|
28
|
-
TonalPalette.fromHueAndChroma(
|
|
29
|
-
neutralVariant: ({
|
|
30
|
-
TonalPalette.fromHueAndChroma(
|
|
31
|
-
error: ({
|
|
27
|
+
neutral: ({ sourceColor }) =>
|
|
28
|
+
TonalPalette.fromHueAndChroma(sourceColor.hue, 1.4),
|
|
29
|
+
neutralVariant: ({ sourceColor }) =>
|
|
30
|
+
TonalPalette.fromHueAndChroma(sourceColor.hue, 1.4 * 2.2),
|
|
31
|
+
error: ({ sourceColor }) => {
|
|
32
32
|
const errorHue = getPiecewiseHue(
|
|
33
|
-
|
|
33
|
+
sourceColor,
|
|
34
34
|
[0, 3, 13, 23, 33, 43, 153, 273, 360],
|
|
35
35
|
[12, 22, 32, 12, 22, 32, 22, 12],
|
|
36
36
|
);
|
|
37
37
|
return TonalPalette.fromHueAndChroma(errorHue, 50);
|
|
38
38
|
},
|
|
39
39
|
},
|
|
40
|
-
customPalettes: (
|
|
40
|
+
customPalettes: (_, colorHct) =>
|
|
41
41
|
TonalPalette.fromHueAndChroma(
|
|
42
42
|
colorHct.hue,
|
|
43
43
|
Hct.isBlue(colorHct.hue) ? 6 : 4,
|
|
44
44
|
),
|
|
45
|
-
};
|
|
45
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { getPiecewiseHue, getRotatedHue, variant, Variant } from '../variant';
|
|
2
|
+
import { TonalPalette } from '@material/material-color-utilities';
|
|
3
|
+
|
|
4
|
+
export const tonalSpotVariant: Variant = variant({
|
|
5
|
+
name: 'tonalSpot',
|
|
6
|
+
palettes: {
|
|
7
|
+
primary: ({ sourceColor, isDark }) =>
|
|
8
|
+
TonalPalette.fromHueAndChroma(sourceColor.hue, isDark ? 26 : 32),
|
|
9
|
+
secondary: ({ sourceColor }) =>
|
|
10
|
+
TonalPalette.fromHueAndChroma(sourceColor.hue, 16),
|
|
11
|
+
tertiary: ({ sourceColor }) =>
|
|
12
|
+
TonalPalette.fromHueAndChroma(
|
|
13
|
+
getRotatedHue(
|
|
14
|
+
sourceColor,
|
|
15
|
+
[0, 20, 71, 161, 333, 360],
|
|
16
|
+
[-40, 48, -32, 40, -32],
|
|
17
|
+
),
|
|
18
|
+
28,
|
|
19
|
+
),
|
|
20
|
+
neutral: ({ sourceColor }) =>
|
|
21
|
+
TonalPalette.fromHueAndChroma(sourceColor.hue, 5),
|
|
22
|
+
neutralVariant: ({ sourceColor }) =>
|
|
23
|
+
TonalPalette.fromHueAndChroma(sourceColor.hue, 5 * 1.7),
|
|
24
|
+
error: ({ sourceColor }) => {
|
|
25
|
+
const errorHue = getPiecewiseHue(
|
|
26
|
+
sourceColor,
|
|
27
|
+
[0, 3, 13, 23, 33, 43, 153, 273, 360],
|
|
28
|
+
[12, 22, 32, 12, 22, 32, 22, 12],
|
|
29
|
+
);
|
|
30
|
+
return TonalPalette.fromHueAndChroma(errorHue, 60);
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
customPalettes: (_, colorHct) =>
|
|
34
|
+
TonalPalette.fromHueAndChroma(colorHct.hue, 16),
|
|
35
|
+
});
|
|
@@ -1,66 +1,65 @@
|
|
|
1
|
-
import { getPiecewiseHue, getRotatedHue, Variant } from '../variant';
|
|
1
|
+
import { getPiecewiseHue, getRotatedHue, variant, Variant } from '../variant';
|
|
2
2
|
import { TonalPalette } from '@material/material-color-utilities';
|
|
3
3
|
import { Hct } from '../../material-color-utilities/htc';
|
|
4
4
|
|
|
5
|
-
const getVibrantNeutralHue = (
|
|
5
|
+
const getVibrantNeutralHue = (sourceColor: Hct): number => {
|
|
6
6
|
return getRotatedHue(
|
|
7
|
-
|
|
7
|
+
sourceColor,
|
|
8
8
|
[0, 38, 105, 140, 333, 360],
|
|
9
9
|
[-14, 10, -14, 10, -14],
|
|
10
10
|
);
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
const getVibrantNeutralChroma = (
|
|
14
|
-
const neutralHue = getVibrantNeutralHue(sourceColorHct);
|
|
13
|
+
const getVibrantNeutralChroma = (sourceColor: Hct): number => {
|
|
15
14
|
return 28;
|
|
16
15
|
};
|
|
17
16
|
|
|
18
|
-
export const vibrantVariant: Variant = {
|
|
17
|
+
export const vibrantVariant: Variant = variant({
|
|
19
18
|
name: 'vibrant',
|
|
20
19
|
palettes: {
|
|
21
|
-
primary: ({
|
|
22
|
-
TonalPalette.fromHueAndChroma(
|
|
23
|
-
secondary: ({
|
|
20
|
+
primary: ({ sourceColor }) =>
|
|
21
|
+
TonalPalette.fromHueAndChroma(sourceColor.hue, 74),
|
|
22
|
+
secondary: ({ sourceColor }) =>
|
|
24
23
|
TonalPalette.fromHueAndChroma(
|
|
25
24
|
getRotatedHue(
|
|
26
|
-
|
|
25
|
+
sourceColor,
|
|
27
26
|
[0, 38, 105, 140, 333, 360],
|
|
28
27
|
[-14, 10, -14, 10, -14],
|
|
29
28
|
),
|
|
30
29
|
56,
|
|
31
30
|
),
|
|
32
|
-
tertiary: ({
|
|
31
|
+
tertiary: ({ sourceColor }) =>
|
|
33
32
|
TonalPalette.fromHueAndChroma(
|
|
34
33
|
getRotatedHue(
|
|
35
|
-
|
|
34
|
+
sourceColor,
|
|
36
35
|
[0, 38, 71, 105, 140, 161, 253, 333, 360],
|
|
37
36
|
[-72, 35, 24, -24, 62, 50, 62, -72],
|
|
38
37
|
),
|
|
39
38
|
56,
|
|
40
39
|
),
|
|
41
|
-
neutral: ({
|
|
40
|
+
neutral: ({ sourceColor }) =>
|
|
42
41
|
TonalPalette.fromHueAndChroma(
|
|
43
|
-
getVibrantNeutralHue(
|
|
44
|
-
getVibrantNeutralChroma(
|
|
42
|
+
getVibrantNeutralHue(sourceColor),
|
|
43
|
+
getVibrantNeutralChroma(sourceColor),
|
|
45
44
|
),
|
|
46
|
-
neutralVariant: ({
|
|
47
|
-
const vibrantNeutralHue = getVibrantNeutralHue(
|
|
48
|
-
const vibrantNeutralChroma = getVibrantNeutralChroma(
|
|
45
|
+
neutralVariant: ({ sourceColor }) => {
|
|
46
|
+
const vibrantNeutralHue = getVibrantNeutralHue(sourceColor);
|
|
47
|
+
const vibrantNeutralChroma = getVibrantNeutralChroma(sourceColor);
|
|
49
48
|
return TonalPalette.fromHueAndChroma(
|
|
50
49
|
vibrantNeutralHue,
|
|
51
50
|
vibrantNeutralChroma * 1.29,
|
|
52
51
|
);
|
|
53
52
|
},
|
|
54
|
-
error: ({
|
|
53
|
+
error: ({ sourceColor }) => {
|
|
55
54
|
const errorHue = getPiecewiseHue(
|
|
56
|
-
|
|
55
|
+
sourceColor,
|
|
57
56
|
[0, 3, 13, 23, 33, 43, 153, 273, 360],
|
|
58
57
|
[12, 22, 32, 12, 22, 32, 22, 12],
|
|
59
58
|
);
|
|
60
59
|
return TonalPalette.fromHueAndChroma(errorHue, 80);
|
|
61
60
|
},
|
|
62
61
|
},
|
|
63
|
-
customPalettes: (
|
|
62
|
+
customPalettes: (_, colorHct) =>
|
|
64
63
|
TonalPalette.fromHueAndChroma(
|
|
65
64
|
getRotatedHue(
|
|
66
65
|
colorHct,
|
|
@@ -69,4 +68,4 @@ export const vibrantVariant: Variant = {
|
|
|
69
68
|
),
|
|
70
69
|
56,
|
|
71
70
|
),
|
|
72
|
-
};
|
|
71
|
+
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { SchemeManager } from '../theme';
|
|
2
|
-
import { DynamicColor, FromPaletteOptions } from '../material-color-utilities';
|
|
3
|
-
import { ColorManager } from './color.manager';
|
|
4
|
-
export type ColorOptions = ((FromPaletteOptions & {
|
|
5
|
-
alias?: string;
|
|
6
|
-
}) | (Partial<FromPaletteOptions> & {
|
|
7
|
-
alias: string;
|
|
8
|
-
palette?: never;
|
|
9
|
-
})) & {
|
|
10
|
-
name: string;
|
|
11
|
-
};
|
|
12
|
-
export declare class ConfigurableColor {
|
|
13
|
-
private option;
|
|
14
|
-
private schemeService;
|
|
15
|
-
private colorService;
|
|
16
|
-
private dynamicColor;
|
|
17
|
-
constructor(option: ColorOptions, schemeService: SchemeManager, colorService: ColorManager);
|
|
18
|
-
update(args: Partial<ColorOptions & {
|
|
19
|
-
name: string;
|
|
20
|
-
}>): void;
|
|
21
|
-
getHex(): string;
|
|
22
|
-
getArgb(): number;
|
|
23
|
-
getRgb(): {
|
|
24
|
-
r: number;
|
|
25
|
-
g: number;
|
|
26
|
-
b: number;
|
|
27
|
-
};
|
|
28
|
-
getName(): string;
|
|
29
|
-
getMaterialColor(): DynamicColor;
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=configurable-color.d.ts.map
|