@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
|
@@ -1,47 +1,27 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
class
|
|
7
|
-
constructor({
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
if (args2.fromPalettes) {
|
|
24
|
-
if (!Array.isArray(args2.fromPalettes))
|
|
25
|
-
args2.fromPalettes = [args2.fromPalettes];
|
|
26
|
-
args2.fromPalettes.map((paletteKey) => {
|
|
27
|
-
this.colorManager.addFromPalette(paletteKey);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
if (args2.colors) {
|
|
31
|
-
Object.keys(args2.colors).map(
|
|
32
|
-
(key) => this.addColor(key, args2.colors[key])
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
getColor(key) {
|
|
38
|
-
return this.colorManager.get(key);
|
|
39
|
-
}
|
|
40
|
-
removeColor(key) {
|
|
41
|
-
return this.colorManager.remove(key);
|
|
4
|
+
import { lerp, argbFromLstar, sanitizeDegreesDouble, yFromLstar, argbFromLinrgb, Cam16, signum, matrixMultiply, ViewingConditions, lstarFromArgb, lstarFromY, Contrast, clampDouble, DynamicColor as DynamicColor$1, argbFromHex, hexFromArgb, TonalPalette } from "@material/material-color-utilities";
|
|
5
|
+
import { asClass, createContainer, InjectionMode } from "awilix";
|
|
6
|
+
class API {
|
|
7
|
+
constructor({
|
|
8
|
+
colorApi,
|
|
9
|
+
pluginApi,
|
|
10
|
+
context,
|
|
11
|
+
paletteApi
|
|
12
|
+
}) {
|
|
13
|
+
__publicField(this, "colors");
|
|
14
|
+
__publicField(this, "plugins");
|
|
15
|
+
__publicField(this, "context");
|
|
16
|
+
__publicField(this, "palettes");
|
|
17
|
+
colorApi.api = this;
|
|
18
|
+
this.context = context;
|
|
19
|
+
this.plugins = pluginApi;
|
|
20
|
+
this.colors = colorApi;
|
|
21
|
+
this.palettes = paletteApi;
|
|
42
22
|
}
|
|
43
|
-
|
|
44
|
-
return this.
|
|
23
|
+
async load() {
|
|
24
|
+
return this.plugins.loadPlugins();
|
|
45
25
|
}
|
|
46
26
|
}
|
|
47
27
|
/**
|
|
@@ -933,7 +913,6 @@ class DynamicColor {
|
|
|
933
913
|
* constructed.
|
|
934
914
|
*/
|
|
935
915
|
constructor(name, palette, tone, isBackground, chromaMultiplier, background, secondBackground, contrastCurve, adjustTone) {
|
|
936
|
-
__publicField(this, "hctCache", /* @__PURE__ */ new Map());
|
|
937
916
|
this.name = name;
|
|
938
917
|
this.palette = palette;
|
|
939
918
|
this.tone = tone;
|
|
@@ -969,7 +948,7 @@ class DynamicColor {
|
|
|
969
948
|
return new DynamicColor(
|
|
970
949
|
args.name ?? "",
|
|
971
950
|
args.palette,
|
|
972
|
-
args.tone ?? DynamicColor.getInitialToneFromBackground(args.background),
|
|
951
|
+
args.tone ?? (() => DynamicColor.getInitialToneFromBackground(args.background)),
|
|
973
952
|
args.isBackground ?? false,
|
|
974
953
|
args.chromaMultiplier,
|
|
975
954
|
args.background,
|
|
@@ -978,12 +957,14 @@ class DynamicColor {
|
|
|
978
957
|
args.adjustTone
|
|
979
958
|
);
|
|
980
959
|
}
|
|
981
|
-
static getInitialToneFromBackground(
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
}
|
|
960
|
+
// static getInitialToneFromBackground(
|
|
961
|
+
// background?: () => Color | undefined,
|
|
962
|
+
// ): number {
|
|
963
|
+
// if (background === undefined) {
|
|
964
|
+
// return 50;
|
|
965
|
+
// }
|
|
966
|
+
// return (background() ? background()!.getTone() : 50);
|
|
967
|
+
// }
|
|
987
968
|
/**
|
|
988
969
|
* Given a background tone, finds a foreground tone, while ensuring they reach
|
|
989
970
|
* a contrast ratio that is as close to [ratio] as possible.
|
|
@@ -1053,13 +1034,6 @@ class DynamicColor {
|
|
|
1053
1034
|
adjustTone: this.adjustTone
|
|
1054
1035
|
});
|
|
1055
1036
|
}
|
|
1056
|
-
/**
|
|
1057
|
-
* Clears the cache of HCT values for this color. For testing or debugging
|
|
1058
|
-
* purposes.
|
|
1059
|
-
*/
|
|
1060
|
-
clearCache() {
|
|
1061
|
-
this.hctCache.clear();
|
|
1062
|
-
}
|
|
1063
1037
|
/**
|
|
1064
1038
|
* Returns a ARGB integer (i.e. a hex code).
|
|
1065
1039
|
*
|
|
@@ -1196,20 +1170,20 @@ class ToneDeltaPair {
|
|
|
1196
1170
|
this.constraint = constraint;
|
|
1197
1171
|
this.constraint = constraint ?? "exact";
|
|
1198
1172
|
}
|
|
1199
|
-
adjustedTone({
|
|
1200
|
-
scheme,
|
|
1201
|
-
dynamicColor
|
|
1202
|
-
}) {
|
|
1173
|
+
adjustedTone({ context: ctx, color }) {
|
|
1203
1174
|
const roleA = this.roleA;
|
|
1204
1175
|
const roleB = this.roleB;
|
|
1205
1176
|
const polarity = this.polarity;
|
|
1206
1177
|
const constraint = this.constraint;
|
|
1207
|
-
const absoluteDelta = polarity === "darker" || polarity === "relative_lighter" &&
|
|
1208
|
-
const amRoleA =
|
|
1178
|
+
const absoluteDelta = polarity === "darker" || polarity === "relative_lighter" && ctx.isDark || polarity === "relative_darker" && !ctx.isDark ? -this.delta : this.delta;
|
|
1179
|
+
const amRoleA = color.name === roleA.name;
|
|
1209
1180
|
const selfRole = amRoleA ? roleA : roleB;
|
|
1210
1181
|
const refRole = amRoleA ? roleB : roleA;
|
|
1211
|
-
|
|
1212
|
-
|
|
1182
|
+
if (!(selfRole instanceof ColorFromPalette)) {
|
|
1183
|
+
throw new Error("selfRole is not a ColorFromPalette");
|
|
1184
|
+
}
|
|
1185
|
+
let selfTone = selfRole.options.tone;
|
|
1186
|
+
const refTone = refRole.getTone();
|
|
1213
1187
|
const relativeDelta = absoluteDelta * (amRoleA ? 1 : -1);
|
|
1214
1188
|
if (constraint === "exact") {
|
|
1215
1189
|
selfTone = clampDouble(0, 100, refTone + relativeDelta);
|
|
@@ -1234,20 +1208,22 @@ class ToneDeltaPair {
|
|
|
1234
1208
|
selfTone = clampDouble(0, refTone + relativeDelta, selfTone);
|
|
1235
1209
|
}
|
|
1236
1210
|
}
|
|
1237
|
-
if (
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1211
|
+
if (color instanceof ColorFromPalette) {
|
|
1212
|
+
if (color.options.background && color.options.contrastCurve) {
|
|
1213
|
+
const background = color.options.background;
|
|
1214
|
+
const contrastCurve = color.options.contrastCurve;
|
|
1215
|
+
if (background && contrastCurve) {
|
|
1216
|
+
const bgTone = background.getTone();
|
|
1217
|
+
const selfContrast = contrastCurve.get(ctx.contrastLevel);
|
|
1218
|
+
selfTone = Contrast.ratioOfTones(bgTone, selfTone) >= selfContrast && ctx.contrastLevel >= 0 ? selfTone : DynamicColor$1.foregroundTone(bgTone, selfContrast);
|
|
1219
|
+
}
|
|
1244
1220
|
}
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1221
|
+
if (color.options.isBackground && !color.name.endsWith("_fixed_dim")) {
|
|
1222
|
+
if (selfTone >= 57) {
|
|
1223
|
+
selfTone = clampDouble(65, 100, selfTone);
|
|
1224
|
+
} else {
|
|
1225
|
+
selfTone = clampDouble(0, 49, selfTone);
|
|
1226
|
+
}
|
|
1251
1227
|
}
|
|
1252
1228
|
}
|
|
1253
1229
|
return selfTone;
|
|
@@ -1263,43 +1239,211 @@ function argbToRgb(argb) {
|
|
|
1263
1239
|
b: argb & 255
|
|
1264
1240
|
};
|
|
1265
1241
|
}
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
this.option = option;
|
|
1270
|
-
this.schemeService = schemeService;
|
|
1271
|
-
this.colorService = colorService;
|
|
1242
|
+
function getInitialToneFromBackground(background) {
|
|
1243
|
+
if (background === void 0) {
|
|
1244
|
+
return 50;
|
|
1272
1245
|
}
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1246
|
+
return background.getTone();
|
|
1247
|
+
}
|
|
1248
|
+
class Color {
|
|
1249
|
+
constructor(name) {
|
|
1250
|
+
this.name = name;
|
|
1276
1251
|
}
|
|
1277
1252
|
getHex() {
|
|
1278
1253
|
return hexFromArgb(this.getArgb());
|
|
1279
1254
|
}
|
|
1280
1255
|
getArgb() {
|
|
1281
|
-
return this.
|
|
1256
|
+
return this.getHct().toInt();
|
|
1282
1257
|
}
|
|
1283
1258
|
getRgb() {
|
|
1284
1259
|
return argbToRgb(this.getArgb());
|
|
1285
1260
|
}
|
|
1286
|
-
|
|
1287
|
-
return this.
|
|
1261
|
+
getTone() {
|
|
1262
|
+
return this.getHct().tone;
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
class ColorAlias extends Color {
|
|
1266
|
+
constructor(name, as, colorService) {
|
|
1267
|
+
super(name);
|
|
1268
|
+
this.as = as;
|
|
1269
|
+
this.colorService = colorService;
|
|
1270
|
+
}
|
|
1271
|
+
getHct() {
|
|
1272
|
+
return this.colorService.get(this.as).getHct();
|
|
1273
|
+
}
|
|
1274
|
+
color() {
|
|
1275
|
+
return this.colorService.get(this.as);
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
class ColorFromHex extends Color {
|
|
1279
|
+
constructor(name, _hex) {
|
|
1280
|
+
super(name);
|
|
1281
|
+
this._hex = _hex;
|
|
1282
|
+
this._hex = _hex;
|
|
1283
|
+
}
|
|
1284
|
+
getHct() {
|
|
1285
|
+
return Hct.fromInt(argbFromHex(this.getHex()));
|
|
1286
|
+
}
|
|
1287
|
+
getHex() {
|
|
1288
|
+
return this._hex;
|
|
1289
|
+
}
|
|
1290
|
+
setHex(hex) {
|
|
1291
|
+
this._hex = hex;
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
class ColorFromPalette extends Color {
|
|
1295
|
+
constructor(name, _options, context) {
|
|
1296
|
+
super(name);
|
|
1297
|
+
this._options = _options;
|
|
1298
|
+
this.context = context;
|
|
1299
|
+
this.validateOption();
|
|
1300
|
+
}
|
|
1301
|
+
get options() {
|
|
1302
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1303
|
+
const options = {
|
|
1304
|
+
...this._options,
|
|
1305
|
+
palette: this._options.palette(),
|
|
1306
|
+
tone: (_b = (_a = this._options).tone) == null ? void 0 : _b.call(_a),
|
|
1307
|
+
chromaMultiplier: (_d = (_c = this._options).chromaMultiplier) == null ? void 0 : _d.call(_c),
|
|
1308
|
+
background: (_f = (_e = this._options).background) == null ? void 0 : _f.call(_e),
|
|
1309
|
+
secondBackground: (_h = (_g = this._options).secondBackground) == null ? void 0 : _h.call(_g),
|
|
1310
|
+
contrastCurve: (_j = (_i = this._options).contrastCurve) == null ? void 0 : _j.call(_i),
|
|
1311
|
+
adjustTone: (_l = (_k = this._options).adjustTone) == null ? void 0 : _l.call(_k)
|
|
1312
|
+
};
|
|
1313
|
+
return {
|
|
1314
|
+
...options,
|
|
1315
|
+
chromaMultiplier: options.chromaMultiplier ?? 1,
|
|
1316
|
+
tone: options.tone ?? getInitialToneFromBackground(options.background)
|
|
1317
|
+
};
|
|
1318
|
+
}
|
|
1319
|
+
update(args) {
|
|
1320
|
+
this._options = { ...this._options, ...args };
|
|
1321
|
+
this.validateOption();
|
|
1322
|
+
}
|
|
1323
|
+
validateOption() {
|
|
1324
|
+
const option = this._options;
|
|
1325
|
+
if ("palette" in option) {
|
|
1326
|
+
if (!option.background && option.secondBackground) {
|
|
1327
|
+
throw new Error(
|
|
1328
|
+
`Color ${this.name} has secondBackground defined, but background is not defined.`
|
|
1329
|
+
);
|
|
1330
|
+
}
|
|
1331
|
+
if (!option.background && option.contrastCurve) {
|
|
1332
|
+
throw new Error(
|
|
1333
|
+
`Color ${this.name} has contrastCurve defined, but background is not defined.`
|
|
1334
|
+
);
|
|
1335
|
+
}
|
|
1336
|
+
if (option.background && !option.contrastCurve) {
|
|
1337
|
+
throw new Error(
|
|
1338
|
+
`Color ${this.name} has background defined, but contrastCurve is not defined.`
|
|
1339
|
+
);
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
getHct() {
|
|
1344
|
+
const option = this.options;
|
|
1345
|
+
const palette = option.palette;
|
|
1346
|
+
const tone = this.getTone();
|
|
1347
|
+
const hue = palette.hue;
|
|
1348
|
+
const chroma = palette.chroma * option.chromaMultiplier;
|
|
1349
|
+
return Hct.from(hue, chroma, tone);
|
|
1350
|
+
}
|
|
1351
|
+
getTone() {
|
|
1352
|
+
const context = this.context;
|
|
1353
|
+
const options = this.options;
|
|
1354
|
+
const adjustTone = options.adjustTone;
|
|
1355
|
+
if (adjustTone) {
|
|
1356
|
+
return adjustTone({ context, color: this });
|
|
1357
|
+
} else {
|
|
1358
|
+
let answer = options.tone;
|
|
1359
|
+
if (!options.background || !options.contrastCurve) {
|
|
1360
|
+
return answer;
|
|
1361
|
+
}
|
|
1362
|
+
const bgTone = options.background.getTone();
|
|
1363
|
+
const desiredRatio = options.contrastCurve.get(context.contrastLevel);
|
|
1364
|
+
answer = Contrast.ratioOfTones(bgTone, answer) >= desiredRatio && context.contrastLevel >= 0 ? answer : DynamicColor.foregroundTone(bgTone, desiredRatio);
|
|
1365
|
+
if (options.isBackground && !this.name.endsWith("_fixed_dim")) {
|
|
1366
|
+
if (answer >= 57) {
|
|
1367
|
+
answer = clampDouble(65, 100, answer);
|
|
1368
|
+
} else {
|
|
1369
|
+
answer = clampDouble(0, 49, answer);
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
if (!options.secondBackground) {
|
|
1373
|
+
return answer;
|
|
1374
|
+
}
|
|
1375
|
+
const [bg1, bg2] = [options.background, options.secondBackground];
|
|
1376
|
+
const [bgTone1, bgTone2] = [bg1.getTone(), bg2.getTone()];
|
|
1377
|
+
const [upper, lower] = [
|
|
1378
|
+
Math.max(bgTone1, bgTone2),
|
|
1379
|
+
Math.min(bgTone1, bgTone2)
|
|
1380
|
+
];
|
|
1381
|
+
if (Contrast.ratioOfTones(upper, answer) >= desiredRatio && Contrast.ratioOfTones(lower, answer) >= desiredRatio) {
|
|
1382
|
+
return answer;
|
|
1383
|
+
}
|
|
1384
|
+
const lightOption = Contrast.lighter(upper, desiredRatio);
|
|
1385
|
+
const darkOption = Contrast.darker(lower, desiredRatio);
|
|
1386
|
+
const availables = [];
|
|
1387
|
+
if (lightOption !== -1) availables.push(lightOption);
|
|
1388
|
+
if (darkOption !== -1) availables.push(darkOption);
|
|
1389
|
+
const prefersLight = DynamicColor.tonePrefersLightForeground(bgTone1) || DynamicColor.tonePrefersLightForeground(bgTone2);
|
|
1390
|
+
if (prefersLight) {
|
|
1391
|
+
return lightOption < 0 ? 100 : lightOption;
|
|
1392
|
+
}
|
|
1393
|
+
if (availables.length === 1) {
|
|
1394
|
+
return availables[0];
|
|
1395
|
+
}
|
|
1396
|
+
return darkOption < 0 ? 0 : darkOption;
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
const highestSurface = (context, colorService) => {
|
|
1401
|
+
if (colorService instanceof ColorApi) {
|
|
1402
|
+
return context.isDark ? colorService.get("surfaceBright") : colorService.get("surfaceDim");
|
|
1403
|
+
} else {
|
|
1404
|
+
return context.isDark ? colorService.get("surfaceBright") : colorService.get("surfaceDim");
|
|
1405
|
+
}
|
|
1406
|
+
};
|
|
1407
|
+
class ColorManager {
|
|
1408
|
+
constructor(args) {
|
|
1409
|
+
__publicField(this, "colorMap", /* @__PURE__ */ new Map());
|
|
1410
|
+
__publicField(this, "context");
|
|
1411
|
+
this.context = args.context;
|
|
1288
1412
|
}
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1413
|
+
createOrUpdate(key, args) {
|
|
1414
|
+
let colorEntity = this.colorMap.get(key);
|
|
1415
|
+
if ("alias" in args) {
|
|
1416
|
+
colorEntity = new ColorAlias(key, args.alias, this);
|
|
1417
|
+
} else if ("hex" in args) {
|
|
1418
|
+
colorEntity = new ColorFromHex(key, args.hex);
|
|
1419
|
+
} else {
|
|
1420
|
+
try {
|
|
1421
|
+
if (colorEntity instanceof ColorFromPalette) {
|
|
1422
|
+
colorEntity.update(args);
|
|
1423
|
+
} else {
|
|
1424
|
+
colorEntity = new ColorFromPalette(key, args, this.context);
|
|
1425
|
+
}
|
|
1426
|
+
} catch (e) {
|
|
1427
|
+
console.error(e);
|
|
1428
|
+
throw new Error(`Invalid color options provided for ${key}`);
|
|
1293
1429
|
}
|
|
1294
|
-
return this.colorService.get(this.option.alias).getMaterialColor();
|
|
1295
1430
|
}
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1431
|
+
this.colorMap.set(key, colorEntity);
|
|
1432
|
+
return colorEntity;
|
|
1433
|
+
}
|
|
1434
|
+
remove(key) {
|
|
1435
|
+
return this.colorMap.delete(key);
|
|
1436
|
+
}
|
|
1437
|
+
get(key) {
|
|
1438
|
+
const colorEntity = this.colorMap.get(key);
|
|
1439
|
+
if (colorEntity) {
|
|
1440
|
+
return colorEntity;
|
|
1441
|
+
} else {
|
|
1442
|
+
throw new Error(`Color ${key} does not exist`);
|
|
1301
1443
|
}
|
|
1302
|
-
|
|
1444
|
+
}
|
|
1445
|
+
getAll() {
|
|
1446
|
+
return this.colorMap;
|
|
1303
1447
|
}
|
|
1304
1448
|
}
|
|
1305
1449
|
function getCurve(defaultContrast) {
|
|
@@ -1352,64 +1496,62 @@ function findBestToneForChroma(hue, chroma, tone, byDecreasingTone) {
|
|
|
1352
1496
|
}
|
|
1353
1497
|
return answer;
|
|
1354
1498
|
}
|
|
1499
|
+
function calculateToneAdjustmentPercentage(toneA, toneB, desiredRatio) {
|
|
1500
|
+
const currentRatio = Contrast.ratioOfTones(toneA, toneB);
|
|
1501
|
+
if (currentRatio >= desiredRatio) {
|
|
1502
|
+
return 0;
|
|
1503
|
+
}
|
|
1504
|
+
const lighterTone = Contrast.lighter(toneA, desiredRatio);
|
|
1505
|
+
const darkerTone = Contrast.darker(toneA, desiredRatio);
|
|
1506
|
+
if (lighterTone !== -1 && toneB < lighterTone) {
|
|
1507
|
+
const percentageToAdjust = (toneB - lighterTone) / (toneA - lighterTone);
|
|
1508
|
+
return clampDouble(0, 1, percentageToAdjust);
|
|
1509
|
+
}
|
|
1510
|
+
if (darkerTone !== -1 && toneB > darkerTone) {
|
|
1511
|
+
const percentageToAdjust = (toneB - darkerTone) / (toneA - darkerTone);
|
|
1512
|
+
return clampDouble(0, 1, percentageToAdjust);
|
|
1513
|
+
}
|
|
1514
|
+
return 0;
|
|
1515
|
+
}
|
|
1355
1516
|
function capitalizeFirstLetter(string) {
|
|
1356
1517
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
1357
1518
|
}
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1519
|
+
class ColorApi {
|
|
1520
|
+
constructor({ colorManager }) {
|
|
1521
|
+
__publicField(this, "colorManager");
|
|
1522
|
+
__publicField(this, "api");
|
|
1523
|
+
this.colorManager = colorManager;
|
|
1363
1524
|
}
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
constructor({ schemeManager }) {
|
|
1367
|
-
__publicField(this, "colorMap", /* @__PURE__ */ new Map());
|
|
1368
|
-
__publicField(this, "schemeManager");
|
|
1369
|
-
this.schemeManager = schemeManager;
|
|
1525
|
+
getAll() {
|
|
1526
|
+
return this.colorManager.getAll();
|
|
1370
1527
|
}
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
if (!colorEntity) {
|
|
1374
|
-
const { palette, alias } = args;
|
|
1375
|
-
if (palette) {
|
|
1376
|
-
colorEntity = new ConfigurableColor(
|
|
1377
|
-
{ ...args, palette, name: key },
|
|
1378
|
-
this.schemeManager,
|
|
1379
|
-
this
|
|
1380
|
-
);
|
|
1381
|
-
this.colorMap.set(key, colorEntity);
|
|
1382
|
-
} else if (alias) {
|
|
1383
|
-
colorEntity = new ConfigurableColor(
|
|
1384
|
-
{ ...args, alias, name: key },
|
|
1385
|
-
this.schemeManager,
|
|
1386
|
-
this
|
|
1387
|
-
);
|
|
1388
|
-
this.colorMap.set(key, colorEntity);
|
|
1389
|
-
} else {
|
|
1390
|
-
throw new Error(`Palette ${palette} does not exist from ${key}`);
|
|
1391
|
-
}
|
|
1392
|
-
} else {
|
|
1393
|
-
colorEntity.update({ ...args, name: key });
|
|
1394
|
-
this.colorMap.set(key, colorEntity);
|
|
1395
|
-
}
|
|
1396
|
-
return colorEntity;
|
|
1528
|
+
addColor(key, color) {
|
|
1529
|
+
return this.colorManager.createOrUpdate(key, color);
|
|
1397
1530
|
}
|
|
1398
|
-
|
|
1399
|
-
|
|
1531
|
+
addColors(args) {
|
|
1532
|
+
if (!this.api)
|
|
1533
|
+
throw new Error(
|
|
1534
|
+
"The API is not initialized. Please call bootstrap() before calling addColors()."
|
|
1535
|
+
);
|
|
1536
|
+
if (typeof args === "function") {
|
|
1537
|
+
args = args(this.api);
|
|
1538
|
+
}
|
|
1539
|
+
if (args) {
|
|
1540
|
+
Object.entries(args).forEach(([name, colorOption]) => {
|
|
1541
|
+
this.addColor(name, colorOption);
|
|
1542
|
+
});
|
|
1543
|
+
}
|
|
1400
1544
|
}
|
|
1401
1545
|
get(key) {
|
|
1402
|
-
|
|
1403
|
-
if (colorEntity) {
|
|
1404
|
-
return colorEntity;
|
|
1405
|
-
} else {
|
|
1406
|
-
throw new Error(`Color ${key} does not exist`);
|
|
1407
|
-
}
|
|
1546
|
+
return this.colorManager.get(key);
|
|
1408
1547
|
}
|
|
1409
|
-
|
|
1410
|
-
return this.
|
|
1548
|
+
remove(key) {
|
|
1549
|
+
return this.colorManager.remove(key);
|
|
1550
|
+
}
|
|
1551
|
+
update(key, newColor) {
|
|
1552
|
+
return this.colorManager.createOrUpdate(key, newColor);
|
|
1411
1553
|
}
|
|
1412
|
-
|
|
1554
|
+
addFromCustomPalette(key) {
|
|
1413
1555
|
const colorKey = key;
|
|
1414
1556
|
const colorDimKey = colorKey + "Dim";
|
|
1415
1557
|
const ColorKey = capitalizeFirstLetter(key);
|
|
@@ -1420,383 +1562,147 @@ class ColorManager {
|
|
|
1420
1562
|
const colorFixedDimKey = colorKey + "FixedDim";
|
|
1421
1563
|
const onColorFixedKey = "on" + ColorKey + "Fixed";
|
|
1422
1564
|
const onColorFixedVariantKey = "on" + ColorKey + "FixedVariant";
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1565
|
+
const colors = ({ palettes, colors: colors2, context: ctx }) => ({
|
|
1566
|
+
[colorKey]: {
|
|
1567
|
+
palette: () => palettes.get(colorKey),
|
|
1568
|
+
tone: () => {
|
|
1569
|
+
if (ctx.variant.name === "neutral") {
|
|
1570
|
+
return ctx.isDark ? tMinC(palettes.get(colorKey), 0, 98) : tMaxC(palettes.get(colorKey));
|
|
1571
|
+
} else if (ctx.variant.name === "vibrant") {
|
|
1572
|
+
return tMaxC(palettes.get(colorKey), 0, ctx.isDark ? 90 : 98);
|
|
1573
|
+
} else {
|
|
1574
|
+
return ctx.isDark ? 80 : tMaxC(palettes.get(colorKey));
|
|
1575
|
+
}
|
|
1576
|
+
},
|
|
1577
|
+
isBackground: true,
|
|
1578
|
+
background: () => highestSurface(ctx, this),
|
|
1579
|
+
contrastCurve: () => getCurve(4.5),
|
|
1580
|
+
adjustTone: () => toneDeltaPair(
|
|
1581
|
+
colors2.get(colorContainerKey),
|
|
1582
|
+
colors2.get(colorKey),
|
|
1583
|
+
5,
|
|
1584
|
+
"relative_lighter",
|
|
1585
|
+
true,
|
|
1586
|
+
"farther"
|
|
1587
|
+
)
|
|
1433
1588
|
},
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1589
|
+
[colorDimKey]: {
|
|
1590
|
+
palette: () => palettes.get(colorKey),
|
|
1591
|
+
tone: () => {
|
|
1592
|
+
if (ctx.variant.name === "neutral") {
|
|
1593
|
+
return 85;
|
|
1594
|
+
} else {
|
|
1595
|
+
return tMaxC(palettes.get(colorKey), 0, 90);
|
|
1596
|
+
}
|
|
1597
|
+
},
|
|
1598
|
+
isBackground: true,
|
|
1599
|
+
background: () => this.get("surfaceContainerHigh"),
|
|
1600
|
+
contrastCurve: () => getCurve(4.5),
|
|
1601
|
+
adjustTone: () => toneDeltaPair(
|
|
1602
|
+
this.get(colorDimKey),
|
|
1603
|
+
this.get(colorKey),
|
|
1604
|
+
5,
|
|
1605
|
+
"darker",
|
|
1606
|
+
true,
|
|
1607
|
+
"farther"
|
|
1608
|
+
)
|
|
1454
1609
|
},
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
this.get(colorDimKey).getMaterialColor(),
|
|
1460
|
-
this.get(colorKey).getMaterialColor(),
|
|
1461
|
-
5,
|
|
1462
|
-
"darker",
|
|
1463
|
-
true,
|
|
1464
|
-
"farther"
|
|
1465
|
-
)
|
|
1466
|
-
});
|
|
1467
|
-
this.createOrUpdate(onColorKey, {
|
|
1468
|
-
palette: (s) => s.getPalette(colorKey),
|
|
1469
|
-
background: (s) => this.get(colorKey).getMaterialColor(),
|
|
1470
|
-
contrastCurve: (s) => getCurve(6)
|
|
1471
|
-
});
|
|
1472
|
-
this.createOrUpdate(colorContainerKey, {
|
|
1473
|
-
palette: (s) => s.getPalette(colorKey),
|
|
1474
|
-
tone: (s) => {
|
|
1475
|
-
if (s.variant === "vibrant") {
|
|
1476
|
-
return s.isDark ? tMinC(s.getPalette(colorKey), 30, 40) : tMaxC(s.getPalette(colorKey), 84, 90);
|
|
1477
|
-
} else if (s.variant === "expressive") {
|
|
1478
|
-
return s.isDark ? 15 : tMaxC(s.getPalette(colorKey), 90, 95);
|
|
1479
|
-
} else {
|
|
1480
|
-
return s.isDark ? 25 : 90;
|
|
1481
|
-
}
|
|
1610
|
+
[onColorKey]: {
|
|
1611
|
+
palette: () => palettes.get(colorKey),
|
|
1612
|
+
background: () => this.get(colorKey),
|
|
1613
|
+
contrastCurve: () => getCurve(6)
|
|
1482
1614
|
},
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1615
|
+
[colorContainerKey]: {
|
|
1616
|
+
palette: () => palettes.get(colorKey),
|
|
1617
|
+
tone: () => {
|
|
1618
|
+
if (ctx.variant.name === "vibrant") {
|
|
1619
|
+
return ctx.isDark ? tMinC(palettes.get(colorKey), 30, 40) : tMaxC(palettes.get(colorKey), 84, 90);
|
|
1620
|
+
} else if (ctx.variant.name === "expressive") {
|
|
1621
|
+
return ctx.isDark ? 15 : tMaxC(palettes.get(colorKey), 90, 95);
|
|
1622
|
+
} else {
|
|
1623
|
+
return ctx.isDark ? 25 : 90;
|
|
1624
|
+
}
|
|
1625
|
+
},
|
|
1626
|
+
isBackground: true,
|
|
1627
|
+
background: () => highestSurface(ctx, this),
|
|
1628
|
+
adjustTone: () => void 0,
|
|
1629
|
+
contrastCurve: () => ctx.contrastLevel > 0 ? getCurve(1.5) : void 0
|
|
1498
1630
|
},
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
true,
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1631
|
+
[onColorContainerKey]: {
|
|
1632
|
+
palette: () => palettes.get(colorKey),
|
|
1633
|
+
background: () => this.get(colorContainerKey),
|
|
1634
|
+
contrastCurve: () => getCurve(6)
|
|
1635
|
+
},
|
|
1636
|
+
[colorFixedKey]: {
|
|
1637
|
+
palette: () => palettes.get(colorKey),
|
|
1638
|
+
tone: () => {
|
|
1639
|
+
return ctx.temp({ isDark: false, contrastLevel: 0 }, () => {
|
|
1640
|
+
const color = this.get(colorContainerKey);
|
|
1641
|
+
return color.getTone();
|
|
1642
|
+
});
|
|
1643
|
+
},
|
|
1644
|
+
isBackground: true,
|
|
1645
|
+
background: () => highestSurface(ctx, this),
|
|
1646
|
+
contrastCurve: () => ctx.contrastLevel > 0 ? getCurve(1.5) : void 0
|
|
1647
|
+
},
|
|
1648
|
+
[colorFixedDimKey]: {
|
|
1649
|
+
palette: () => palettes.get(colorKey),
|
|
1650
|
+
tone: () => this.get(colorFixedKey).getTone(),
|
|
1651
|
+
isBackground: true,
|
|
1652
|
+
adjustTone: () => toneDeltaPair(
|
|
1653
|
+
this.get(colorFixedDimKey),
|
|
1654
|
+
this.get(colorFixedKey),
|
|
1655
|
+
5,
|
|
1656
|
+
"darker",
|
|
1657
|
+
true,
|
|
1658
|
+
"exact"
|
|
1659
|
+
)
|
|
1660
|
+
},
|
|
1661
|
+
[onColorFixedKey]: {
|
|
1662
|
+
palette: () => palettes.get(colorKey),
|
|
1663
|
+
background: () => this.get(colorFixedDimKey),
|
|
1664
|
+
contrastCurve: () => getCurve(7)
|
|
1665
|
+
},
|
|
1666
|
+
[onColorFixedVariantKey]: {
|
|
1667
|
+
palette: () => palettes.get(colorKey),
|
|
1668
|
+
background: () => this.get(colorFixedDimKey),
|
|
1669
|
+
contrastCurve: () => getCurve(4.5)
|
|
1670
|
+
}
|
|
1525
1671
|
});
|
|
1672
|
+
this.addColors(colors);
|
|
1526
1673
|
}
|
|
1527
1674
|
}
|
|
1528
1675
|
const ColorModule = {
|
|
1529
1676
|
colorManager: asClass(ColorManager).singleton(),
|
|
1530
1677
|
colorApi: asClass(ColorApi).singleton()
|
|
1531
1678
|
};
|
|
1532
|
-
class Scheme {
|
|
1533
|
-
constructor(options) {
|
|
1534
|
-
this.options = options;
|
|
1535
|
-
}
|
|
1536
|
-
get variant() {
|
|
1537
|
-
return this.options.variant.name;
|
|
1538
|
-
}
|
|
1539
|
-
get contrastLevel() {
|
|
1540
|
-
if (!this.options) {
|
|
1541
|
-
throw new Error("Scheme options is not set");
|
|
1542
|
-
}
|
|
1543
|
-
return this.options.contrastLevel;
|
|
1544
|
-
}
|
|
1545
|
-
get isDark() {
|
|
1546
|
-
if (!this.options) {
|
|
1547
|
-
throw new Error("Scheme options is not set");
|
|
1548
|
-
}
|
|
1549
|
-
return this.options.isDark;
|
|
1550
|
-
}
|
|
1551
|
-
get sourceColorHct() {
|
|
1552
|
-
if (!this.options) {
|
|
1553
|
-
throw new Error("Scheme options is not set");
|
|
1554
|
-
}
|
|
1555
|
-
return Hct.fromInt(this.options.sourceColorArgb);
|
|
1556
|
-
}
|
|
1557
|
-
getPalette(key) {
|
|
1558
|
-
if (!this.options) {
|
|
1559
|
-
throw new Error("Scheme options is not set");
|
|
1560
|
-
}
|
|
1561
|
-
const palette = this.options.palettes.get(key);
|
|
1562
|
-
if (!palette) {
|
|
1563
|
-
throw new Error(`Palette ${key} not found`);
|
|
1564
|
-
}
|
|
1565
|
-
return palette;
|
|
1566
|
-
}
|
|
1567
|
-
}
|
|
1568
|
-
class SchemeManager {
|
|
1569
|
-
constructor() {
|
|
1570
|
-
__publicField(this, "schemeEntity");
|
|
1571
|
-
__publicField(this, "options");
|
|
1572
|
-
}
|
|
1573
|
-
createOrUpdate(options) {
|
|
1574
|
-
var _a, _b;
|
|
1575
|
-
this.options = {
|
|
1576
|
-
...this.options,
|
|
1577
|
-
...options,
|
|
1578
|
-
sourcesColorHex: {
|
|
1579
|
-
...(_a = this.options) == null ? void 0 : _a.sourcesColorHex,
|
|
1580
|
-
...options.sourcesColorHex
|
|
1581
|
-
},
|
|
1582
|
-
palettes: {
|
|
1583
|
-
...(_b = this.options) == null ? void 0 : _b.palettes,
|
|
1584
|
-
...options.palettes
|
|
1585
|
-
}
|
|
1586
|
-
};
|
|
1587
|
-
const palettes = /* @__PURE__ */ new Map();
|
|
1588
|
-
if (!this.options.sourcesColorHex.primary) {
|
|
1589
|
-
throw new Error("Primary source color is not set");
|
|
1590
|
-
}
|
|
1591
|
-
const sourceColorArgb = argbFromHex(this.options.sourcesColorHex.primary);
|
|
1592
|
-
const sourceColorHct = Hct.fromInt(sourceColorArgb);
|
|
1593
|
-
if (!this.options.palettes) {
|
|
1594
|
-
return;
|
|
1595
|
-
}
|
|
1596
|
-
for (const [
|
|
1597
|
-
key,
|
|
1598
|
-
{ sourceColorkey, tonalPalette: paletteFunction }
|
|
1599
|
-
] of Object.entries(this.options.palettes)) {
|
|
1600
|
-
let palette;
|
|
1601
|
-
if (typeof sourceColorkey != "string") {
|
|
1602
|
-
palette = paletteFunction({
|
|
1603
|
-
sourceColorHct,
|
|
1604
|
-
isDark: options.isDark ?? false
|
|
1605
|
-
});
|
|
1606
|
-
} else {
|
|
1607
|
-
const sourceColorArgb2 = argbFromHex(
|
|
1608
|
-
this.options.sourcesColorHex[sourceColorkey]
|
|
1609
|
-
);
|
|
1610
|
-
const colorHct = Hct.fromInt(sourceColorArgb2);
|
|
1611
|
-
palette = paletteFunction({
|
|
1612
|
-
sourceColorHct,
|
|
1613
|
-
colorHct,
|
|
1614
|
-
isDark: options.isDark ?? false
|
|
1615
|
-
});
|
|
1616
|
-
}
|
|
1617
|
-
palettes.set(key, palette);
|
|
1618
|
-
}
|
|
1619
|
-
this.schemeEntity = new Scheme({
|
|
1620
|
-
...this.options,
|
|
1621
|
-
palettes,
|
|
1622
|
-
sourceColorArgb
|
|
1623
|
-
});
|
|
1624
|
-
}
|
|
1625
|
-
get() {
|
|
1626
|
-
if (!this.schemeEntity) {
|
|
1627
|
-
throw new Error("Scheme is not created");
|
|
1628
|
-
}
|
|
1629
|
-
return this.schemeEntity;
|
|
1630
|
-
}
|
|
1631
|
-
}
|
|
1632
|
-
class VariantManager {
|
|
1633
|
-
constructor({ schemeManager }) {
|
|
1634
|
-
__publicField(this, "customPalettes", {});
|
|
1635
|
-
__publicField(this, "variantEntity");
|
|
1636
|
-
__publicField(this, "schemeManager");
|
|
1637
|
-
this.schemeManager = schemeManager;
|
|
1638
|
-
}
|
|
1639
|
-
addCustomPalette(key, colorHex) {
|
|
1640
|
-
this.customPalettes[key] = colorHex;
|
|
1641
|
-
this.update();
|
|
1642
|
-
}
|
|
1643
|
-
set(variantEntity) {
|
|
1644
|
-
this.variantEntity = variantEntity;
|
|
1645
|
-
this.update();
|
|
1646
|
-
}
|
|
1647
|
-
update() {
|
|
1648
|
-
if (!this.variantEntity) return;
|
|
1649
|
-
const palettes = {};
|
|
1650
|
-
Object.keys(this.variantEntity.palettes).forEach((key) => {
|
|
1651
|
-
palettes[key] = { tonalPalette: this.variantEntity.palettes[key] };
|
|
1652
|
-
});
|
|
1653
|
-
const customPalettes = this.variantEntity.customPalettes;
|
|
1654
|
-
if (customPalettes) {
|
|
1655
|
-
Object.keys(this.customPalettes).forEach((key) => {
|
|
1656
|
-
palettes[key] = {
|
|
1657
|
-
sourceColorkey: key,
|
|
1658
|
-
tonalPalette: customPalettes
|
|
1659
|
-
};
|
|
1660
|
-
});
|
|
1661
|
-
}
|
|
1662
|
-
this.schemeManager.createOrUpdate({
|
|
1663
|
-
sourcesColorHex: this.customPalettes,
|
|
1664
|
-
palettes
|
|
1665
|
-
});
|
|
1666
|
-
}
|
|
1667
|
-
}
|
|
1668
|
-
DynamicColor$1.fromPalette({
|
|
1669
|
-
name: "primary_palette_key_color",
|
|
1670
|
-
palette: (s) => s.primaryPalette,
|
|
1671
|
-
tone: (s) => s.primaryPalette.keyColor.tone
|
|
1672
|
-
});
|
|
1673
|
-
class ThemeApi {
|
|
1674
|
-
constructor({
|
|
1675
|
-
schemeManager,
|
|
1676
|
-
variantManager
|
|
1677
|
-
}) {
|
|
1678
|
-
__publicField(this, "schemeManager");
|
|
1679
|
-
__publicField(this, "variantManager");
|
|
1680
|
-
this.schemeManager = schemeManager;
|
|
1681
|
-
this.variantManager = variantManager;
|
|
1682
|
-
}
|
|
1683
|
-
// addPalette({key, palette, addDefaultColors}: {key: string; palette: TonalPalette; addDefaultColors: boolean}) {
|
|
1684
|
-
// this.themeOptions.palettes.set(key, palette);
|
|
1685
|
-
// if (addDefaultColors){
|
|
1686
|
-
// this.colorService.addPalette(key)
|
|
1687
|
-
// }
|
|
1688
|
-
// }
|
|
1689
|
-
// create(args: ThemeOptions): SchemeService {
|
|
1690
|
-
// return new SchemeService(args, this.colorService)
|
|
1691
|
-
// }
|
|
1692
|
-
//
|
|
1693
|
-
// update(options: Partial<ThemeOptions>): SchemeService {
|
|
1694
|
-
// Object.assign(this.themeOptions, options);
|
|
1695
|
-
// return this.theme();
|
|
1696
|
-
// }
|
|
1697
|
-
get sourceColorHex() {
|
|
1698
|
-
return this.schemeManager.get().sourceColorHct;
|
|
1699
|
-
}
|
|
1700
|
-
create(options) {
|
|
1701
|
-
this.schemeManager.createOrUpdate({
|
|
1702
|
-
...options,
|
|
1703
|
-
sourcesColorHex: { primary: options.sourceColorHex }
|
|
1704
|
-
});
|
|
1705
|
-
this.variantManager.set(options.variant);
|
|
1706
|
-
}
|
|
1707
|
-
update(options) {
|
|
1708
|
-
const themeOptions = { ...options };
|
|
1709
|
-
if (options.sourceColorHex)
|
|
1710
|
-
themeOptions.sourcesColorHex = { primary: options.sourceColorHex };
|
|
1711
|
-
this.schemeManager.createOrUpdate(themeOptions);
|
|
1712
|
-
if (options.variant) this.variantManager.set(options.variant);
|
|
1713
|
-
}
|
|
1714
|
-
addCustomPalette(key, colorHex) {
|
|
1715
|
-
this.variantManager.addCustomPalette(key, colorHex);
|
|
1716
|
-
}
|
|
1717
|
-
// theme(): SchemeService {
|
|
1718
|
-
// return new SchemeService(this.themeOptions, this.colorService)
|
|
1719
|
-
// }
|
|
1720
|
-
}
|
|
1721
|
-
const ThemeModule = {
|
|
1722
|
-
schemeManager: asClass(SchemeManager).singleton(),
|
|
1723
|
-
variantManager: asClass(VariantManager).singleton(),
|
|
1724
|
-
themeApi: asClass(ThemeApi).singleton()
|
|
1725
|
-
};
|
|
1726
|
-
const getPiecewiseHue = (sourceColorHct, hueBreakpoints, hues) => {
|
|
1727
|
-
const size = Math.min(hueBreakpoints.length - 1, hues.length);
|
|
1728
|
-
const sourceHue = sourceColorHct.hue;
|
|
1729
|
-
for (let i = 0; i < size; i++) {
|
|
1730
|
-
if (sourceHue >= hueBreakpoints[i] && sourceHue < hueBreakpoints[i + 1]) {
|
|
1731
|
-
return sanitizeDegreesDouble(hues[i]);
|
|
1732
|
-
}
|
|
1733
|
-
}
|
|
1734
|
-
return sourceHue;
|
|
1735
|
-
};
|
|
1736
|
-
const getRotatedHue = (sourceColorHct, hueBreakpoints, rotations) => {
|
|
1737
|
-
let rotation = getPiecewiseHue(sourceColorHct, hueBreakpoints, rotations);
|
|
1738
|
-
if (Math.min(hueBreakpoints.length - 1, rotations.length) <= 0) {
|
|
1739
|
-
rotation = 0;
|
|
1740
|
-
}
|
|
1741
|
-
return sanitizeDegreesDouble(sourceColorHct.hue + rotation);
|
|
1742
|
-
};
|
|
1743
|
-
class Variant {
|
|
1744
|
-
constructor(palettes = {}, name, customPalettes, colors) {
|
|
1745
|
-
this.palettes = palettes;
|
|
1746
|
-
this.name = name;
|
|
1747
|
-
this.customPalettes = customPalettes;
|
|
1748
|
-
this.colors = colors;
|
|
1749
|
-
}
|
|
1750
|
-
}
|
|
1751
|
-
const tonalSpotVariant = {
|
|
1752
|
-
name: "tonalSpot",
|
|
1753
|
-
palettes: {
|
|
1754
|
-
primary: ({ sourceColorHct, isDark }) => TonalPalette.fromHueAndChroma(sourceColorHct.hue, isDark ? 26 : 32),
|
|
1755
|
-
secondary: ({ sourceColorHct }) => TonalPalette.fromHueAndChroma(sourceColorHct.hue, 16),
|
|
1756
|
-
tertiary: ({ sourceColorHct }) => TonalPalette.fromHueAndChroma(
|
|
1757
|
-
getRotatedHue(
|
|
1758
|
-
sourceColorHct,
|
|
1759
|
-
[0, 20, 71, 161, 333, 360],
|
|
1760
|
-
[-40, 48, -32, 40, -32]
|
|
1761
|
-
),
|
|
1762
|
-
28
|
|
1763
|
-
),
|
|
1764
|
-
neutral: ({ sourceColorHct }) => TonalPalette.fromHueAndChroma(sourceColorHct.hue, 5),
|
|
1765
|
-
neutralVariant: ({ sourceColorHct }) => TonalPalette.fromHueAndChroma(sourceColorHct.hue, 5 * 1.7),
|
|
1766
|
-
error: ({ sourceColorHct }) => {
|
|
1767
|
-
const errorHue = getPiecewiseHue(
|
|
1768
|
-
sourceColorHct,
|
|
1769
|
-
[0, 3, 13, 23, 33, 43, 153, 273, 360],
|
|
1770
|
-
[12, 22, 32, 12, 22, 32, 22, 12]
|
|
1771
|
-
);
|
|
1772
|
-
return TonalPalette.fromHueAndChroma(errorHue, 60);
|
|
1773
|
-
}
|
|
1774
|
-
},
|
|
1775
|
-
customPalettes: ({ colorHct }) => TonalPalette.fromHueAndChroma(colorHct.hue, 16)
|
|
1776
|
-
};
|
|
1777
1679
|
const inverseTone = (tone) => {
|
|
1778
1680
|
return 100 - tone;
|
|
1779
1681
|
};
|
|
1780
|
-
const defaultColors = (
|
|
1682
|
+
const defaultColors = ({
|
|
1683
|
+
colors,
|
|
1684
|
+
context: c,
|
|
1685
|
+
palettes
|
|
1686
|
+
}) => {
|
|
1781
1687
|
const getColor = (key) => {
|
|
1782
|
-
return
|
|
1688
|
+
return colors.get(key);
|
|
1783
1689
|
};
|
|
1784
|
-
|
|
1690
|
+
return {
|
|
1785
1691
|
////////////////////////////////////////////////////////////////
|
|
1786
1692
|
// Surfaces [S] //
|
|
1787
1693
|
////////////////////////////////////////////////////////////////
|
|
1788
1694
|
surface: {
|
|
1789
|
-
palette: (
|
|
1790
|
-
tone: (
|
|
1791
|
-
if (
|
|
1695
|
+
palette: () => palettes.get("neutral"),
|
|
1696
|
+
tone: () => {
|
|
1697
|
+
if (c.isDark) {
|
|
1792
1698
|
return 4;
|
|
1793
1699
|
} else {
|
|
1794
|
-
if (
|
|
1700
|
+
if (c.variant.name == "fidelity") {
|
|
1795
1701
|
return 100;
|
|
1796
1702
|
}
|
|
1797
|
-
if (Hct.isYellow(
|
|
1703
|
+
if (Hct.isYellow(palettes.get("neutral").hue)) {
|
|
1798
1704
|
return 99;
|
|
1799
|
-
} else if (
|
|
1705
|
+
} else if (c.variant.name === "vibrant") {
|
|
1800
1706
|
return 97;
|
|
1801
1707
|
} else {
|
|
1802
1708
|
return 98;
|
|
@@ -1806,14 +1712,14 @@ const defaultColors = (colorService) => {
|
|
|
1806
1712
|
isBackground: true
|
|
1807
1713
|
},
|
|
1808
1714
|
surfaceDim: {
|
|
1809
|
-
palette: (
|
|
1810
|
-
tone: (
|
|
1811
|
-
if (
|
|
1715
|
+
palette: () => palettes.get("neutral"),
|
|
1716
|
+
tone: () => {
|
|
1717
|
+
if (c.isDark) {
|
|
1812
1718
|
return 4;
|
|
1813
1719
|
} else {
|
|
1814
|
-
if (Hct.isYellow(
|
|
1720
|
+
if (Hct.isYellow(palettes.get("neutral").hue)) {
|
|
1815
1721
|
return 90;
|
|
1816
|
-
} else if (
|
|
1722
|
+
} else if (c.variant.name === "vibrant") {
|
|
1817
1723
|
return 85;
|
|
1818
1724
|
} else {
|
|
1819
1725
|
return 87;
|
|
@@ -1821,15 +1727,15 @@ const defaultColors = (colorService) => {
|
|
|
1821
1727
|
}
|
|
1822
1728
|
},
|
|
1823
1729
|
isBackground: true,
|
|
1824
|
-
chromaMultiplier: (
|
|
1825
|
-
if (!
|
|
1826
|
-
if (
|
|
1730
|
+
chromaMultiplier: () => {
|
|
1731
|
+
if (!c.isDark) {
|
|
1732
|
+
if (c.variant.name === "neutral") {
|
|
1827
1733
|
return 2.5;
|
|
1828
|
-
} else if (
|
|
1734
|
+
} else if (c.variant.name === "tonalSpot") {
|
|
1829
1735
|
return 1.7;
|
|
1830
|
-
} else if (
|
|
1831
|
-
return Hct.isYellow(
|
|
1832
|
-
} else if (
|
|
1736
|
+
} else if (c.variant.name === "expressive") {
|
|
1737
|
+
return Hct.isYellow(palettes.get("neutral").hue) ? 2.7 : 1.75;
|
|
1738
|
+
} else if (c.variant.name === "vibrant") {
|
|
1833
1739
|
return 1.36;
|
|
1834
1740
|
}
|
|
1835
1741
|
}
|
|
@@ -1837,14 +1743,14 @@ const defaultColors = (colorService) => {
|
|
|
1837
1743
|
}
|
|
1838
1744
|
},
|
|
1839
1745
|
surfaceBright: {
|
|
1840
|
-
palette: (
|
|
1841
|
-
tone: (
|
|
1842
|
-
if (
|
|
1746
|
+
palette: () => palettes.get("neutral"),
|
|
1747
|
+
tone: () => {
|
|
1748
|
+
if (c.isDark) {
|
|
1843
1749
|
return 18;
|
|
1844
1750
|
} else {
|
|
1845
|
-
if (Hct.isYellow(
|
|
1751
|
+
if (Hct.isYellow(palettes.get("neutral").hue)) {
|
|
1846
1752
|
return 99;
|
|
1847
|
-
} else if (
|
|
1753
|
+
} else if (c.variant.name === "vibrant") {
|
|
1848
1754
|
return 97;
|
|
1849
1755
|
} else {
|
|
1850
1756
|
return 98;
|
|
@@ -1852,15 +1758,15 @@ const defaultColors = (colorService) => {
|
|
|
1852
1758
|
}
|
|
1853
1759
|
},
|
|
1854
1760
|
isBackground: true,
|
|
1855
|
-
chromaMultiplier: (
|
|
1856
|
-
if (
|
|
1857
|
-
if (
|
|
1761
|
+
chromaMultiplier: () => {
|
|
1762
|
+
if (c.isDark) {
|
|
1763
|
+
if (c.variant.name === "neutral") {
|
|
1858
1764
|
return 2.5;
|
|
1859
|
-
} else if (
|
|
1765
|
+
} else if (c.variant.name === "tonalSpot") {
|
|
1860
1766
|
return 1.7;
|
|
1861
|
-
} else if (
|
|
1862
|
-
return Hct.isYellow(
|
|
1863
|
-
} else if (
|
|
1767
|
+
} else if (c.variant.name === "expressive") {
|
|
1768
|
+
return Hct.isYellow(palettes.get("neutral").hue) ? 2.7 : 1.75;
|
|
1769
|
+
} else if (c.variant.name === "vibrant") {
|
|
1864
1770
|
return 1.36;
|
|
1865
1771
|
}
|
|
1866
1772
|
}
|
|
@@ -1868,19 +1774,19 @@ const defaultColors = (colorService) => {
|
|
|
1868
1774
|
}
|
|
1869
1775
|
},
|
|
1870
1776
|
surfaceContainerLowest: {
|
|
1871
|
-
palette: (
|
|
1872
|
-
tone: (
|
|
1777
|
+
palette: () => palettes.get("neutral"),
|
|
1778
|
+
tone: () => c.isDark ? 0 : 100,
|
|
1873
1779
|
isBackground: true
|
|
1874
1780
|
},
|
|
1875
1781
|
surfaceContainerLow: {
|
|
1876
|
-
palette: (
|
|
1877
|
-
tone: (
|
|
1878
|
-
if (
|
|
1782
|
+
palette: () => palettes.get("neutral"),
|
|
1783
|
+
tone: () => {
|
|
1784
|
+
if (c.isDark) {
|
|
1879
1785
|
return 6;
|
|
1880
1786
|
} else {
|
|
1881
|
-
if (Hct.isYellow(
|
|
1787
|
+
if (Hct.isYellow(palettes.get("neutral").hue)) {
|
|
1882
1788
|
return 98;
|
|
1883
|
-
} else if (
|
|
1789
|
+
} else if (c.variant.name === "vibrant") {
|
|
1884
1790
|
return 95;
|
|
1885
1791
|
} else {
|
|
1886
1792
|
return 96;
|
|
@@ -1888,28 +1794,28 @@ const defaultColors = (colorService) => {
|
|
|
1888
1794
|
}
|
|
1889
1795
|
},
|
|
1890
1796
|
isBackground: true,
|
|
1891
|
-
chromaMultiplier: (
|
|
1892
|
-
if (
|
|
1797
|
+
chromaMultiplier: () => {
|
|
1798
|
+
if (c.variant.name === "neutral") {
|
|
1893
1799
|
return 1.3;
|
|
1894
|
-
} else if (
|
|
1800
|
+
} else if (c.variant.name === "tonalSpot") {
|
|
1895
1801
|
return 1.25;
|
|
1896
|
-
} else if (
|
|
1897
|
-
return Hct.isYellow(
|
|
1898
|
-
} else if (
|
|
1802
|
+
} else if (c.variant.name === "expressive") {
|
|
1803
|
+
return Hct.isYellow(palettes.get("neutral").hue) ? 1.3 : 1.15;
|
|
1804
|
+
} else if (c.variant.name === "vibrant") {
|
|
1899
1805
|
return 1.08;
|
|
1900
1806
|
}
|
|
1901
1807
|
return 1;
|
|
1902
1808
|
}
|
|
1903
1809
|
},
|
|
1904
1810
|
surfaceContainer: {
|
|
1905
|
-
palette: (
|
|
1906
|
-
tone: (
|
|
1907
|
-
if (
|
|
1811
|
+
palette: () => palettes.get("neutral"),
|
|
1812
|
+
tone: () => {
|
|
1813
|
+
if (c.isDark) {
|
|
1908
1814
|
return 9;
|
|
1909
1815
|
} else {
|
|
1910
|
-
if (Hct.isYellow(
|
|
1816
|
+
if (Hct.isYellow(palettes.get("neutral").hue)) {
|
|
1911
1817
|
return 96;
|
|
1912
|
-
} else if (
|
|
1818
|
+
} else if (c.variant.name === "vibrant") {
|
|
1913
1819
|
return 92;
|
|
1914
1820
|
} else {
|
|
1915
1821
|
return 94;
|
|
@@ -1917,28 +1823,28 @@ const defaultColors = (colorService) => {
|
|
|
1917
1823
|
}
|
|
1918
1824
|
},
|
|
1919
1825
|
isBackground: true,
|
|
1920
|
-
chromaMultiplier: (
|
|
1921
|
-
if (
|
|
1826
|
+
chromaMultiplier: () => {
|
|
1827
|
+
if (c.variant.name === "neutral") {
|
|
1922
1828
|
return 1.6;
|
|
1923
|
-
} else if (
|
|
1829
|
+
} else if (c.variant.name === "tonalSpot") {
|
|
1924
1830
|
return 1.4;
|
|
1925
|
-
} else if (
|
|
1926
|
-
return Hct.isYellow(
|
|
1927
|
-
} else if (
|
|
1831
|
+
} else if (c.variant.name === "expressive") {
|
|
1832
|
+
return Hct.isYellow(palettes.get("neutral").hue) ? 1.6 : 1.3;
|
|
1833
|
+
} else if (c.variant.name === "vibrant") {
|
|
1928
1834
|
return 1.15;
|
|
1929
1835
|
}
|
|
1930
1836
|
return 1;
|
|
1931
1837
|
}
|
|
1932
1838
|
},
|
|
1933
1839
|
surfaceContainerHigh: {
|
|
1934
|
-
palette: (
|
|
1935
|
-
tone: (
|
|
1936
|
-
if (
|
|
1840
|
+
palette: () => palettes.get("neutral"),
|
|
1841
|
+
tone: () => {
|
|
1842
|
+
if (c.isDark) {
|
|
1937
1843
|
return 12;
|
|
1938
1844
|
} else {
|
|
1939
|
-
if (Hct.isYellow(
|
|
1845
|
+
if (Hct.isYellow(palettes.get("neutral").hue)) {
|
|
1940
1846
|
return 94;
|
|
1941
|
-
} else if (
|
|
1847
|
+
} else if (c.variant.name === "vibrant") {
|
|
1942
1848
|
return 90;
|
|
1943
1849
|
} else {
|
|
1944
1850
|
return 92;
|
|
@@ -1946,28 +1852,28 @@ const defaultColors = (colorService) => {
|
|
|
1946
1852
|
}
|
|
1947
1853
|
},
|
|
1948
1854
|
isBackground: true,
|
|
1949
|
-
chromaMultiplier: (
|
|
1950
|
-
if (
|
|
1855
|
+
chromaMultiplier: () => {
|
|
1856
|
+
if (c.variant.name === "neutral") {
|
|
1951
1857
|
return 1.9;
|
|
1952
|
-
} else if (
|
|
1858
|
+
} else if (c.variant.name === "tonalSpot") {
|
|
1953
1859
|
return 1.5;
|
|
1954
|
-
} else if (
|
|
1955
|
-
return Hct.isYellow(
|
|
1956
|
-
} else if (
|
|
1860
|
+
} else if (c.variant.name === "expressive") {
|
|
1861
|
+
return Hct.isYellow(palettes.get("neutral").hue) ? 1.95 : 1.45;
|
|
1862
|
+
} else if (c.variant.name === "vibrant") {
|
|
1957
1863
|
return 1.22;
|
|
1958
1864
|
}
|
|
1959
1865
|
return 1;
|
|
1960
1866
|
}
|
|
1961
1867
|
},
|
|
1962
1868
|
surfaceContainerHighest: {
|
|
1963
|
-
palette: (
|
|
1964
|
-
tone: (
|
|
1965
|
-
if (
|
|
1869
|
+
palette: () => palettes.get("neutral"),
|
|
1870
|
+
tone: () => {
|
|
1871
|
+
if (c.isDark) {
|
|
1966
1872
|
return 15;
|
|
1967
1873
|
} else {
|
|
1968
|
-
if (Hct.isYellow(
|
|
1874
|
+
if (Hct.isYellow(palettes.get("neutral").hue)) {
|
|
1969
1875
|
return 92;
|
|
1970
|
-
} else if (
|
|
1876
|
+
} else if (c.variant.name === "vibrant") {
|
|
1971
1877
|
return 88;
|
|
1972
1878
|
} else {
|
|
1973
1879
|
return 90;
|
|
@@ -1975,14 +1881,14 @@ const defaultColors = (colorService) => {
|
|
|
1975
1881
|
}
|
|
1976
1882
|
},
|
|
1977
1883
|
isBackground: true,
|
|
1978
|
-
chromaMultiplier: (
|
|
1979
|
-
if (
|
|
1884
|
+
chromaMultiplier: () => {
|
|
1885
|
+
if (c.variant.name === "neutral") {
|
|
1980
1886
|
return 2.2;
|
|
1981
|
-
} else if (
|
|
1887
|
+
} else if (c.variant.name === "tonalSpot") {
|
|
1982
1888
|
return 1.7;
|
|
1983
|
-
} else if (
|
|
1984
|
-
return Hct.isYellow(
|
|
1985
|
-
} else if (
|
|
1889
|
+
} else if (c.variant.name === "expressive") {
|
|
1890
|
+
return Hct.isYellow(palettes.get("neutral").hue) ? 2.3 : 1.6;
|
|
1891
|
+
} else if (c.variant.name === "vibrant") {
|
|
1986
1892
|
return 1.29;
|
|
1987
1893
|
} else {
|
|
1988
1894
|
return 1;
|
|
@@ -1990,132 +1896,133 @@ const defaultColors = (colorService) => {
|
|
|
1990
1896
|
}
|
|
1991
1897
|
},
|
|
1992
1898
|
onSurface: {
|
|
1993
|
-
palette: (
|
|
1994
|
-
tone: (
|
|
1995
|
-
if (
|
|
1996
|
-
return tMaxC(
|
|
1899
|
+
palette: () => palettes.get("neutral"),
|
|
1900
|
+
tone: () => {
|
|
1901
|
+
if (c.variant.name === "vibrant") {
|
|
1902
|
+
return tMaxC(palettes.get("neutral"), 0, 100, 1.1);
|
|
1997
1903
|
} else {
|
|
1998
|
-
return
|
|
1999
|
-
(s2) => highestSurface(s2, colorService)
|
|
2000
|
-
)(s);
|
|
1904
|
+
return getInitialToneFromBackground(highestSurface(c, colors));
|
|
2001
1905
|
}
|
|
2002
1906
|
},
|
|
2003
|
-
chromaMultiplier: (
|
|
2004
|
-
if (
|
|
1907
|
+
chromaMultiplier: () => {
|
|
1908
|
+
if (c.variant.name === "neutral") {
|
|
2005
1909
|
return 2.2;
|
|
2006
|
-
} else if (
|
|
1910
|
+
} else if (c.variant.name === "tonalSpot") {
|
|
2007
1911
|
return 1.7;
|
|
2008
|
-
} else if (
|
|
2009
|
-
return Hct.isYellow(
|
|
1912
|
+
} else if (c.variant.name === "expressive") {
|
|
1913
|
+
return Hct.isYellow(palettes.get("neutral").hue) ? c.isDark ? 3 : 2.3 : 1.6;
|
|
2010
1914
|
}
|
|
2011
1915
|
return 1;
|
|
2012
1916
|
},
|
|
2013
|
-
background: (
|
|
2014
|
-
contrastCurve: (
|
|
1917
|
+
background: () => highestSurface(c, colors),
|
|
1918
|
+
contrastCurve: () => c.isDark ? getCurve(11) : getCurve(9)
|
|
2015
1919
|
},
|
|
2016
1920
|
onSurfaceVariant: {
|
|
2017
|
-
palette: (
|
|
2018
|
-
chromaMultiplier: (
|
|
2019
|
-
if (
|
|
1921
|
+
palette: () => palettes.get("neutralVariant"),
|
|
1922
|
+
chromaMultiplier: () => {
|
|
1923
|
+
if (c.variant.name === "neutral") {
|
|
2020
1924
|
return 2.2;
|
|
2021
|
-
} else if (
|
|
1925
|
+
} else if (c.variant.name === "tonalSpot") {
|
|
2022
1926
|
return 1.7;
|
|
2023
|
-
} else if (
|
|
2024
|
-
return Hct.isYellow(
|
|
1927
|
+
} else if (c.variant.name === "expressive") {
|
|
1928
|
+
return Hct.isYellow(palettes.get("neutral").hue) ? c.isDark ? 3 : 2.3 : 1.6;
|
|
2025
1929
|
}
|
|
2026
1930
|
return 1;
|
|
2027
1931
|
},
|
|
2028
|
-
background: (
|
|
2029
|
-
contrastCurve: (
|
|
1932
|
+
background: () => highestSurface(c, colors),
|
|
1933
|
+
contrastCurve: () => c.isDark ? getCurve(6) : getCurve(4.5)
|
|
2030
1934
|
},
|
|
2031
1935
|
outline: {
|
|
2032
|
-
palette: (
|
|
2033
|
-
chromaMultiplier: (
|
|
2034
|
-
if (
|
|
1936
|
+
palette: () => palettes.get("neutralVariant"),
|
|
1937
|
+
chromaMultiplier: () => {
|
|
1938
|
+
if (c.variant.name === "neutral") {
|
|
2035
1939
|
return 2.2;
|
|
2036
|
-
} else if (
|
|
1940
|
+
} else if (c.variant.name === "tonalSpot") {
|
|
2037
1941
|
return 1.7;
|
|
2038
|
-
} else if (
|
|
2039
|
-
return Hct.isYellow(
|
|
1942
|
+
} else if (c.variant.name === "expressive") {
|
|
1943
|
+
return Hct.isYellow(palettes.get("neutral").hue) ? c.isDark ? 3 : 2.3 : 1.6;
|
|
2040
1944
|
}
|
|
2041
1945
|
return 1;
|
|
2042
1946
|
},
|
|
2043
|
-
background: (
|
|
2044
|
-
contrastCurve: (
|
|
1947
|
+
background: () => highestSurface(c, colors),
|
|
1948
|
+
contrastCurve: () => getCurve(3)
|
|
2045
1949
|
},
|
|
2046
1950
|
outlineVariant: {
|
|
2047
|
-
palette: (
|
|
2048
|
-
chromaMultiplier: (
|
|
2049
|
-
if (
|
|
1951
|
+
palette: () => palettes.get("neutralVariant"),
|
|
1952
|
+
chromaMultiplier: () => {
|
|
1953
|
+
if (c.variant.name === "neutral") {
|
|
2050
1954
|
return 2.2;
|
|
2051
|
-
} else if (
|
|
1955
|
+
} else if (c.variant.name === "tonalSpot") {
|
|
2052
1956
|
return 1.7;
|
|
2053
|
-
} else if (
|
|
2054
|
-
return Hct.isYellow(
|
|
1957
|
+
} else if (c.variant.name === "expressive") {
|
|
1958
|
+
return Hct.isYellow(palettes.get("neutral").hue) ? c.isDark ? 3 : 2.3 : 1.6;
|
|
2055
1959
|
}
|
|
2056
1960
|
return 1;
|
|
2057
1961
|
},
|
|
2058
|
-
background: (
|
|
2059
|
-
contrastCurve: (
|
|
1962
|
+
background: () => highestSurface(c, colors),
|
|
1963
|
+
contrastCurve: () => getCurve(1.5)
|
|
2060
1964
|
},
|
|
2061
1965
|
inverseSurface: {
|
|
2062
|
-
palette: (
|
|
2063
|
-
tone: (
|
|
1966
|
+
palette: () => palettes.get("neutral"),
|
|
1967
|
+
tone: () => c.isDark ? 98 : 4,
|
|
2064
1968
|
isBackground: true
|
|
2065
1969
|
},
|
|
2066
1970
|
inverseOnSurface: {
|
|
2067
|
-
palette: (
|
|
2068
|
-
tone: (
|
|
2069
|
-
background: (
|
|
2070
|
-
contrastCurve: (
|
|
1971
|
+
palette: () => palettes.get("neutral"),
|
|
1972
|
+
tone: () => c.isDark ? 20 : 95,
|
|
1973
|
+
background: () => colors.get("inverseSurface"),
|
|
1974
|
+
contrastCurve: () => getCurve(7)
|
|
2071
1975
|
},
|
|
2072
1976
|
////////////////////////////////////////////////////////////////
|
|
2073
1977
|
// Primaries [P] //
|
|
2074
1978
|
////////////////////////////////////////////////////////////////
|
|
2075
1979
|
primary: {
|
|
2076
|
-
palette: (
|
|
2077
|
-
tone: (
|
|
2078
|
-
if (
|
|
2079
|
-
return
|
|
2080
|
-
} else if (
|
|
2081
|
-
if (
|
|
1980
|
+
palette: () => palettes.get("primary"),
|
|
1981
|
+
tone: () => {
|
|
1982
|
+
if (c.variant.name === "neutral") {
|
|
1983
|
+
return c.isDark ? 80 : 40;
|
|
1984
|
+
} else if (c.variant.name === "tonalSpot") {
|
|
1985
|
+
if (c.isDark) {
|
|
2082
1986
|
return 80;
|
|
2083
1987
|
} else {
|
|
2084
|
-
return tMaxC(
|
|
1988
|
+
return tMaxC(palettes.get("primary"));
|
|
2085
1989
|
}
|
|
2086
|
-
} else if (
|
|
1990
|
+
} else if (c.variant.name === "expressive") {
|
|
2087
1991
|
return tMaxC(
|
|
2088
|
-
|
|
1992
|
+
palettes.get("primary"),
|
|
2089
1993
|
0,
|
|
2090
|
-
Hct.isYellow(
|
|
1994
|
+
Hct.isYellow(palettes.get("primary").hue) ? 25 : Hct.isCyan(palettes.get("primary").hue) ? 88 : 98
|
|
2091
1995
|
);
|
|
2092
|
-
} else if (
|
|
2093
|
-
return
|
|
1996
|
+
} else if (c.variant.name == "fidelity") {
|
|
1997
|
+
return c.sourceColor.tone;
|
|
2094
1998
|
} else {
|
|
2095
1999
|
return tMaxC(
|
|
2096
|
-
|
|
2000
|
+
palettes.get("primary"),
|
|
2097
2001
|
0,
|
|
2098
|
-
Hct.isCyan(
|
|
2002
|
+
Hct.isCyan(palettes.get("primary").hue) ? 88 : 98
|
|
2099
2003
|
);
|
|
2100
2004
|
}
|
|
2101
2005
|
},
|
|
2102
2006
|
isBackground: true,
|
|
2103
|
-
background: (
|
|
2104
|
-
contrastCurve: (
|
|
2105
|
-
adjustTone: (
|
|
2106
|
-
const surfaceTone =
|
|
2107
|
-
const primaryTone =
|
|
2007
|
+
background: () => highestSurface(c, colors),
|
|
2008
|
+
contrastCurve: () => getCurve(4.5),
|
|
2009
|
+
adjustTone: () => c.variant.name == "fidelity" ? () => {
|
|
2010
|
+
const surfaceTone = colors.get("surface").getTone();
|
|
2011
|
+
const primaryTone = colors.get("primary").options.tone;
|
|
2108
2012
|
let selfTone = primaryTone;
|
|
2109
2013
|
if (Contrast.ratioOfTones(surfaceTone, selfTone) < 3) {
|
|
2110
|
-
const
|
|
2111
|
-
|
|
2112
|
-
selfTone
|
|
2113
|
-
|
|
2014
|
+
const ratio = calculateToneAdjustmentPercentage(
|
|
2015
|
+
surfaceTone,
|
|
2016
|
+
selfTone,
|
|
2017
|
+
3
|
|
2018
|
+
);
|
|
2019
|
+
const inverseT = inverseTone(primaryTone);
|
|
2020
|
+
selfTone = selfTone + (inverseT - selfTone) * ratio;
|
|
2114
2021
|
}
|
|
2115
2022
|
return selfTone;
|
|
2116
2023
|
} : toneDeltaPair(
|
|
2117
|
-
|
|
2118
|
-
|
|
2024
|
+
colors.get("primaryContainer"),
|
|
2025
|
+
colors.get("primary"),
|
|
2119
2026
|
5,
|
|
2120
2027
|
"relative_lighter",
|
|
2121
2028
|
true,
|
|
@@ -2123,22 +2030,22 @@ const defaultColors = (colorService) => {
|
|
|
2123
2030
|
)
|
|
2124
2031
|
},
|
|
2125
2032
|
primaryDim: {
|
|
2126
|
-
palette: (
|
|
2127
|
-
tone: (
|
|
2128
|
-
if (
|
|
2033
|
+
palette: () => palettes.get("primary"),
|
|
2034
|
+
tone: () => {
|
|
2035
|
+
if (c.variant.name === "neutral") {
|
|
2129
2036
|
return 85;
|
|
2130
|
-
} else if (
|
|
2131
|
-
return tMaxC(
|
|
2037
|
+
} else if (c.variant.name === "tonalSpot") {
|
|
2038
|
+
return tMaxC(palettes.get("primary"), 0, 90);
|
|
2132
2039
|
} else {
|
|
2133
|
-
return tMaxC(
|
|
2040
|
+
return tMaxC(palettes.get("primary"));
|
|
2134
2041
|
}
|
|
2135
2042
|
},
|
|
2136
2043
|
isBackground: true,
|
|
2137
|
-
background: (
|
|
2138
|
-
contrastCurve: (
|
|
2139
|
-
adjustTone: (
|
|
2140
|
-
|
|
2141
|
-
|
|
2044
|
+
background: () => getColor("surfaceContainerHigh"),
|
|
2045
|
+
contrastCurve: () => getCurve(4.5),
|
|
2046
|
+
adjustTone: () => toneDeltaPair(
|
|
2047
|
+
colors.get("primaryDim"),
|
|
2048
|
+
colors.get("primary"),
|
|
2142
2049
|
5,
|
|
2143
2050
|
"darker",
|
|
2144
2051
|
true,
|
|
@@ -2146,74 +2053,74 @@ const defaultColors = (colorService) => {
|
|
|
2146
2053
|
)
|
|
2147
2054
|
},
|
|
2148
2055
|
onPrimary: {
|
|
2149
|
-
palette: (
|
|
2150
|
-
background: (
|
|
2151
|
-
contrastCurve: (
|
|
2056
|
+
palette: () => palettes.get("primary"),
|
|
2057
|
+
background: () => colors.get("primary"),
|
|
2058
|
+
contrastCurve: () => getCurve(6)
|
|
2152
2059
|
},
|
|
2153
2060
|
primaryContainer: {
|
|
2154
|
-
palette: (
|
|
2155
|
-
tone: (
|
|
2156
|
-
if (
|
|
2157
|
-
return
|
|
2158
|
-
} else if (
|
|
2159
|
-
return
|
|
2160
|
-
} else if (
|
|
2161
|
-
return
|
|
2162
|
-
|
|
2061
|
+
palette: () => palettes.get("primary"),
|
|
2062
|
+
tone: () => {
|
|
2063
|
+
if (c.variant.name === "neutral") {
|
|
2064
|
+
return c.isDark ? 30 : 90;
|
|
2065
|
+
} else if (c.variant.name === "tonalSpot") {
|
|
2066
|
+
return c.isDark ? tMinC(palettes.get("primary"), 35, 93) : tMaxC(palettes.get("primary"), 0, 90);
|
|
2067
|
+
} else if (c.variant.name === "expressive") {
|
|
2068
|
+
return c.isDark ? tMaxC(palettes.get("primary"), 30, 93) : tMaxC(
|
|
2069
|
+
palettes.get("primary"),
|
|
2163
2070
|
78,
|
|
2164
|
-
Hct.isCyan(
|
|
2071
|
+
Hct.isCyan(palettes.get("primary").hue) ? 88 : 90
|
|
2165
2072
|
);
|
|
2166
2073
|
}
|
|
2167
|
-
if (
|
|
2168
|
-
return
|
|
2169
|
-
s.getPalette("primary"),
|
|
2170
|
-
78,
|
|
2171
|
-
Hct.isCyan(s.getPalette("primary").hue) ? 88 : 90
|
|
2172
|
-
);
|
|
2074
|
+
if (c.variant.name == "fidelity") {
|
|
2075
|
+
return c.isDark ? tMinC(palettes.get("primary"), 35, 93) : tMaxC(palettes.get("primary"), 0, 90);
|
|
2173
2076
|
} else {
|
|
2174
|
-
return
|
|
2175
|
-
|
|
2077
|
+
return c.isDark ? tMinC(palettes.get("primary"), 66, 93) : tMaxC(
|
|
2078
|
+
palettes.get("primary"),
|
|
2176
2079
|
66,
|
|
2177
|
-
Hct.isCyan(
|
|
2080
|
+
Hct.isCyan(palettes.get("primary").hue) ? 88 : 93
|
|
2178
2081
|
);
|
|
2179
2082
|
}
|
|
2180
2083
|
},
|
|
2181
2084
|
isBackground: true,
|
|
2182
|
-
background: (
|
|
2183
|
-
adjustTone: (
|
|
2184
|
-
|
|
2185
|
-
|
|
2085
|
+
background: () => highestSurface(c, colors),
|
|
2086
|
+
adjustTone: () => c.variant.name == "fidelity" ? toneDeltaPair(
|
|
2087
|
+
colors.get("primary"),
|
|
2088
|
+
colors.get("primaryContainer"),
|
|
2186
2089
|
15,
|
|
2187
2090
|
"relative_darker",
|
|
2188
2091
|
true,
|
|
2189
2092
|
"farther"
|
|
2190
2093
|
) : void 0,
|
|
2191
|
-
contrastCurve: (
|
|
2094
|
+
contrastCurve: () => c.contrastLevel > 0 ? getCurve(1.5) : void 0
|
|
2192
2095
|
},
|
|
2193
2096
|
onPrimaryContainer: {
|
|
2194
|
-
palette: (
|
|
2195
|
-
background: (
|
|
2196
|
-
contrastCurve: (
|
|
2097
|
+
palette: () => palettes.get("primary"),
|
|
2098
|
+
background: () => colors.get("primaryContainer"),
|
|
2099
|
+
contrastCurve: () => getCurve(6)
|
|
2197
2100
|
},
|
|
2198
2101
|
primaryFixed: {
|
|
2199
|
-
palette: (
|
|
2200
|
-
tone: (
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2102
|
+
palette: () => palettes.get("primary"),
|
|
2103
|
+
tone: () => {
|
|
2104
|
+
return c.temp(
|
|
2105
|
+
{
|
|
2106
|
+
isDark: false,
|
|
2107
|
+
contrastLevel: 0
|
|
2108
|
+
},
|
|
2109
|
+
() => {
|
|
2110
|
+
const color = getColor("primaryContainer");
|
|
2111
|
+
return color.getTone();
|
|
2112
|
+
}
|
|
2113
|
+
);
|
|
2207
2114
|
},
|
|
2208
2115
|
isBackground: true,
|
|
2209
|
-
background: (
|
|
2210
|
-
contrastCurve: (
|
|
2116
|
+
background: () => highestSurface(c, colors),
|
|
2117
|
+
contrastCurve: () => c.contrastLevel > 0 ? getCurve(1.5) : void 0
|
|
2211
2118
|
},
|
|
2212
2119
|
primaryFixedDim: {
|
|
2213
|
-
palette: (
|
|
2214
|
-
tone: (
|
|
2120
|
+
palette: () => palettes.get("primary"),
|
|
2121
|
+
tone: () => colors.get("primaryFixed").getTone(),
|
|
2215
2122
|
isBackground: true,
|
|
2216
|
-
adjustTone: (
|
|
2123
|
+
adjustTone: () => toneDeltaPair(
|
|
2217
2124
|
getColor("primaryFixedDim"),
|
|
2218
2125
|
getColor("primaryFixed"),
|
|
2219
2126
|
5,
|
|
@@ -2223,39 +2130,39 @@ const defaultColors = (colorService) => {
|
|
|
2223
2130
|
)
|
|
2224
2131
|
},
|
|
2225
2132
|
onPrimaryFixed: {
|
|
2226
|
-
palette: (
|
|
2227
|
-
background: (
|
|
2228
|
-
contrastCurve: (
|
|
2133
|
+
palette: () => palettes.get("primary"),
|
|
2134
|
+
background: () => colors.get("primaryFixedDim"),
|
|
2135
|
+
contrastCurve: () => getCurve(7)
|
|
2229
2136
|
},
|
|
2230
2137
|
onPrimaryFixedVariant: {
|
|
2231
|
-
palette: (
|
|
2232
|
-
background: (
|
|
2233
|
-
contrastCurve: (
|
|
2138
|
+
palette: () => palettes.get("primary"),
|
|
2139
|
+
background: () => colors.get("primaryFixedDim"),
|
|
2140
|
+
contrastCurve: () => getCurve(4.5)
|
|
2234
2141
|
},
|
|
2235
2142
|
inversePrimary: {
|
|
2236
|
-
palette: (
|
|
2237
|
-
tone: (
|
|
2238
|
-
background: (
|
|
2239
|
-
contrastCurve: (
|
|
2143
|
+
palette: () => palettes.get("primary"),
|
|
2144
|
+
tone: () => tMaxC(palettes.get("primary")),
|
|
2145
|
+
background: () => colors.get("inverseSurface"),
|
|
2146
|
+
contrastCurve: () => getCurve(6)
|
|
2240
2147
|
},
|
|
2241
2148
|
////////////////////////////////////////////////////////////////
|
|
2242
2149
|
// Secondaries [Q] //
|
|
2243
2150
|
////////////////////////////////////////////////////////////////
|
|
2244
2151
|
secondary: {
|
|
2245
|
-
palette: (
|
|
2246
|
-
tone: (
|
|
2247
|
-
if (
|
|
2248
|
-
return
|
|
2249
|
-
} else if (
|
|
2250
|
-
return tMaxC(
|
|
2152
|
+
palette: () => palettes.get("secondary"),
|
|
2153
|
+
tone: () => {
|
|
2154
|
+
if (c.variant.name === "neutral") {
|
|
2155
|
+
return c.isDark ? tMinC(palettes.get("secondary"), 0, 98) : tMaxC(palettes.get("secondary"));
|
|
2156
|
+
} else if (c.variant.name === "vibrant") {
|
|
2157
|
+
return tMaxC(palettes.get("secondary"), 0, c.isDark ? 90 : 98);
|
|
2251
2158
|
} else {
|
|
2252
|
-
return
|
|
2159
|
+
return c.isDark ? 80 : tMaxC(palettes.get("secondary"));
|
|
2253
2160
|
}
|
|
2254
2161
|
},
|
|
2255
2162
|
isBackground: true,
|
|
2256
|
-
background: (
|
|
2257
|
-
contrastCurve: (
|
|
2258
|
-
adjustTone: (
|
|
2163
|
+
background: () => highestSurface(c, colors),
|
|
2164
|
+
contrastCurve: () => getCurve(4.5),
|
|
2165
|
+
adjustTone: () => toneDeltaPair(
|
|
2259
2166
|
getColor("secondaryContainer"),
|
|
2260
2167
|
getColor("secondary"),
|
|
2261
2168
|
5,
|
|
@@ -2265,18 +2172,18 @@ const defaultColors = (colorService) => {
|
|
|
2265
2172
|
)
|
|
2266
2173
|
},
|
|
2267
2174
|
secondaryDim: {
|
|
2268
|
-
palette: (
|
|
2269
|
-
tone: (
|
|
2270
|
-
if (
|
|
2175
|
+
palette: () => palettes.get("secondary"),
|
|
2176
|
+
tone: () => {
|
|
2177
|
+
if (c.variant.name === "neutral") {
|
|
2271
2178
|
return 85;
|
|
2272
2179
|
} else {
|
|
2273
|
-
return tMaxC(
|
|
2180
|
+
return tMaxC(palettes.get("secondary"), 0, 90);
|
|
2274
2181
|
}
|
|
2275
2182
|
},
|
|
2276
2183
|
isBackground: true,
|
|
2277
|
-
background: (
|
|
2278
|
-
contrastCurve: (
|
|
2279
|
-
adjustTone: (
|
|
2184
|
+
background: () => getColor("surfaceContainerHigh"),
|
|
2185
|
+
contrastCurve: () => getCurve(4.5),
|
|
2186
|
+
adjustTone: () => toneDeltaPair(
|
|
2280
2187
|
getColor("secondaryDim"),
|
|
2281
2188
|
getColor("secondary"),
|
|
2282
2189
|
5,
|
|
@@ -2286,50 +2193,54 @@ const defaultColors = (colorService) => {
|
|
|
2286
2193
|
)
|
|
2287
2194
|
},
|
|
2288
2195
|
onSecondary: {
|
|
2289
|
-
palette: (
|
|
2290
|
-
background: (
|
|
2291
|
-
contrastCurve: (
|
|
2196
|
+
palette: () => palettes.get("secondary"),
|
|
2197
|
+
background: () => getColor("secondary"),
|
|
2198
|
+
contrastCurve: () => getCurve(6)
|
|
2292
2199
|
},
|
|
2293
2200
|
secondaryContainer: {
|
|
2294
|
-
palette: (
|
|
2295
|
-
tone: (
|
|
2296
|
-
if (
|
|
2297
|
-
return
|
|
2298
|
-
} else if (
|
|
2299
|
-
return
|
|
2201
|
+
palette: () => palettes.get("secondary"),
|
|
2202
|
+
tone: () => {
|
|
2203
|
+
if (c.variant.name === "vibrant") {
|
|
2204
|
+
return c.isDark ? tMinC(palettes.get("secondary"), 30, 40) : tMaxC(palettes.get("secondary"), 84, 90);
|
|
2205
|
+
} else if (c.variant.name === "expressive") {
|
|
2206
|
+
return c.isDark ? 15 : tMaxC(palettes.get("secondary"), 90, 95);
|
|
2300
2207
|
} else {
|
|
2301
|
-
return
|
|
2208
|
+
return c.isDark ? 25 : 90;
|
|
2302
2209
|
}
|
|
2303
2210
|
},
|
|
2304
2211
|
isBackground: true,
|
|
2305
|
-
background: (
|
|
2306
|
-
adjustTone: (
|
|
2307
|
-
contrastCurve: (
|
|
2212
|
+
background: () => highestSurface(c, colors),
|
|
2213
|
+
adjustTone: () => void 0,
|
|
2214
|
+
contrastCurve: () => c.contrastLevel > 0 ? getCurve(1.5) : void 0
|
|
2308
2215
|
},
|
|
2309
2216
|
onSecondaryContainer: {
|
|
2310
|
-
palette: (
|
|
2311
|
-
background: (
|
|
2312
|
-
contrastCurve: (
|
|
2217
|
+
palette: () => palettes.get("secondary"),
|
|
2218
|
+
background: () => getColor("secondaryContainer"),
|
|
2219
|
+
contrastCurve: () => getCurve(6)
|
|
2313
2220
|
},
|
|
2314
2221
|
secondaryFixed: {
|
|
2315
|
-
palette: (
|
|
2316
|
-
tone: (
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2222
|
+
palette: () => palettes.get("secondary"),
|
|
2223
|
+
tone: () => {
|
|
2224
|
+
return c.temp(
|
|
2225
|
+
{
|
|
2226
|
+
isDark: false,
|
|
2227
|
+
contrastLevel: 0
|
|
2228
|
+
},
|
|
2229
|
+
() => {
|
|
2230
|
+
const color = getColor("secondaryContainer");
|
|
2231
|
+
return color.getTone();
|
|
2232
|
+
}
|
|
2233
|
+
);
|
|
2323
2234
|
},
|
|
2324
2235
|
isBackground: true,
|
|
2325
|
-
background: (
|
|
2326
|
-
contrastCurve: (
|
|
2236
|
+
background: () => highestSurface(c, colors),
|
|
2237
|
+
contrastCurve: () => c.contrastLevel > 0 ? getCurve(1.5) : void 0
|
|
2327
2238
|
},
|
|
2328
2239
|
secondaryFixedDim: {
|
|
2329
|
-
palette: (
|
|
2330
|
-
tone: (
|
|
2240
|
+
palette: () => palettes.get("secondary"),
|
|
2241
|
+
tone: () => getColor("secondaryFixed").getTone(),
|
|
2331
2242
|
isBackground: true,
|
|
2332
|
-
adjustTone: (
|
|
2243
|
+
adjustTone: () => toneDeltaPair(
|
|
2333
2244
|
getColor("secondaryFixedDim"),
|
|
2334
2245
|
getColor("secondaryFixed"),
|
|
2335
2246
|
5,
|
|
@@ -2339,35 +2250,35 @@ const defaultColors = (colorService) => {
|
|
|
2339
2250
|
)
|
|
2340
2251
|
},
|
|
2341
2252
|
onSecondaryFixed: {
|
|
2342
|
-
palette: (
|
|
2343
|
-
background: (
|
|
2344
|
-
contrastCurve: (
|
|
2253
|
+
palette: () => palettes.get("secondary"),
|
|
2254
|
+
background: () => getColor("secondaryFixedDim"),
|
|
2255
|
+
contrastCurve: () => getCurve(7)
|
|
2345
2256
|
},
|
|
2346
2257
|
onSecondaryFixedVariant: {
|
|
2347
|
-
palette: (
|
|
2348
|
-
background: (
|
|
2349
|
-
contrastCurve: (
|
|
2258
|
+
palette: () => palettes.get("secondary"),
|
|
2259
|
+
background: () => getColor("secondaryFixedDim"),
|
|
2260
|
+
contrastCurve: () => getCurve(4.5)
|
|
2350
2261
|
},
|
|
2351
2262
|
////////////////////////////////////////////////////////////////
|
|
2352
2263
|
// Tertiaries [T] //
|
|
2353
2264
|
////////////////////////////////////////////////////////////////
|
|
2354
2265
|
tertiary: {
|
|
2355
|
-
palette: (
|
|
2356
|
-
tone: (
|
|
2357
|
-
if (
|
|
2266
|
+
palette: () => palettes.get("tertiary"),
|
|
2267
|
+
tone: () => {
|
|
2268
|
+
if (c.variant.name === "expressive" || c.variant.name === "vibrant") {
|
|
2358
2269
|
return tMaxC(
|
|
2359
|
-
|
|
2270
|
+
palettes.get("tertiary"),
|
|
2360
2271
|
0,
|
|
2361
|
-
Hct.isCyan(
|
|
2272
|
+
Hct.isCyan(palettes.get("tertiary").hue) ? 88 : c.isDark ? 98 : 100
|
|
2362
2273
|
);
|
|
2363
2274
|
} else {
|
|
2364
|
-
return
|
|
2275
|
+
return c.isDark ? tMaxC(palettes.get("tertiary"), 0, 98) : tMaxC(palettes.get("tertiary"));
|
|
2365
2276
|
}
|
|
2366
2277
|
},
|
|
2367
2278
|
isBackground: true,
|
|
2368
|
-
background: (
|
|
2369
|
-
contrastCurve: (
|
|
2370
|
-
adjustTone: (
|
|
2279
|
+
background: () => highestSurface(c, colors),
|
|
2280
|
+
contrastCurve: () => getCurve(4.5),
|
|
2281
|
+
adjustTone: () => toneDeltaPair(
|
|
2371
2282
|
getColor("tertiaryContainer"),
|
|
2372
2283
|
getColor("tertiary"),
|
|
2373
2284
|
5,
|
|
@@ -2377,18 +2288,18 @@ const defaultColors = (colorService) => {
|
|
|
2377
2288
|
)
|
|
2378
2289
|
},
|
|
2379
2290
|
tertiaryDim: {
|
|
2380
|
-
palette: (
|
|
2381
|
-
tone: (
|
|
2382
|
-
if (
|
|
2383
|
-
return tMaxC(
|
|
2291
|
+
palette: () => palettes.get("tertiary"),
|
|
2292
|
+
tone: () => {
|
|
2293
|
+
if (c.variant.name === "tonalSpot") {
|
|
2294
|
+
return tMaxC(palettes.get("tertiary"), 0, 90);
|
|
2384
2295
|
} else {
|
|
2385
|
-
return tMaxC(
|
|
2296
|
+
return tMaxC(palettes.get("tertiary"));
|
|
2386
2297
|
}
|
|
2387
2298
|
},
|
|
2388
2299
|
isBackground: true,
|
|
2389
|
-
background: (
|
|
2390
|
-
contrastCurve: (
|
|
2391
|
-
adjustTone: (
|
|
2300
|
+
background: () => getColor("surfaceContainerHigh"),
|
|
2301
|
+
contrastCurve: () => getCurve(4.5),
|
|
2302
|
+
adjustTone: () => toneDeltaPair(
|
|
2392
2303
|
getColor("tertiaryDim"),
|
|
2393
2304
|
getColor("tertiary"),
|
|
2394
2305
|
5,
|
|
@@ -2398,56 +2309,60 @@ const defaultColors = (colorService) => {
|
|
|
2398
2309
|
)
|
|
2399
2310
|
},
|
|
2400
2311
|
onTertiary: {
|
|
2401
|
-
palette: (
|
|
2402
|
-
background: (
|
|
2403
|
-
contrastCurve: (
|
|
2312
|
+
palette: () => palettes.get("tertiary"),
|
|
2313
|
+
background: () => getColor("tertiary"),
|
|
2314
|
+
contrastCurve: () => getCurve(6)
|
|
2404
2315
|
},
|
|
2405
2316
|
tertiaryContainer: {
|
|
2406
|
-
palette: (
|
|
2407
|
-
tone: (
|
|
2408
|
-
if (
|
|
2409
|
-
return
|
|
2410
|
-
} else if (
|
|
2411
|
-
return tMaxC(
|
|
2412
|
-
} else if (
|
|
2317
|
+
palette: () => palettes.get("tertiary"),
|
|
2318
|
+
tone: () => {
|
|
2319
|
+
if (c.variant.name === "neutral") {
|
|
2320
|
+
return c.isDark ? tMaxC(palettes.get("tertiary"), 0, 93) : tMaxC(palettes.get("tertiary"), 0, 96);
|
|
2321
|
+
} else if (c.variant.name === "tonalSpot") {
|
|
2322
|
+
return tMaxC(palettes.get("tertiary"), 0, c.isDark ? 93 : 100);
|
|
2323
|
+
} else if (c.variant.name === "expressive") {
|
|
2413
2324
|
return tMaxC(
|
|
2414
|
-
|
|
2325
|
+
palettes.get("tertiary"),
|
|
2415
2326
|
75,
|
|
2416
|
-
Hct.isCyan(
|
|
2327
|
+
Hct.isCyan(palettes.get("tertiary").hue) ? 88 : c.isDark ? 93 : 100
|
|
2417
2328
|
);
|
|
2418
2329
|
} else {
|
|
2419
|
-
return
|
|
2330
|
+
return c.isDark ? tMaxC(palettes.get("tertiary"), 0, 93) : tMaxC(palettes.get("tertiary"), 72, 100);
|
|
2420
2331
|
}
|
|
2421
2332
|
},
|
|
2422
2333
|
isBackground: true,
|
|
2423
|
-
background: (
|
|
2424
|
-
adjustTone: (
|
|
2425
|
-
contrastCurve: (
|
|
2334
|
+
background: () => highestSurface(c, colors),
|
|
2335
|
+
adjustTone: () => void 0,
|
|
2336
|
+
contrastCurve: () => c.contrastLevel > 0 ? getCurve(1.5) : void 0
|
|
2426
2337
|
},
|
|
2427
2338
|
onTertiaryContainer: {
|
|
2428
|
-
palette: (
|
|
2429
|
-
background: (
|
|
2430
|
-
contrastCurve: (
|
|
2339
|
+
palette: () => palettes.get("tertiary"),
|
|
2340
|
+
background: () => getColor("tertiaryContainer"),
|
|
2341
|
+
contrastCurve: () => getCurve(6)
|
|
2431
2342
|
},
|
|
2432
2343
|
tertiaryFixed: {
|
|
2433
|
-
palette: (
|
|
2434
|
-
tone: (
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2344
|
+
palette: () => palettes.get("tertiary"),
|
|
2345
|
+
tone: () => {
|
|
2346
|
+
return c.temp(
|
|
2347
|
+
{
|
|
2348
|
+
isDark: false,
|
|
2349
|
+
contrastLevel: 0
|
|
2350
|
+
},
|
|
2351
|
+
() => {
|
|
2352
|
+
const color = getColor("tertiaryContainer");
|
|
2353
|
+
return color.getTone();
|
|
2354
|
+
}
|
|
2355
|
+
);
|
|
2441
2356
|
},
|
|
2442
2357
|
isBackground: true,
|
|
2443
|
-
background: (
|
|
2444
|
-
contrastCurve: (
|
|
2358
|
+
background: () => highestSurface(c, colors),
|
|
2359
|
+
contrastCurve: () => c.contrastLevel > 0 ? getCurve(1.5) : void 0
|
|
2445
2360
|
},
|
|
2446
2361
|
tertiaryFixedDim: {
|
|
2447
|
-
palette: (
|
|
2448
|
-
tone: (
|
|
2362
|
+
palette: () => palettes.get("tertiary"),
|
|
2363
|
+
tone: () => getColor("tertiaryFixed").getTone(),
|
|
2449
2364
|
isBackground: true,
|
|
2450
|
-
adjustTone: (
|
|
2365
|
+
adjustTone: () => toneDeltaPair(
|
|
2451
2366
|
getColor("tertiaryFixedDim"),
|
|
2452
2367
|
getColor("tertiaryFixed"),
|
|
2453
2368
|
5,
|
|
@@ -2457,29 +2372,29 @@ const defaultColors = (colorService) => {
|
|
|
2457
2372
|
)
|
|
2458
2373
|
},
|
|
2459
2374
|
onTertiaryFixed: {
|
|
2460
|
-
palette: (
|
|
2461
|
-
background: (
|
|
2462
|
-
contrastCurve: (
|
|
2375
|
+
palette: () => palettes.get("tertiary"),
|
|
2376
|
+
background: () => getColor("tertiaryFixedDim"),
|
|
2377
|
+
contrastCurve: () => getCurve(7)
|
|
2463
2378
|
},
|
|
2464
2379
|
onTertiaryFixedVariant: {
|
|
2465
|
-
palette: (
|
|
2466
|
-
background: (
|
|
2467
|
-
contrastCurve: (
|
|
2380
|
+
palette: () => palettes.get("tertiary"),
|
|
2381
|
+
background: () => getColor("tertiaryFixedDim"),
|
|
2382
|
+
contrastCurve: () => getCurve(4.5)
|
|
2468
2383
|
},
|
|
2469
2384
|
////////////////////////////////////////////////////////////////
|
|
2470
2385
|
// Errors [E] //
|
|
2471
2386
|
////////////////////////////////////////////////////////////////
|
|
2472
2387
|
error: {
|
|
2473
|
-
palette: (
|
|
2474
|
-
tone: (
|
|
2475
|
-
return
|
|
2388
|
+
palette: () => palettes.get("error"),
|
|
2389
|
+
tone: () => {
|
|
2390
|
+
return c.isDark ? tMinC(palettes.get("error"), 0, 98) : tMaxC(palettes.get("error"));
|
|
2476
2391
|
},
|
|
2477
2392
|
isBackground: true,
|
|
2478
|
-
background: (
|
|
2479
|
-
contrastCurve: (
|
|
2480
|
-
adjustTone: (
|
|
2481
|
-
|
|
2482
|
-
|
|
2393
|
+
background: () => highestSurface(c, colors),
|
|
2394
|
+
contrastCurve: () => getCurve(4.5),
|
|
2395
|
+
adjustTone: () => toneDeltaPair(
|
|
2396
|
+
colors.get("errorContainer"),
|
|
2397
|
+
colors.get("error"),
|
|
2483
2398
|
5,
|
|
2484
2399
|
"relative_lighter",
|
|
2485
2400
|
true,
|
|
@@ -2487,12 +2402,12 @@ const defaultColors = (colorService) => {
|
|
|
2487
2402
|
)
|
|
2488
2403
|
},
|
|
2489
2404
|
errorDim: {
|
|
2490
|
-
palette: (
|
|
2491
|
-
tone: (
|
|
2405
|
+
palette: () => palettes.get("error"),
|
|
2406
|
+
tone: () => tMinC(palettes.get("error")),
|
|
2492
2407
|
isBackground: true,
|
|
2493
|
-
background: (
|
|
2494
|
-
contrastCurve: (
|
|
2495
|
-
adjustTone: (
|
|
2408
|
+
background: () => getColor("surfaceContainerHigh"),
|
|
2409
|
+
contrastCurve: () => getCurve(4.5),
|
|
2410
|
+
adjustTone: () => toneDeltaPair(
|
|
2496
2411
|
getColor("errorDim"),
|
|
2497
2412
|
getColor("error"),
|
|
2498
2413
|
5,
|
|
@@ -2502,24 +2417,24 @@ const defaultColors = (colorService) => {
|
|
|
2502
2417
|
)
|
|
2503
2418
|
},
|
|
2504
2419
|
onError: {
|
|
2505
|
-
palette: (
|
|
2506
|
-
background: (
|
|
2507
|
-
contrastCurve: (
|
|
2420
|
+
palette: () => palettes.get("error"),
|
|
2421
|
+
background: () => colors.get("error"),
|
|
2422
|
+
contrastCurve: () => getCurve(6)
|
|
2508
2423
|
},
|
|
2509
2424
|
errorContainer: {
|
|
2510
|
-
palette: (
|
|
2511
|
-
tone: (
|
|
2512
|
-
return
|
|
2425
|
+
palette: () => palettes.get("error"),
|
|
2426
|
+
tone: () => {
|
|
2427
|
+
return c.isDark ? tMinC(palettes.get("error"), 30, 93) : tMaxC(palettes.get("error"), 0, 90);
|
|
2513
2428
|
},
|
|
2514
2429
|
isBackground: true,
|
|
2515
|
-
background: (
|
|
2516
|
-
adjustTone: (
|
|
2517
|
-
contrastCurve: (
|
|
2430
|
+
background: () => highestSurface(c, colors),
|
|
2431
|
+
adjustTone: () => void 0,
|
|
2432
|
+
contrastCurve: () => c.contrastLevel > 0 ? getCurve(1.5) : void 0
|
|
2518
2433
|
},
|
|
2519
2434
|
onErrorContainer: {
|
|
2520
|
-
palette: (
|
|
2521
|
-
background: (
|
|
2522
|
-
contrastCurve: (
|
|
2435
|
+
palette: () => palettes.get("error"),
|
|
2436
|
+
background: () => colors.get("errorContainer"),
|
|
2437
|
+
contrastCurve: () => getCurve(4.5)
|
|
2523
2438
|
},
|
|
2524
2439
|
/////////////////////////////////////////////////////////////////
|
|
2525
2440
|
// Remapped Colors //
|
|
@@ -2537,27 +2452,7 @@ const defaultColors = (colorService) => {
|
|
|
2537
2452
|
alias: "onSurface"
|
|
2538
2453
|
}
|
|
2539
2454
|
};
|
|
2540
|
-
return {
|
|
2541
|
-
colors
|
|
2542
|
-
};
|
|
2543
2455
|
};
|
|
2544
|
-
class API {
|
|
2545
|
-
constructor({
|
|
2546
|
-
colorApi,
|
|
2547
|
-
themeApi,
|
|
2548
|
-
pluginApi
|
|
2549
|
-
}) {
|
|
2550
|
-
__publicField(this, "colors");
|
|
2551
|
-
__publicField(this, "themes");
|
|
2552
|
-
__publicField(this, "plugins");
|
|
2553
|
-
this.plugins = pluginApi;
|
|
2554
|
-
this.colors = colorApi;
|
|
2555
|
-
this.themes = themeApi;
|
|
2556
|
-
}
|
|
2557
|
-
async load() {
|
|
2558
|
-
return this.plugins.loadPlugins();
|
|
2559
|
-
}
|
|
2560
|
-
}
|
|
2561
2456
|
const AppModule = {
|
|
2562
2457
|
api: asClass(API).singleton()
|
|
2563
2458
|
};
|
|
@@ -2604,54 +2499,650 @@ class PluginApi {
|
|
|
2604
2499
|
const PluginModule = {
|
|
2605
2500
|
pluginApi: asClass(PluginApi).singleton()
|
|
2606
2501
|
};
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2502
|
+
class Context {
|
|
2503
|
+
constructor() {
|
|
2504
|
+
__publicField(this, "_options");
|
|
2505
|
+
__publicField(this, "_temOptions", null);
|
|
2506
|
+
__publicField(this, "updateCallbacks", []);
|
|
2507
|
+
this.onUpdate((changed) => {
|
|
2508
|
+
if (changed.includes("variant")) {
|
|
2509
|
+
this.variant.init(this);
|
|
2510
|
+
}
|
|
2611
2511
|
});
|
|
2612
|
-
}
|
|
2613
|
-
|
|
2512
|
+
}
|
|
2513
|
+
/**
|
|
2514
|
+
* Runs the provided callback with a proxied Context and records which Context
|
|
2515
|
+
* properties (getters) were accessed during its execution.
|
|
2516
|
+
*
|
|
2517
|
+
* This helps determine dependencies of the callback on the Context.
|
|
2518
|
+
*
|
|
2519
|
+
* Example usage:
|
|
2520
|
+
* const { result, dependencies } = Context.trackDependencies(ctx, (c) => cb(c));
|
|
2521
|
+
*/
|
|
2522
|
+
static trackDependencies(context, callback) {
|
|
2523
|
+
const dependencies = /* @__PURE__ */ new Set();
|
|
2524
|
+
const isGetterOnContext = (prop) => {
|
|
2525
|
+
if (typeof prop !== "string") return false;
|
|
2526
|
+
const desc = Object.getOwnPropertyDescriptor(Context.prototype, prop);
|
|
2527
|
+
return !!desc && typeof desc.get === "function";
|
|
2528
|
+
};
|
|
2529
|
+
const proxy = new Proxy(context, {
|
|
2530
|
+
get(target, prop, receiver) {
|
|
2531
|
+
if (isGetterOnContext(prop)) {
|
|
2532
|
+
dependencies.add(prop);
|
|
2533
|
+
}
|
|
2534
|
+
return Reflect.get(target, prop, receiver);
|
|
2535
|
+
}
|
|
2536
|
+
});
|
|
2537
|
+
const result = callback(proxy);
|
|
2538
|
+
return { result, dependencies: Array.from(dependencies) };
|
|
2539
|
+
}
|
|
2540
|
+
set(options) {
|
|
2541
|
+
if (this._options) {
|
|
2542
|
+
console.error(this._options);
|
|
2543
|
+
throw new Error("Options already set");
|
|
2544
|
+
}
|
|
2545
|
+
if (typeof options.sourceColor === "string") {
|
|
2546
|
+
options.sourceColor = Hct.fromInt(argbFromHex(options.sourceColor));
|
|
2547
|
+
}
|
|
2548
|
+
const changed = [];
|
|
2549
|
+
for (const key of Object.keys(options)) {
|
|
2550
|
+
changed.push(key);
|
|
2551
|
+
}
|
|
2552
|
+
this._options = options;
|
|
2553
|
+
if (changed.length > 0) {
|
|
2554
|
+
this.updateCallbacks.forEach((callback) => callback(changed));
|
|
2555
|
+
}
|
|
2556
|
+
}
|
|
2557
|
+
update(args) {
|
|
2558
|
+
const options = this._options;
|
|
2559
|
+
if (!options) {
|
|
2560
|
+
throw new Error("Options not found");
|
|
2561
|
+
}
|
|
2562
|
+
if (typeof args.sourceColor === "string") {
|
|
2563
|
+
args.sourceColor = Hct.fromInt(argbFromHex(args.sourceColor));
|
|
2564
|
+
}
|
|
2565
|
+
const changed = [];
|
|
2566
|
+
for (const key of Object.keys(args)) {
|
|
2567
|
+
if (args[key] !== options[key]) {
|
|
2568
|
+
changed.push(key);
|
|
2569
|
+
}
|
|
2570
|
+
}
|
|
2571
|
+
this._options = {
|
|
2572
|
+
...options,
|
|
2573
|
+
...args
|
|
2574
|
+
};
|
|
2575
|
+
if (changed.length > 0) {
|
|
2576
|
+
this.updateCallbacks.forEach((callback) => callback(changed));
|
|
2577
|
+
}
|
|
2578
|
+
}
|
|
2579
|
+
getOptions() {
|
|
2580
|
+
let options;
|
|
2581
|
+
if (this._temOptions) {
|
|
2582
|
+
options = this._temOptions;
|
|
2583
|
+
} else {
|
|
2584
|
+
options = this._options;
|
|
2585
|
+
}
|
|
2586
|
+
if (!options) {
|
|
2587
|
+
throw new Error("Options not found");
|
|
2588
|
+
}
|
|
2589
|
+
return options;
|
|
2590
|
+
}
|
|
2591
|
+
set darkMode(isDark) {
|
|
2592
|
+
this.update({ isDark });
|
|
2593
|
+
}
|
|
2594
|
+
get isDark() {
|
|
2595
|
+
return this.getOptions().isDark;
|
|
2596
|
+
}
|
|
2597
|
+
set contrastLevel(contrastLevel) {
|
|
2598
|
+
this.update({ contrastLevel });
|
|
2599
|
+
}
|
|
2600
|
+
get contrastLevel() {
|
|
2601
|
+
return this.getOptions().contrastLevel;
|
|
2602
|
+
}
|
|
2603
|
+
set sourceColor(sourceColor) {
|
|
2604
|
+
this.update({ sourceColor });
|
|
2605
|
+
}
|
|
2606
|
+
get sourceColor() {
|
|
2607
|
+
let sourceColor = this.getOptions().sourceColor;
|
|
2608
|
+
if (typeof sourceColor === "string") {
|
|
2609
|
+
sourceColor = Hct.fromInt(argbFromHex(sourceColor));
|
|
2610
|
+
}
|
|
2611
|
+
return sourceColor;
|
|
2612
|
+
}
|
|
2613
|
+
set variant(variant2) {
|
|
2614
|
+
this.update({ variant: variant2 });
|
|
2615
|
+
}
|
|
2616
|
+
get variant() {
|
|
2617
|
+
return this.getOptions().variant;
|
|
2618
|
+
}
|
|
2619
|
+
temp(args, callback) {
|
|
2620
|
+
const previousOptions = this.getOptions();
|
|
2621
|
+
this._temOptions = {
|
|
2622
|
+
...previousOptions,
|
|
2623
|
+
...args
|
|
2624
|
+
};
|
|
2625
|
+
const result = callback();
|
|
2626
|
+
this._temOptions = null;
|
|
2627
|
+
return result;
|
|
2628
|
+
}
|
|
2629
|
+
onUpdate(callback) {
|
|
2630
|
+
this.updateCallbacks.push(callback);
|
|
2631
|
+
}
|
|
2614
2632
|
}
|
|
2615
|
-
const
|
|
2616
|
-
|
|
2617
|
-
}
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2633
|
+
const ContextModule = {
|
|
2634
|
+
context: asClass(Context).singleton()
|
|
2635
|
+
};
|
|
2636
|
+
class Palette {
|
|
2637
|
+
constructor(name, callback, context) {
|
|
2638
|
+
__publicField(this, "cache", /* @__PURE__ */ new Map());
|
|
2639
|
+
__publicField(this, "hueCache", null);
|
|
2640
|
+
__publicField(this, "chromaCache", null);
|
|
2641
|
+
__publicField(this, "dependencies", null);
|
|
2642
|
+
this.name = name;
|
|
2643
|
+
this.callback = callback;
|
|
2644
|
+
this.context = context;
|
|
2645
|
+
this.update([]);
|
|
2646
|
+
}
|
|
2647
|
+
static fromVariant(name, color, ctx) {
|
|
2648
|
+
const callback = (context) => {
|
|
2649
|
+
return context.variant.customPalettes(context, color);
|
|
2650
|
+
};
|
|
2651
|
+
return new Palette(name, callback, ctx);
|
|
2652
|
+
}
|
|
2653
|
+
update(change) {
|
|
2654
|
+
let result = null;
|
|
2655
|
+
if (this.dependencies == null) {
|
|
2656
|
+
const trackDependencies = Context.trackDependencies(
|
|
2657
|
+
this.context,
|
|
2658
|
+
(ctx) => this.callback(ctx)
|
|
2659
|
+
);
|
|
2660
|
+
this.dependencies = trackDependencies.dependencies;
|
|
2661
|
+
result = trackDependencies.result;
|
|
2662
|
+
} else if (change.length > 0 && change.some((c) => {
|
|
2663
|
+
var _a;
|
|
2664
|
+
return (_a = this.dependencies) == null ? void 0 : _a.includes(c);
|
|
2665
|
+
})) {
|
|
2666
|
+
result = this.callback(this.context);
|
|
2667
|
+
}
|
|
2668
|
+
if (result && this.hueCache !== result.hue && this.chromaCache !== result.chroma) {
|
|
2669
|
+
this.clearCache();
|
|
2670
|
+
this.hueCache = result.hue;
|
|
2671
|
+
this.chromaCache = result.chroma;
|
|
2672
|
+
}
|
|
2673
|
+
}
|
|
2674
|
+
clearCache() {
|
|
2675
|
+
this.cache.clear();
|
|
2676
|
+
this.hueCache = null;
|
|
2677
|
+
this.chromaCache = null;
|
|
2678
|
+
}
|
|
2679
|
+
/**
|
|
2680
|
+
* @param tone HCT tone, measured from 0 to 100.
|
|
2681
|
+
* @return ARGB representation of a color with that tone.
|
|
2682
|
+
*/
|
|
2683
|
+
tone(tone) {
|
|
2684
|
+
const hue = this.hueCache;
|
|
2685
|
+
const chroma = this.chromaCache;
|
|
2686
|
+
if (hue == null || chroma == null)
|
|
2687
|
+
throw new Error("Palette must be updated before using tone");
|
|
2688
|
+
let argb = this.cache.get(tone);
|
|
2689
|
+
if (argb === void 0) {
|
|
2690
|
+
if (tone == 99 && Hct.isYellow(hue)) {
|
|
2691
|
+
argb = this.averageArgb(this.tone(98), this.tone(100));
|
|
2692
|
+
} else {
|
|
2693
|
+
argb = Hct.from(hue, chroma, tone).toInt();
|
|
2694
|
+
}
|
|
2695
|
+
this.cache.set(tone, argb);
|
|
2696
|
+
}
|
|
2697
|
+
return argb;
|
|
2698
|
+
}
|
|
2699
|
+
/**
|
|
2700
|
+
* @param tone HCT tone.
|
|
2701
|
+
* @return HCT representation of a color with that tone.
|
|
2702
|
+
*/
|
|
2703
|
+
getHct(tone) {
|
|
2704
|
+
return Hct.fromInt(this.tone(tone));
|
|
2705
|
+
}
|
|
2706
|
+
get hue() {
|
|
2707
|
+
const hue = this.hueCache;
|
|
2708
|
+
if (hue == null) {
|
|
2709
|
+
throw new Error(`Palette ${this.name} must be updated before using hue`);
|
|
2710
|
+
}
|
|
2711
|
+
return hue;
|
|
2712
|
+
}
|
|
2713
|
+
get chroma() {
|
|
2714
|
+
const chroma = this.chromaCache;
|
|
2715
|
+
if (chroma == null) {
|
|
2716
|
+
throw new Error(`Palette ${this.name} must be updated before using hue`);
|
|
2717
|
+
}
|
|
2718
|
+
return chroma;
|
|
2719
|
+
}
|
|
2720
|
+
averageArgb(argb1, argb2) {
|
|
2721
|
+
const red1 = argb1 >>> 16 & 255;
|
|
2722
|
+
const green1 = argb1 >>> 8 & 255;
|
|
2723
|
+
const blue1 = argb1 & 255;
|
|
2724
|
+
const red2 = argb2 >>> 16 & 255;
|
|
2725
|
+
const green2 = argb2 >>> 8 & 255;
|
|
2726
|
+
const blue2 = argb2 & 255;
|
|
2727
|
+
const red = Math.round((red1 + red2) / 2);
|
|
2728
|
+
const green = Math.round((green1 + green2) / 2);
|
|
2729
|
+
const blue = Math.round((blue1 + blue2) / 2);
|
|
2730
|
+
return (255 << 24 | (red & 255) << 16 | (green & 255) << 8 | blue & 255) >>> 0;
|
|
2731
|
+
}
|
|
2621
2732
|
}
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2733
|
+
class PaletteApi {
|
|
2734
|
+
constructor({ paletteManager }) {
|
|
2735
|
+
__publicField(this, "paletteManager");
|
|
2736
|
+
this.paletteManager = paletteManager;
|
|
2737
|
+
}
|
|
2738
|
+
add(args) {
|
|
2739
|
+
Object.entries(args).forEach(([key, callback]) => {
|
|
2740
|
+
if (typeof callback === "string") {
|
|
2741
|
+
this.paletteManager.addCustomPalette(
|
|
2742
|
+
key,
|
|
2743
|
+
Hct.fromInt(argbFromHex(callback))
|
|
2744
|
+
);
|
|
2745
|
+
} else {
|
|
2746
|
+
this.paletteManager.add(key, callback);
|
|
2747
|
+
}
|
|
2748
|
+
});
|
|
2749
|
+
}
|
|
2750
|
+
get(key) {
|
|
2751
|
+
return this.paletteManager.get(key);
|
|
2752
|
+
}
|
|
2753
|
+
getAll() {
|
|
2754
|
+
return this.paletteManager.palettes;
|
|
2755
|
+
}
|
|
2756
|
+
}
|
|
2757
|
+
class PaletteManager {
|
|
2758
|
+
constructor(args) {
|
|
2759
|
+
__publicField(this, "_palettes", {});
|
|
2760
|
+
__publicField(this, "context");
|
|
2761
|
+
__publicField(this, "colorApi");
|
|
2762
|
+
this.colorApi = args.colorApi;
|
|
2763
|
+
this.context = args.context;
|
|
2764
|
+
this.context.onUpdate(
|
|
2765
|
+
(changed) => Object.entries(this.palettes).forEach(([key, value]) => {
|
|
2766
|
+
value.update(changed);
|
|
2767
|
+
})
|
|
2768
|
+
);
|
|
2769
|
+
}
|
|
2770
|
+
get palettes() {
|
|
2771
|
+
return {
|
|
2772
|
+
...this.context.variant.palettes,
|
|
2773
|
+
...this._palettes
|
|
2774
|
+
};
|
|
2775
|
+
}
|
|
2776
|
+
addCustomPalette(key, color) {
|
|
2777
|
+
const palette = Palette.fromVariant(key, color, this.context);
|
|
2778
|
+
this.add(key, palette);
|
|
2779
|
+
this.colorApi.addFromCustomPalette(key);
|
|
2780
|
+
}
|
|
2781
|
+
add(key, palette) {
|
|
2782
|
+
if (this._palettes["key"]) {
|
|
2783
|
+
throw new Error(`Palette with key ${key} already exists`);
|
|
2784
|
+
}
|
|
2785
|
+
if (!(palette instanceof Palette))
|
|
2786
|
+
palette = new Palette(key, palette, this.context);
|
|
2787
|
+
this.set(key, palette);
|
|
2788
|
+
}
|
|
2789
|
+
get(key) {
|
|
2790
|
+
const palette = this.palettes[key];
|
|
2791
|
+
if (!palette) {
|
|
2792
|
+
throw new Error(`Palette ${key} not found`);
|
|
2793
|
+
}
|
|
2794
|
+
return palette;
|
|
2795
|
+
}
|
|
2796
|
+
set(key, palette) {
|
|
2797
|
+
this._palettes[key] = palette;
|
|
2798
|
+
}
|
|
2799
|
+
update(key, args) {
|
|
2800
|
+
if (!this.palettes["key"]) {
|
|
2801
|
+
throw new Error(`Palette with key ${key} not found`);
|
|
2802
|
+
}
|
|
2803
|
+
if (!(args instanceof Palette)) {
|
|
2804
|
+
args = new Palette(key, args, this.context);
|
|
2805
|
+
}
|
|
2806
|
+
this.set(key, args);
|
|
2807
|
+
}
|
|
2808
|
+
}
|
|
2809
|
+
const PaletteModule = {
|
|
2810
|
+
paletteApi: asClass(PaletteApi).singleton(),
|
|
2811
|
+
paletteManager: asClass(PaletteManager).singleton()
|
|
2812
|
+
};
|
|
2813
|
+
const AppContainer = () => {
|
|
2814
|
+
function registerModule(...modules) {
|
|
2815
|
+
modules.forEach((module) => {
|
|
2816
|
+
Object.entries(module).forEach(([name, moduleClass]) => {
|
|
2817
|
+
container.register(name, moduleClass);
|
|
2818
|
+
});
|
|
2819
|
+
});
|
|
2820
|
+
return AppContainer;
|
|
2821
|
+
}
|
|
2822
|
+
const container = createContainer({
|
|
2823
|
+
injectionMode: InjectionMode.PROXY
|
|
2626
2824
|
});
|
|
2627
|
-
|
|
2825
|
+
registerModule(
|
|
2826
|
+
AppModule,
|
|
2827
|
+
PluginModule,
|
|
2828
|
+
ColorModule,
|
|
2829
|
+
PaletteModule,
|
|
2830
|
+
ContextModule
|
|
2831
|
+
);
|
|
2832
|
+
return container;
|
|
2833
|
+
};
|
|
2834
|
+
function bootstrap() {
|
|
2835
|
+
return AppContainer().resolve("api");
|
|
2836
|
+
}
|
|
2837
|
+
const getPiecewiseHue = (sourceColor, hueBreakpoints, hues) => {
|
|
2838
|
+
const size = Math.min(hueBreakpoints.length - 1, hues.length);
|
|
2839
|
+
const sourceHue = sourceColor.hue;
|
|
2840
|
+
for (let i = 0; i < size; i++) {
|
|
2841
|
+
if (sourceHue >= hueBreakpoints[i] && sourceHue < hueBreakpoints[i + 1]) {
|
|
2842
|
+
return sanitizeDegreesDouble(hues[i]);
|
|
2843
|
+
}
|
|
2844
|
+
}
|
|
2845
|
+
return sourceHue;
|
|
2846
|
+
};
|
|
2847
|
+
const getRotatedHue = (sourceColor, hueBreakpoints, rotations) => {
|
|
2848
|
+
let rotation = getPiecewiseHue(sourceColor, hueBreakpoints, rotations);
|
|
2849
|
+
if (Math.min(hueBreakpoints.length - 1, rotations.length) <= 0) {
|
|
2850
|
+
rotation = 0;
|
|
2851
|
+
}
|
|
2852
|
+
return sanitizeDegreesDouble(sourceColor.hue + rotation);
|
|
2853
|
+
};
|
|
2854
|
+
class Variant {
|
|
2855
|
+
constructor(options) {
|
|
2856
|
+
__publicField(this, "_palettes");
|
|
2857
|
+
__publicField(this, "customPalettes");
|
|
2858
|
+
__publicField(this, "colors");
|
|
2859
|
+
__publicField(this, "name");
|
|
2860
|
+
__publicField(this, "context");
|
|
2861
|
+
this.options = options;
|
|
2862
|
+
this.customPalettes = options.customPalettes;
|
|
2863
|
+
this.colors = options.colors || {};
|
|
2864
|
+
this.name = options.name;
|
|
2865
|
+
}
|
|
2866
|
+
get palettes() {
|
|
2867
|
+
if (!this._palettes) {
|
|
2868
|
+
throw new Error("Variant not initialized");
|
|
2869
|
+
}
|
|
2870
|
+
return this._palettes;
|
|
2871
|
+
}
|
|
2872
|
+
init(context) {
|
|
2873
|
+
if (this.context) return;
|
|
2874
|
+
this.context = context;
|
|
2875
|
+
this._palettes = Object.entries(this.options.palettes).reduce(
|
|
2876
|
+
(acc, [key, callback]) => ({
|
|
2877
|
+
...acc,
|
|
2878
|
+
[key]: new Palette(key, callback, context)
|
|
2879
|
+
}),
|
|
2880
|
+
{}
|
|
2881
|
+
);
|
|
2882
|
+
}
|
|
2883
|
+
}
|
|
2884
|
+
const variant = (args) => new Variant(args);
|
|
2885
|
+
const getExpressiveNeutralHue = (sourceColor) => {
|
|
2886
|
+
const hue = getRotatedHue(
|
|
2887
|
+
sourceColor,
|
|
2888
|
+
[0, 71, 124, 253, 278, 300, 360],
|
|
2889
|
+
[10, 0, 10, 0, 10, 0]
|
|
2890
|
+
);
|
|
2891
|
+
return hue;
|
|
2892
|
+
};
|
|
2893
|
+
const getExpressiveNeutralChroma = (sourceColor, isDark) => {
|
|
2894
|
+
const neutralHue = getExpressiveNeutralHue(sourceColor);
|
|
2895
|
+
return isDark ? Hct.isYellow(neutralHue) ? 6 : 14 : 18;
|
|
2896
|
+
};
|
|
2897
|
+
const expressiveVariant = variant({
|
|
2898
|
+
name: "expressive",
|
|
2899
|
+
palettes: {
|
|
2900
|
+
primary: ({ sourceColor, isDark }) => ({
|
|
2901
|
+
hue: sourceColor.hue,
|
|
2902
|
+
chroma: isDark ? 36 : 48
|
|
2903
|
+
}),
|
|
2904
|
+
secondary: ({ sourceColor, isDark }) => ({
|
|
2905
|
+
hue: getRotatedHue(
|
|
2906
|
+
sourceColor,
|
|
2907
|
+
[0, 105, 140, 204, 253, 278, 300, 333, 360],
|
|
2908
|
+
[-160, 155, -100, 96, -96, -156, -165, -160]
|
|
2909
|
+
),
|
|
2910
|
+
chroma: isDark ? 16 : 24
|
|
2911
|
+
}),
|
|
2912
|
+
tertiary: ({ sourceColor }) => TonalPalette.fromHueAndChroma(
|
|
2913
|
+
getRotatedHue(
|
|
2914
|
+
sourceColor,
|
|
2915
|
+
[0, 105, 140, 204, 253, 278, 300, 333, 360],
|
|
2916
|
+
[-165, 160, -105, 101, -101, -160, -170, -165]
|
|
2917
|
+
),
|
|
2918
|
+
48
|
|
2919
|
+
),
|
|
2920
|
+
neutral: ({ sourceColor, isDark }) => TonalPalette.fromHueAndChroma(
|
|
2921
|
+
getExpressiveNeutralHue(sourceColor),
|
|
2922
|
+
getExpressiveNeutralChroma(sourceColor, isDark)
|
|
2923
|
+
),
|
|
2924
|
+
neutralVariant: ({ sourceColor, isDark }) => {
|
|
2925
|
+
const expressiveNeutralHue = getExpressiveNeutralHue(sourceColor);
|
|
2926
|
+
const expressiveNeutralChroma = getExpressiveNeutralChroma(
|
|
2927
|
+
sourceColor,
|
|
2928
|
+
isDark
|
|
2929
|
+
);
|
|
2930
|
+
return TonalPalette.fromHueAndChroma(
|
|
2931
|
+
expressiveNeutralHue,
|
|
2932
|
+
expressiveNeutralChroma * (expressiveNeutralHue >= 105 && expressiveNeutralHue < 125 ? 1.6 : 2.3)
|
|
2933
|
+
);
|
|
2934
|
+
},
|
|
2935
|
+
error: ({ sourceColor }) => {
|
|
2936
|
+
const errorHue = getPiecewiseHue(
|
|
2937
|
+
sourceColor,
|
|
2938
|
+
[0, 3, 13, 23, 33, 43, 153, 273, 360],
|
|
2939
|
+
[12, 22, 32, 12, 22, 32, 22, 12]
|
|
2940
|
+
);
|
|
2941
|
+
return TonalPalette.fromHueAndChroma(errorHue, 64);
|
|
2942
|
+
}
|
|
2943
|
+
},
|
|
2944
|
+
customPalettes: ({ isDark }, color) => TonalPalette.fromHueAndChroma(
|
|
2945
|
+
getRotatedHue(
|
|
2946
|
+
color,
|
|
2947
|
+
[0, 105, 140, 204, 253, 278, 300, 333, 360],
|
|
2948
|
+
[-160, 155, -100, 96, -96, -156, -165, -160]
|
|
2949
|
+
),
|
|
2950
|
+
isDark ? 16 : 24
|
|
2951
|
+
)
|
|
2952
|
+
});
|
|
2953
|
+
const neutralVariant = variant({
|
|
2954
|
+
name: "neutral",
|
|
2955
|
+
palettes: {
|
|
2956
|
+
primary: ({ sourceColor }) => TonalPalette.fromHueAndChroma(
|
|
2957
|
+
sourceColor.hue,
|
|
2958
|
+
Hct.isBlue(sourceColor.hue) ? 12 : 8
|
|
2959
|
+
),
|
|
2960
|
+
secondary: ({ sourceColor }) => TonalPalette.fromHueAndChroma(
|
|
2961
|
+
sourceColor.hue,
|
|
2962
|
+
Hct.isBlue(sourceColor.hue) ? 6 : 4
|
|
2963
|
+
),
|
|
2964
|
+
tertiary: ({ sourceColor }) => TonalPalette.fromHueAndChroma(
|
|
2965
|
+
getRotatedHue(
|
|
2966
|
+
sourceColor,
|
|
2967
|
+
[0, 38, 105, 161, 204, 278, 333, 360],
|
|
2968
|
+
[-32, 26, 10, -39, 24, -15, -32]
|
|
2969
|
+
),
|
|
2970
|
+
20
|
|
2971
|
+
),
|
|
2972
|
+
neutral: ({ sourceColor }) => TonalPalette.fromHueAndChroma(sourceColor.hue, 1.4),
|
|
2973
|
+
neutralVariant: ({ sourceColor }) => TonalPalette.fromHueAndChroma(sourceColor.hue, 1.4 * 2.2),
|
|
2974
|
+
error: ({ sourceColor }) => {
|
|
2975
|
+
const errorHue = getPiecewiseHue(
|
|
2976
|
+
sourceColor,
|
|
2977
|
+
[0, 3, 13, 23, 33, 43, 153, 273, 360],
|
|
2978
|
+
[12, 22, 32, 12, 22, 32, 22, 12]
|
|
2979
|
+
);
|
|
2980
|
+
return TonalPalette.fromHueAndChroma(errorHue, 50);
|
|
2981
|
+
}
|
|
2982
|
+
},
|
|
2983
|
+
customPalettes: (_, colorHct) => TonalPalette.fromHueAndChroma(
|
|
2984
|
+
colorHct.hue,
|
|
2985
|
+
Hct.isBlue(colorHct.hue) ? 6 : 4
|
|
2986
|
+
)
|
|
2987
|
+
});
|
|
2988
|
+
const tonalSpotVariant = variant({
|
|
2989
|
+
name: "tonalSpot",
|
|
2990
|
+
palettes: {
|
|
2991
|
+
primary: ({ sourceColor, isDark }) => TonalPalette.fromHueAndChroma(sourceColor.hue, isDark ? 26 : 32),
|
|
2992
|
+
secondary: ({ sourceColor }) => TonalPalette.fromHueAndChroma(sourceColor.hue, 16),
|
|
2993
|
+
tertiary: ({ sourceColor }) => TonalPalette.fromHueAndChroma(
|
|
2994
|
+
getRotatedHue(
|
|
2995
|
+
sourceColor,
|
|
2996
|
+
[0, 20, 71, 161, 333, 360],
|
|
2997
|
+
[-40, 48, -32, 40, -32]
|
|
2998
|
+
),
|
|
2999
|
+
28
|
|
3000
|
+
),
|
|
3001
|
+
neutral: ({ sourceColor }) => TonalPalette.fromHueAndChroma(sourceColor.hue, 5),
|
|
3002
|
+
neutralVariant: ({ sourceColor }) => TonalPalette.fromHueAndChroma(sourceColor.hue, 5 * 1.7),
|
|
3003
|
+
error: ({ sourceColor }) => {
|
|
3004
|
+
const errorHue = getPiecewiseHue(
|
|
3005
|
+
sourceColor,
|
|
3006
|
+
[0, 3, 13, 23, 33, 43, 153, 273, 360],
|
|
3007
|
+
[12, 22, 32, 12, 22, 32, 22, 12]
|
|
3008
|
+
);
|
|
3009
|
+
return TonalPalette.fromHueAndChroma(errorHue, 60);
|
|
3010
|
+
}
|
|
3011
|
+
},
|
|
3012
|
+
customPalettes: (_, colorHct) => TonalPalette.fromHueAndChroma(colorHct.hue, 16)
|
|
3013
|
+
});
|
|
3014
|
+
const getVibrantNeutralHue = (sourceColor) => {
|
|
3015
|
+
return getRotatedHue(
|
|
3016
|
+
sourceColor,
|
|
3017
|
+
[0, 38, 105, 140, 333, 360],
|
|
3018
|
+
[-14, 10, -14, 10, -14]
|
|
3019
|
+
);
|
|
2628
3020
|
};
|
|
2629
|
-
const
|
|
2630
|
-
|
|
3021
|
+
const getVibrantNeutralChroma = (sourceColor) => {
|
|
3022
|
+
return 28;
|
|
3023
|
+
};
|
|
3024
|
+
const vibrantVariant = variant({
|
|
3025
|
+
name: "vibrant",
|
|
3026
|
+
palettes: {
|
|
3027
|
+
primary: ({ sourceColor }) => TonalPalette.fromHueAndChroma(sourceColor.hue, 74),
|
|
3028
|
+
secondary: ({ sourceColor }) => TonalPalette.fromHueAndChroma(
|
|
3029
|
+
getRotatedHue(
|
|
3030
|
+
sourceColor,
|
|
3031
|
+
[0, 38, 105, 140, 333, 360],
|
|
3032
|
+
[-14, 10, -14, 10, -14]
|
|
3033
|
+
),
|
|
3034
|
+
56
|
|
3035
|
+
),
|
|
3036
|
+
tertiary: ({ sourceColor }) => TonalPalette.fromHueAndChroma(
|
|
3037
|
+
getRotatedHue(
|
|
3038
|
+
sourceColor,
|
|
3039
|
+
[0, 38, 71, 105, 140, 161, 253, 333, 360],
|
|
3040
|
+
[-72, 35, 24, -24, 62, 50, 62, -72]
|
|
3041
|
+
),
|
|
3042
|
+
56
|
|
3043
|
+
),
|
|
3044
|
+
neutral: ({ sourceColor }) => TonalPalette.fromHueAndChroma(
|
|
3045
|
+
getVibrantNeutralHue(sourceColor),
|
|
3046
|
+
getVibrantNeutralChroma()
|
|
3047
|
+
),
|
|
3048
|
+
neutralVariant: ({ sourceColor }) => {
|
|
3049
|
+
const vibrantNeutralHue = getVibrantNeutralHue(sourceColor);
|
|
3050
|
+
const vibrantNeutralChroma = getVibrantNeutralChroma();
|
|
3051
|
+
return TonalPalette.fromHueAndChroma(
|
|
3052
|
+
vibrantNeutralHue,
|
|
3053
|
+
vibrantNeutralChroma * 1.29
|
|
3054
|
+
);
|
|
3055
|
+
},
|
|
3056
|
+
error: ({ sourceColor }) => {
|
|
3057
|
+
const errorHue = getPiecewiseHue(
|
|
3058
|
+
sourceColor,
|
|
3059
|
+
[0, 3, 13, 23, 33, 43, 153, 273, 360],
|
|
3060
|
+
[12, 22, 32, 12, 22, 32, 22, 12]
|
|
3061
|
+
);
|
|
3062
|
+
return TonalPalette.fromHueAndChroma(errorHue, 80);
|
|
3063
|
+
}
|
|
3064
|
+
},
|
|
3065
|
+
customPalettes: (_, colorHct) => TonalPalette.fromHueAndChroma(
|
|
3066
|
+
getRotatedHue(
|
|
3067
|
+
colorHct,
|
|
3068
|
+
[0, 38, 105, 140, 333, 360],
|
|
3069
|
+
[-14, 10, -14, 10, -14]
|
|
3070
|
+
),
|
|
3071
|
+
56
|
|
3072
|
+
)
|
|
3073
|
+
});
|
|
3074
|
+
const fidelityVariant = variant({
|
|
3075
|
+
name: "fidelity",
|
|
3076
|
+
palettes: {
|
|
3077
|
+
primary: ({ sourceColor }) => ({
|
|
3078
|
+
hue: sourceColor.hue,
|
|
3079
|
+
chroma: sourceColor.chroma
|
|
3080
|
+
}),
|
|
3081
|
+
secondary: ({ sourceColor }) => ({
|
|
3082
|
+
hue: sourceColor.hue,
|
|
3083
|
+
chroma: sourceColor.chroma / 1.4
|
|
3084
|
+
}),
|
|
3085
|
+
tertiary: ({ sourceColor }) => ({
|
|
3086
|
+
hue: getRotatedHue(
|
|
3087
|
+
sourceColor,
|
|
3088
|
+
[0, 20, 71, 161, 333, 360],
|
|
3089
|
+
[-40, 48, -32, 40, -32]
|
|
3090
|
+
),
|
|
3091
|
+
chroma: sourceColor.chroma
|
|
3092
|
+
}),
|
|
3093
|
+
neutral: ({ sourceColor }) => ({
|
|
3094
|
+
hue: sourceColor.hue,
|
|
3095
|
+
chroma: 5
|
|
3096
|
+
}),
|
|
3097
|
+
neutralVariant: ({ sourceColor }) => ({
|
|
3098
|
+
hue: sourceColor.hue,
|
|
3099
|
+
chroma: 5 * 1.7
|
|
3100
|
+
}),
|
|
3101
|
+
error: ({ sourceColor }) => {
|
|
3102
|
+
const errorHue = getPiecewiseHue(
|
|
3103
|
+
sourceColor,
|
|
3104
|
+
[0, 3, 13, 23, 33, 43, 153, 273, 360],
|
|
3105
|
+
[12, 22, 32, 12, 22, 32, 22, 12]
|
|
3106
|
+
);
|
|
3107
|
+
return {
|
|
3108
|
+
hue: errorHue,
|
|
3109
|
+
chroma: 60
|
|
3110
|
+
};
|
|
3111
|
+
}
|
|
3112
|
+
},
|
|
3113
|
+
customPalettes: ({ sourceColor }, colorHct) => ({
|
|
3114
|
+
hue: colorHct.hue,
|
|
3115
|
+
chroma: sourceColor.chroma
|
|
3116
|
+
})
|
|
3117
|
+
});
|
|
3118
|
+
const Variants = {
|
|
3119
|
+
Expressive: expressiveVariant,
|
|
3120
|
+
Neutral: neutralVariant,
|
|
3121
|
+
TonalSpot: tonalSpotVariant,
|
|
3122
|
+
Vibrant: vibrantVariant,
|
|
3123
|
+
Fidelity: fidelityVariant
|
|
3124
|
+
};
|
|
3125
|
+
const loader = async (config, load = true) => {
|
|
3126
|
+
const api = bootstrap();
|
|
2631
3127
|
const init = () => {
|
|
2632
3128
|
const {
|
|
2633
3129
|
sourceColor,
|
|
2634
3130
|
contrastLevel = 0,
|
|
2635
3131
|
isDark = false,
|
|
2636
|
-
variant =
|
|
3132
|
+
variant: variant2 = Variants.TonalSpot,
|
|
2637
3133
|
palettes,
|
|
2638
3134
|
colors,
|
|
2639
|
-
useDefaultColors = true,
|
|
2640
3135
|
plugins
|
|
2641
3136
|
} = config;
|
|
2642
|
-
api.
|
|
3137
|
+
api.context.set({
|
|
2643
3138
|
contrastLevel,
|
|
2644
3139
|
isDark,
|
|
2645
|
-
|
|
2646
|
-
variant
|
|
3140
|
+
sourceColor,
|
|
3141
|
+
variant: variant2
|
|
2647
3142
|
});
|
|
3143
|
+
api.colors.addColors(defaultColors);
|
|
2648
3144
|
if (palettes) {
|
|
2649
|
-
|
|
2650
|
-
([key, value]) => api.themes.addCustomPalette(key, value)
|
|
2651
|
-
);
|
|
2652
|
-
}
|
|
2653
|
-
if (useDefaultColors) {
|
|
2654
|
-
api.colors.addColors(defaultColors);
|
|
3145
|
+
api.palettes.add(palettes);
|
|
2655
3146
|
}
|
|
2656
3147
|
if (colors) {
|
|
2657
3148
|
api.colors.addColors(colors);
|
|
@@ -2664,35 +3155,44 @@ const loader = async (config) => {
|
|
|
2664
3155
|
}
|
|
2665
3156
|
};
|
|
2666
3157
|
init();
|
|
2667
|
-
|
|
3158
|
+
if (load) {
|
|
3159
|
+
await api.load();
|
|
3160
|
+
}
|
|
2668
3161
|
return api;
|
|
2669
3162
|
};
|
|
2670
3163
|
export {
|
|
2671
|
-
|
|
3164
|
+
API as A,
|
|
3165
|
+
vibrantVariant as B,
|
|
2672
3166
|
ColorApi as C,
|
|
2673
3167
|
DynamicColor as D,
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
ThemeModule as T,
|
|
3168
|
+
expressiveVariant as E,
|
|
3169
|
+
neutralVariant as F,
|
|
3170
|
+
Palette as P,
|
|
2678
3171
|
Variant as V,
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
3172
|
+
AppContainer as a,
|
|
3173
|
+
AppModule as b,
|
|
3174
|
+
bootstrap as c,
|
|
3175
|
+
ColorManager as d,
|
|
3176
|
+
ColorModule as e,
|
|
3177
|
+
Color as f,
|
|
3178
|
+
getInitialToneFromBackground as g,
|
|
2686
3179
|
highestSurface as h,
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
3180
|
+
ColorAlias as i,
|
|
3181
|
+
ColorFromHex as j,
|
|
3182
|
+
ColorFromPalette as k,
|
|
3183
|
+
defaultColors as l,
|
|
3184
|
+
ContextModule as m,
|
|
3185
|
+
Context as n,
|
|
3186
|
+
loader as o,
|
|
3187
|
+
ContrastCurve as p,
|
|
3188
|
+
PaletteApi as q,
|
|
3189
|
+
PaletteModule as r,
|
|
3190
|
+
PluginModule as s,
|
|
3191
|
+
toneDeltaPair as t,
|
|
3192
|
+
PluginApi as u,
|
|
3193
|
+
getPiecewiseHue as v,
|
|
3194
|
+
getRotatedHue as w,
|
|
3195
|
+
variant as x,
|
|
3196
|
+
Variants as y,
|
|
3197
|
+
tonalSpotVariant as z
|
|
2698
3198
|
};
|