@udixio/theme 1.3.0 → 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 +15 -0
- 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-BuN8RpOs.cjs → load-from-path-DZ35yiXK.cjs} +2 -2
- package/dist/{load-from-path-BSrT4DOj.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-Bc0bstAD.js → loader-BS_Esfwg.js} +1408 -905
- package/dist/{loader-YNN5hAF3.cjs → loader-C8LnOoqg.cjs} +1392 -889
- 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-B1QPKKY_.js +0 -430
- package/dist/define-config-BGgVazsr.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 -23
- 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 -78
- 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,380 +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
|
-
create(options) {
|
|
1698
|
-
this.schemeManager.createOrUpdate({
|
|
1699
|
-
...options,
|
|
1700
|
-
sourcesColorHex: { primary: options.sourceColorHex }
|
|
1701
|
-
});
|
|
1702
|
-
this.variantManager.set(options.variant);
|
|
1703
|
-
}
|
|
1704
|
-
update(options) {
|
|
1705
|
-
const themeOptions = { ...options };
|
|
1706
|
-
if (options.sourceColorHex)
|
|
1707
|
-
themeOptions.sourcesColorHex = { primary: options.sourceColorHex };
|
|
1708
|
-
this.schemeManager.createOrUpdate(themeOptions);
|
|
1709
|
-
if (options.variant) this.variantManager.set(options.variant);
|
|
1710
|
-
}
|
|
1711
|
-
addCustomPalette(key, colorHex) {
|
|
1712
|
-
this.variantManager.addCustomPalette(key, colorHex);
|
|
1713
|
-
}
|
|
1714
|
-
// theme(): SchemeService {
|
|
1715
|
-
// return new SchemeService(this.themeOptions, this.colorService)
|
|
1716
|
-
// }
|
|
1717
|
-
}
|
|
1718
|
-
const ThemeModule = {
|
|
1719
|
-
schemeManager: asClass(SchemeManager).singleton(),
|
|
1720
|
-
variantManager: asClass(VariantManager).singleton(),
|
|
1721
|
-
themeApi: asClass(ThemeApi).singleton()
|
|
1722
|
-
};
|
|
1723
|
-
const getPiecewiseHue = (sourceColorHct, hueBreakpoints, hues) => {
|
|
1724
|
-
const size = Math.min(hueBreakpoints.length - 1, hues.length);
|
|
1725
|
-
const sourceHue = sourceColorHct.hue;
|
|
1726
|
-
for (let i = 0; i < size; i++) {
|
|
1727
|
-
if (sourceHue >= hueBreakpoints[i] && sourceHue < hueBreakpoints[i + 1]) {
|
|
1728
|
-
return sanitizeDegreesDouble(hues[i]);
|
|
1729
|
-
}
|
|
1730
|
-
}
|
|
1731
|
-
return sourceHue;
|
|
1732
|
-
};
|
|
1733
|
-
const getRotatedHue = (sourceColorHct, hueBreakpoints, rotations) => {
|
|
1734
|
-
let rotation = getPiecewiseHue(sourceColorHct, hueBreakpoints, rotations);
|
|
1735
|
-
if (Math.min(hueBreakpoints.length - 1, rotations.length) <= 0) {
|
|
1736
|
-
rotation = 0;
|
|
1737
|
-
}
|
|
1738
|
-
return sanitizeDegreesDouble(sourceColorHct.hue + rotation);
|
|
1739
|
-
};
|
|
1740
|
-
class Variant {
|
|
1741
|
-
constructor(palettes = {}, name, customPalettes, colors) {
|
|
1742
|
-
this.palettes = palettes;
|
|
1743
|
-
this.name = name;
|
|
1744
|
-
this.customPalettes = customPalettes;
|
|
1745
|
-
this.colors = colors;
|
|
1746
|
-
}
|
|
1747
|
-
}
|
|
1748
|
-
const tonalSpotVariant = {
|
|
1749
|
-
name: "tonalSpot",
|
|
1750
|
-
palettes: {
|
|
1751
|
-
primary: ({ sourceColorHct, isDark }) => TonalPalette.fromHueAndChroma(sourceColorHct.hue, isDark ? 26 : 32),
|
|
1752
|
-
secondary: ({ sourceColorHct }) => TonalPalette.fromHueAndChroma(sourceColorHct.hue, 16),
|
|
1753
|
-
tertiary: ({ sourceColorHct }) => TonalPalette.fromHueAndChroma(
|
|
1754
|
-
getRotatedHue(
|
|
1755
|
-
sourceColorHct,
|
|
1756
|
-
[0, 20, 71, 161, 333, 360],
|
|
1757
|
-
[-40, 48, -32, 40, -32]
|
|
1758
|
-
),
|
|
1759
|
-
28
|
|
1760
|
-
),
|
|
1761
|
-
neutral: ({ sourceColorHct }) => TonalPalette.fromHueAndChroma(sourceColorHct.hue, 5),
|
|
1762
|
-
neutralVariant: ({ sourceColorHct }) => TonalPalette.fromHueAndChroma(sourceColorHct.hue, 5 * 1.7),
|
|
1763
|
-
error: ({ sourceColorHct }) => {
|
|
1764
|
-
const errorHue = getPiecewiseHue(
|
|
1765
|
-
sourceColorHct,
|
|
1766
|
-
[0, 3, 13, 23, 33, 43, 153, 273, 360],
|
|
1767
|
-
[12, 22, 32, 12, 22, 32, 22, 12]
|
|
1768
|
-
);
|
|
1769
|
-
return TonalPalette.fromHueAndChroma(errorHue, 60);
|
|
1770
|
-
}
|
|
1771
|
-
},
|
|
1772
|
-
customPalettes: ({ colorHct }) => TonalPalette.fromHueAndChroma(colorHct.hue, 16)
|
|
1773
|
-
};
|
|
1774
1679
|
const inverseTone = (tone) => {
|
|
1775
1680
|
return 100 - tone;
|
|
1776
1681
|
};
|
|
1777
|
-
const defaultColors = (
|
|
1682
|
+
const defaultColors = ({
|
|
1683
|
+
colors,
|
|
1684
|
+
context: c,
|
|
1685
|
+
palettes
|
|
1686
|
+
}) => {
|
|
1778
1687
|
const getColor = (key) => {
|
|
1779
|
-
return
|
|
1688
|
+
return colors.get(key);
|
|
1780
1689
|
};
|
|
1781
|
-
|
|
1690
|
+
return {
|
|
1782
1691
|
////////////////////////////////////////////////////////////////
|
|
1783
1692
|
// Surfaces [S] //
|
|
1784
1693
|
////////////////////////////////////////////////////////////////
|
|
1785
1694
|
surface: {
|
|
1786
|
-
palette: (
|
|
1787
|
-
tone: (
|
|
1788
|
-
if (
|
|
1695
|
+
palette: () => palettes.get("neutral"),
|
|
1696
|
+
tone: () => {
|
|
1697
|
+
if (c.isDark) {
|
|
1789
1698
|
return 4;
|
|
1790
1699
|
} else {
|
|
1791
|
-
if (
|
|
1700
|
+
if (c.variant.name == "fidelity") {
|
|
1792
1701
|
return 100;
|
|
1793
1702
|
}
|
|
1794
|
-
if (Hct.isYellow(
|
|
1703
|
+
if (Hct.isYellow(palettes.get("neutral").hue)) {
|
|
1795
1704
|
return 99;
|
|
1796
|
-
} else if (
|
|
1705
|
+
} else if (c.variant.name === "vibrant") {
|
|
1797
1706
|
return 97;
|
|
1798
1707
|
} else {
|
|
1799
1708
|
return 98;
|
|
@@ -1803,14 +1712,14 @@ const defaultColors = (colorService) => {
|
|
|
1803
1712
|
isBackground: true
|
|
1804
1713
|
},
|
|
1805
1714
|
surfaceDim: {
|
|
1806
|
-
palette: (
|
|
1807
|
-
tone: (
|
|
1808
|
-
if (
|
|
1715
|
+
palette: () => palettes.get("neutral"),
|
|
1716
|
+
tone: () => {
|
|
1717
|
+
if (c.isDark) {
|
|
1809
1718
|
return 4;
|
|
1810
1719
|
} else {
|
|
1811
|
-
if (Hct.isYellow(
|
|
1720
|
+
if (Hct.isYellow(palettes.get("neutral").hue)) {
|
|
1812
1721
|
return 90;
|
|
1813
|
-
} else if (
|
|
1722
|
+
} else if (c.variant.name === "vibrant") {
|
|
1814
1723
|
return 85;
|
|
1815
1724
|
} else {
|
|
1816
1725
|
return 87;
|
|
@@ -1818,15 +1727,15 @@ const defaultColors = (colorService) => {
|
|
|
1818
1727
|
}
|
|
1819
1728
|
},
|
|
1820
1729
|
isBackground: true,
|
|
1821
|
-
chromaMultiplier: (
|
|
1822
|
-
if (!
|
|
1823
|
-
if (
|
|
1730
|
+
chromaMultiplier: () => {
|
|
1731
|
+
if (!c.isDark) {
|
|
1732
|
+
if (c.variant.name === "neutral") {
|
|
1824
1733
|
return 2.5;
|
|
1825
|
-
} else if (
|
|
1734
|
+
} else if (c.variant.name === "tonalSpot") {
|
|
1826
1735
|
return 1.7;
|
|
1827
|
-
} else if (
|
|
1828
|
-
return Hct.isYellow(
|
|
1829
|
-
} 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") {
|
|
1830
1739
|
return 1.36;
|
|
1831
1740
|
}
|
|
1832
1741
|
}
|
|
@@ -1834,14 +1743,14 @@ const defaultColors = (colorService) => {
|
|
|
1834
1743
|
}
|
|
1835
1744
|
},
|
|
1836
1745
|
surfaceBright: {
|
|
1837
|
-
palette: (
|
|
1838
|
-
tone: (
|
|
1839
|
-
if (
|
|
1746
|
+
palette: () => palettes.get("neutral"),
|
|
1747
|
+
tone: () => {
|
|
1748
|
+
if (c.isDark) {
|
|
1840
1749
|
return 18;
|
|
1841
1750
|
} else {
|
|
1842
|
-
if (Hct.isYellow(
|
|
1751
|
+
if (Hct.isYellow(palettes.get("neutral").hue)) {
|
|
1843
1752
|
return 99;
|
|
1844
|
-
} else if (
|
|
1753
|
+
} else if (c.variant.name === "vibrant") {
|
|
1845
1754
|
return 97;
|
|
1846
1755
|
} else {
|
|
1847
1756
|
return 98;
|
|
@@ -1849,15 +1758,15 @@ const defaultColors = (colorService) => {
|
|
|
1849
1758
|
}
|
|
1850
1759
|
},
|
|
1851
1760
|
isBackground: true,
|
|
1852
|
-
chromaMultiplier: (
|
|
1853
|
-
if (
|
|
1854
|
-
if (
|
|
1761
|
+
chromaMultiplier: () => {
|
|
1762
|
+
if (c.isDark) {
|
|
1763
|
+
if (c.variant.name === "neutral") {
|
|
1855
1764
|
return 2.5;
|
|
1856
|
-
} else if (
|
|
1765
|
+
} else if (c.variant.name === "tonalSpot") {
|
|
1857
1766
|
return 1.7;
|
|
1858
|
-
} else if (
|
|
1859
|
-
return Hct.isYellow(
|
|
1860
|
-
} 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") {
|
|
1861
1770
|
return 1.36;
|
|
1862
1771
|
}
|
|
1863
1772
|
}
|
|
@@ -1865,19 +1774,19 @@ const defaultColors = (colorService) => {
|
|
|
1865
1774
|
}
|
|
1866
1775
|
},
|
|
1867
1776
|
surfaceContainerLowest: {
|
|
1868
|
-
palette: (
|
|
1869
|
-
tone: (
|
|
1777
|
+
palette: () => palettes.get("neutral"),
|
|
1778
|
+
tone: () => c.isDark ? 0 : 100,
|
|
1870
1779
|
isBackground: true
|
|
1871
1780
|
},
|
|
1872
1781
|
surfaceContainerLow: {
|
|
1873
|
-
palette: (
|
|
1874
|
-
tone: (
|
|
1875
|
-
if (
|
|
1782
|
+
palette: () => palettes.get("neutral"),
|
|
1783
|
+
tone: () => {
|
|
1784
|
+
if (c.isDark) {
|
|
1876
1785
|
return 6;
|
|
1877
1786
|
} else {
|
|
1878
|
-
if (Hct.isYellow(
|
|
1787
|
+
if (Hct.isYellow(palettes.get("neutral").hue)) {
|
|
1879
1788
|
return 98;
|
|
1880
|
-
} else if (
|
|
1789
|
+
} else if (c.variant.name === "vibrant") {
|
|
1881
1790
|
return 95;
|
|
1882
1791
|
} else {
|
|
1883
1792
|
return 96;
|
|
@@ -1885,28 +1794,28 @@ const defaultColors = (colorService) => {
|
|
|
1885
1794
|
}
|
|
1886
1795
|
},
|
|
1887
1796
|
isBackground: true,
|
|
1888
|
-
chromaMultiplier: (
|
|
1889
|
-
if (
|
|
1797
|
+
chromaMultiplier: () => {
|
|
1798
|
+
if (c.variant.name === "neutral") {
|
|
1890
1799
|
return 1.3;
|
|
1891
|
-
} else if (
|
|
1800
|
+
} else if (c.variant.name === "tonalSpot") {
|
|
1892
1801
|
return 1.25;
|
|
1893
|
-
} else if (
|
|
1894
|
-
return Hct.isYellow(
|
|
1895
|
-
} 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") {
|
|
1896
1805
|
return 1.08;
|
|
1897
1806
|
}
|
|
1898
1807
|
return 1;
|
|
1899
1808
|
}
|
|
1900
1809
|
},
|
|
1901
1810
|
surfaceContainer: {
|
|
1902
|
-
palette: (
|
|
1903
|
-
tone: (
|
|
1904
|
-
if (
|
|
1811
|
+
palette: () => palettes.get("neutral"),
|
|
1812
|
+
tone: () => {
|
|
1813
|
+
if (c.isDark) {
|
|
1905
1814
|
return 9;
|
|
1906
1815
|
} else {
|
|
1907
|
-
if (Hct.isYellow(
|
|
1816
|
+
if (Hct.isYellow(palettes.get("neutral").hue)) {
|
|
1908
1817
|
return 96;
|
|
1909
|
-
} else if (
|
|
1818
|
+
} else if (c.variant.name === "vibrant") {
|
|
1910
1819
|
return 92;
|
|
1911
1820
|
} else {
|
|
1912
1821
|
return 94;
|
|
@@ -1914,28 +1823,28 @@ const defaultColors = (colorService) => {
|
|
|
1914
1823
|
}
|
|
1915
1824
|
},
|
|
1916
1825
|
isBackground: true,
|
|
1917
|
-
chromaMultiplier: (
|
|
1918
|
-
if (
|
|
1826
|
+
chromaMultiplier: () => {
|
|
1827
|
+
if (c.variant.name === "neutral") {
|
|
1919
1828
|
return 1.6;
|
|
1920
|
-
} else if (
|
|
1829
|
+
} else if (c.variant.name === "tonalSpot") {
|
|
1921
1830
|
return 1.4;
|
|
1922
|
-
} else if (
|
|
1923
|
-
return Hct.isYellow(
|
|
1924
|
-
} 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") {
|
|
1925
1834
|
return 1.15;
|
|
1926
1835
|
}
|
|
1927
1836
|
return 1;
|
|
1928
1837
|
}
|
|
1929
1838
|
},
|
|
1930
1839
|
surfaceContainerHigh: {
|
|
1931
|
-
palette: (
|
|
1932
|
-
tone: (
|
|
1933
|
-
if (
|
|
1840
|
+
palette: () => palettes.get("neutral"),
|
|
1841
|
+
tone: () => {
|
|
1842
|
+
if (c.isDark) {
|
|
1934
1843
|
return 12;
|
|
1935
1844
|
} else {
|
|
1936
|
-
if (Hct.isYellow(
|
|
1845
|
+
if (Hct.isYellow(palettes.get("neutral").hue)) {
|
|
1937
1846
|
return 94;
|
|
1938
|
-
} else if (
|
|
1847
|
+
} else if (c.variant.name === "vibrant") {
|
|
1939
1848
|
return 90;
|
|
1940
1849
|
} else {
|
|
1941
1850
|
return 92;
|
|
@@ -1943,28 +1852,28 @@ const defaultColors = (colorService) => {
|
|
|
1943
1852
|
}
|
|
1944
1853
|
},
|
|
1945
1854
|
isBackground: true,
|
|
1946
|
-
chromaMultiplier: (
|
|
1947
|
-
if (
|
|
1855
|
+
chromaMultiplier: () => {
|
|
1856
|
+
if (c.variant.name === "neutral") {
|
|
1948
1857
|
return 1.9;
|
|
1949
|
-
} else if (
|
|
1858
|
+
} else if (c.variant.name === "tonalSpot") {
|
|
1950
1859
|
return 1.5;
|
|
1951
|
-
} else if (
|
|
1952
|
-
return Hct.isYellow(
|
|
1953
|
-
} 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") {
|
|
1954
1863
|
return 1.22;
|
|
1955
1864
|
}
|
|
1956
1865
|
return 1;
|
|
1957
1866
|
}
|
|
1958
1867
|
},
|
|
1959
1868
|
surfaceContainerHighest: {
|
|
1960
|
-
palette: (
|
|
1961
|
-
tone: (
|
|
1962
|
-
if (
|
|
1869
|
+
palette: () => palettes.get("neutral"),
|
|
1870
|
+
tone: () => {
|
|
1871
|
+
if (c.isDark) {
|
|
1963
1872
|
return 15;
|
|
1964
1873
|
} else {
|
|
1965
|
-
if (Hct.isYellow(
|
|
1874
|
+
if (Hct.isYellow(palettes.get("neutral").hue)) {
|
|
1966
1875
|
return 92;
|
|
1967
|
-
} else if (
|
|
1876
|
+
} else if (c.variant.name === "vibrant") {
|
|
1968
1877
|
return 88;
|
|
1969
1878
|
} else {
|
|
1970
1879
|
return 90;
|
|
@@ -1972,14 +1881,14 @@ const defaultColors = (colorService) => {
|
|
|
1972
1881
|
}
|
|
1973
1882
|
},
|
|
1974
1883
|
isBackground: true,
|
|
1975
|
-
chromaMultiplier: (
|
|
1976
|
-
if (
|
|
1884
|
+
chromaMultiplier: () => {
|
|
1885
|
+
if (c.variant.name === "neutral") {
|
|
1977
1886
|
return 2.2;
|
|
1978
|
-
} else if (
|
|
1887
|
+
} else if (c.variant.name === "tonalSpot") {
|
|
1979
1888
|
return 1.7;
|
|
1980
|
-
} else if (
|
|
1981
|
-
return Hct.isYellow(
|
|
1982
|
-
} 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") {
|
|
1983
1892
|
return 1.29;
|
|
1984
1893
|
} else {
|
|
1985
1894
|
return 1;
|
|
@@ -1987,132 +1896,133 @@ const defaultColors = (colorService) => {
|
|
|
1987
1896
|
}
|
|
1988
1897
|
},
|
|
1989
1898
|
onSurface: {
|
|
1990
|
-
palette: (
|
|
1991
|
-
tone: (
|
|
1992
|
-
if (
|
|
1993
|
-
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);
|
|
1994
1903
|
} else {
|
|
1995
|
-
return
|
|
1996
|
-
(s2) => highestSurface(s2, colorService)
|
|
1997
|
-
)(s);
|
|
1904
|
+
return getInitialToneFromBackground(highestSurface(c, colors));
|
|
1998
1905
|
}
|
|
1999
1906
|
},
|
|
2000
|
-
chromaMultiplier: (
|
|
2001
|
-
if (
|
|
1907
|
+
chromaMultiplier: () => {
|
|
1908
|
+
if (c.variant.name === "neutral") {
|
|
2002
1909
|
return 2.2;
|
|
2003
|
-
} else if (
|
|
1910
|
+
} else if (c.variant.name === "tonalSpot") {
|
|
2004
1911
|
return 1.7;
|
|
2005
|
-
} else if (
|
|
2006
|
-
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;
|
|
2007
1914
|
}
|
|
2008
1915
|
return 1;
|
|
2009
1916
|
},
|
|
2010
|
-
background: (
|
|
2011
|
-
contrastCurve: (
|
|
1917
|
+
background: () => highestSurface(c, colors),
|
|
1918
|
+
contrastCurve: () => c.isDark ? getCurve(11) : getCurve(9)
|
|
2012
1919
|
},
|
|
2013
1920
|
onSurfaceVariant: {
|
|
2014
|
-
palette: (
|
|
2015
|
-
chromaMultiplier: (
|
|
2016
|
-
if (
|
|
1921
|
+
palette: () => palettes.get("neutralVariant"),
|
|
1922
|
+
chromaMultiplier: () => {
|
|
1923
|
+
if (c.variant.name === "neutral") {
|
|
2017
1924
|
return 2.2;
|
|
2018
|
-
} else if (
|
|
1925
|
+
} else if (c.variant.name === "tonalSpot") {
|
|
2019
1926
|
return 1.7;
|
|
2020
|
-
} else if (
|
|
2021
|
-
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;
|
|
2022
1929
|
}
|
|
2023
1930
|
return 1;
|
|
2024
1931
|
},
|
|
2025
|
-
background: (
|
|
2026
|
-
contrastCurve: (
|
|
1932
|
+
background: () => highestSurface(c, colors),
|
|
1933
|
+
contrastCurve: () => c.isDark ? getCurve(6) : getCurve(4.5)
|
|
2027
1934
|
},
|
|
2028
1935
|
outline: {
|
|
2029
|
-
palette: (
|
|
2030
|
-
chromaMultiplier: (
|
|
2031
|
-
if (
|
|
1936
|
+
palette: () => palettes.get("neutralVariant"),
|
|
1937
|
+
chromaMultiplier: () => {
|
|
1938
|
+
if (c.variant.name === "neutral") {
|
|
2032
1939
|
return 2.2;
|
|
2033
|
-
} else if (
|
|
1940
|
+
} else if (c.variant.name === "tonalSpot") {
|
|
2034
1941
|
return 1.7;
|
|
2035
|
-
} else if (
|
|
2036
|
-
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;
|
|
2037
1944
|
}
|
|
2038
1945
|
return 1;
|
|
2039
1946
|
},
|
|
2040
|
-
background: (
|
|
2041
|
-
contrastCurve: (
|
|
1947
|
+
background: () => highestSurface(c, colors),
|
|
1948
|
+
contrastCurve: () => getCurve(3)
|
|
2042
1949
|
},
|
|
2043
1950
|
outlineVariant: {
|
|
2044
|
-
palette: (
|
|
2045
|
-
chromaMultiplier: (
|
|
2046
|
-
if (
|
|
1951
|
+
palette: () => palettes.get("neutralVariant"),
|
|
1952
|
+
chromaMultiplier: () => {
|
|
1953
|
+
if (c.variant.name === "neutral") {
|
|
2047
1954
|
return 2.2;
|
|
2048
|
-
} else if (
|
|
1955
|
+
} else if (c.variant.name === "tonalSpot") {
|
|
2049
1956
|
return 1.7;
|
|
2050
|
-
} else if (
|
|
2051
|
-
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;
|
|
2052
1959
|
}
|
|
2053
1960
|
return 1;
|
|
2054
1961
|
},
|
|
2055
|
-
background: (
|
|
2056
|
-
contrastCurve: (
|
|
1962
|
+
background: () => highestSurface(c, colors),
|
|
1963
|
+
contrastCurve: () => getCurve(1.5)
|
|
2057
1964
|
},
|
|
2058
1965
|
inverseSurface: {
|
|
2059
|
-
palette: (
|
|
2060
|
-
tone: (
|
|
1966
|
+
palette: () => palettes.get("neutral"),
|
|
1967
|
+
tone: () => c.isDark ? 98 : 4,
|
|
2061
1968
|
isBackground: true
|
|
2062
1969
|
},
|
|
2063
1970
|
inverseOnSurface: {
|
|
2064
|
-
palette: (
|
|
2065
|
-
tone: (
|
|
2066
|
-
background: (
|
|
2067
|
-
contrastCurve: (
|
|
1971
|
+
palette: () => palettes.get("neutral"),
|
|
1972
|
+
tone: () => c.isDark ? 20 : 95,
|
|
1973
|
+
background: () => colors.get("inverseSurface"),
|
|
1974
|
+
contrastCurve: () => getCurve(7)
|
|
2068
1975
|
},
|
|
2069
1976
|
////////////////////////////////////////////////////////////////
|
|
2070
1977
|
// Primaries [P] //
|
|
2071
1978
|
////////////////////////////////////////////////////////////////
|
|
2072
1979
|
primary: {
|
|
2073
|
-
palette: (
|
|
2074
|
-
tone: (
|
|
2075
|
-
if (
|
|
2076
|
-
return
|
|
2077
|
-
} else if (
|
|
2078
|
-
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) {
|
|
2079
1986
|
return 80;
|
|
2080
1987
|
} else {
|
|
2081
|
-
return tMaxC(
|
|
1988
|
+
return tMaxC(palettes.get("primary"));
|
|
2082
1989
|
}
|
|
2083
|
-
} else if (
|
|
1990
|
+
} else if (c.variant.name === "expressive") {
|
|
2084
1991
|
return tMaxC(
|
|
2085
|
-
|
|
1992
|
+
palettes.get("primary"),
|
|
2086
1993
|
0,
|
|
2087
|
-
Hct.isYellow(
|
|
1994
|
+
Hct.isYellow(palettes.get("primary").hue) ? 25 : Hct.isCyan(palettes.get("primary").hue) ? 88 : 98
|
|
2088
1995
|
);
|
|
2089
|
-
} else if (
|
|
2090
|
-
return
|
|
1996
|
+
} else if (c.variant.name == "fidelity") {
|
|
1997
|
+
return c.sourceColor.tone;
|
|
2091
1998
|
} else {
|
|
2092
1999
|
return tMaxC(
|
|
2093
|
-
|
|
2000
|
+
palettes.get("primary"),
|
|
2094
2001
|
0,
|
|
2095
|
-
Hct.isCyan(
|
|
2002
|
+
Hct.isCyan(palettes.get("primary").hue) ? 88 : 98
|
|
2096
2003
|
);
|
|
2097
2004
|
}
|
|
2098
2005
|
},
|
|
2099
2006
|
isBackground: true,
|
|
2100
|
-
background: (
|
|
2101
|
-
contrastCurve: (
|
|
2102
|
-
adjustTone: (
|
|
2103
|
-
const surfaceTone =
|
|
2104
|
-
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;
|
|
2105
2012
|
let selfTone = primaryTone;
|
|
2106
2013
|
if (Contrast.ratioOfTones(surfaceTone, selfTone) < 3) {
|
|
2107
|
-
const
|
|
2108
|
-
|
|
2109
|
-
selfTone
|
|
2110
|
-
|
|
2014
|
+
const ratio = calculateToneAdjustmentPercentage(
|
|
2015
|
+
surfaceTone,
|
|
2016
|
+
selfTone,
|
|
2017
|
+
3
|
|
2018
|
+
);
|
|
2019
|
+
const inverseT = inverseTone(primaryTone);
|
|
2020
|
+
selfTone = selfTone + (inverseT - selfTone) * ratio;
|
|
2111
2021
|
}
|
|
2112
2022
|
return selfTone;
|
|
2113
2023
|
} : toneDeltaPair(
|
|
2114
|
-
|
|
2115
|
-
|
|
2024
|
+
colors.get("primaryContainer"),
|
|
2025
|
+
colors.get("primary"),
|
|
2116
2026
|
5,
|
|
2117
2027
|
"relative_lighter",
|
|
2118
2028
|
true,
|
|
@@ -2120,22 +2030,22 @@ const defaultColors = (colorService) => {
|
|
|
2120
2030
|
)
|
|
2121
2031
|
},
|
|
2122
2032
|
primaryDim: {
|
|
2123
|
-
palette: (
|
|
2124
|
-
tone: (
|
|
2125
|
-
if (
|
|
2033
|
+
palette: () => palettes.get("primary"),
|
|
2034
|
+
tone: () => {
|
|
2035
|
+
if (c.variant.name === "neutral") {
|
|
2126
2036
|
return 85;
|
|
2127
|
-
} else if (
|
|
2128
|
-
return tMaxC(
|
|
2037
|
+
} else if (c.variant.name === "tonalSpot") {
|
|
2038
|
+
return tMaxC(palettes.get("primary"), 0, 90);
|
|
2129
2039
|
} else {
|
|
2130
|
-
return tMaxC(
|
|
2040
|
+
return tMaxC(palettes.get("primary"));
|
|
2131
2041
|
}
|
|
2132
2042
|
},
|
|
2133
2043
|
isBackground: true,
|
|
2134
|
-
background: (
|
|
2135
|
-
contrastCurve: (
|
|
2136
|
-
adjustTone: (
|
|
2137
|
-
|
|
2138
|
-
|
|
2044
|
+
background: () => getColor("surfaceContainerHigh"),
|
|
2045
|
+
contrastCurve: () => getCurve(4.5),
|
|
2046
|
+
adjustTone: () => toneDeltaPair(
|
|
2047
|
+
colors.get("primaryDim"),
|
|
2048
|
+
colors.get("primary"),
|
|
2139
2049
|
5,
|
|
2140
2050
|
"darker",
|
|
2141
2051
|
true,
|
|
@@ -2143,74 +2053,74 @@ const defaultColors = (colorService) => {
|
|
|
2143
2053
|
)
|
|
2144
2054
|
},
|
|
2145
2055
|
onPrimary: {
|
|
2146
|
-
palette: (
|
|
2147
|
-
background: (
|
|
2148
|
-
contrastCurve: (
|
|
2056
|
+
palette: () => palettes.get("primary"),
|
|
2057
|
+
background: () => colors.get("primary"),
|
|
2058
|
+
contrastCurve: () => getCurve(6)
|
|
2149
2059
|
},
|
|
2150
2060
|
primaryContainer: {
|
|
2151
|
-
palette: (
|
|
2152
|
-
tone: (
|
|
2153
|
-
if (
|
|
2154
|
-
return
|
|
2155
|
-
} else if (
|
|
2156
|
-
return
|
|
2157
|
-
} else if (
|
|
2158
|
-
return
|
|
2159
|
-
|
|
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"),
|
|
2160
2070
|
78,
|
|
2161
|
-
Hct.isCyan(
|
|
2071
|
+
Hct.isCyan(palettes.get("primary").hue) ? 88 : 90
|
|
2162
2072
|
);
|
|
2163
2073
|
}
|
|
2164
|
-
if (
|
|
2165
|
-
return
|
|
2166
|
-
s.getPalette("primary"),
|
|
2167
|
-
78,
|
|
2168
|
-
Hct.isCyan(s.getPalette("primary").hue) ? 88 : 90
|
|
2169
|
-
);
|
|
2074
|
+
if (c.variant.name == "fidelity") {
|
|
2075
|
+
return c.isDark ? tMinC(palettes.get("primary"), 35, 93) : tMaxC(palettes.get("primary"), 0, 90);
|
|
2170
2076
|
} else {
|
|
2171
|
-
return
|
|
2172
|
-
|
|
2077
|
+
return c.isDark ? tMinC(palettes.get("primary"), 66, 93) : tMaxC(
|
|
2078
|
+
palettes.get("primary"),
|
|
2173
2079
|
66,
|
|
2174
|
-
Hct.isCyan(
|
|
2080
|
+
Hct.isCyan(palettes.get("primary").hue) ? 88 : 93
|
|
2175
2081
|
);
|
|
2176
2082
|
}
|
|
2177
2083
|
},
|
|
2178
2084
|
isBackground: true,
|
|
2179
|
-
background: (
|
|
2180
|
-
adjustTone: (
|
|
2181
|
-
|
|
2182
|
-
|
|
2085
|
+
background: () => highestSurface(c, colors),
|
|
2086
|
+
adjustTone: () => c.variant.name == "fidelity" ? toneDeltaPair(
|
|
2087
|
+
colors.get("primary"),
|
|
2088
|
+
colors.get("primaryContainer"),
|
|
2183
2089
|
15,
|
|
2184
2090
|
"relative_darker",
|
|
2185
2091
|
true,
|
|
2186
2092
|
"farther"
|
|
2187
2093
|
) : void 0,
|
|
2188
|
-
contrastCurve: (
|
|
2094
|
+
contrastCurve: () => c.contrastLevel > 0 ? getCurve(1.5) : void 0
|
|
2189
2095
|
},
|
|
2190
2096
|
onPrimaryContainer: {
|
|
2191
|
-
palette: (
|
|
2192
|
-
background: (
|
|
2193
|
-
contrastCurve: (
|
|
2097
|
+
palette: () => palettes.get("primary"),
|
|
2098
|
+
background: () => colors.get("primaryContainer"),
|
|
2099
|
+
contrastCurve: () => getCurve(6)
|
|
2194
2100
|
},
|
|
2195
2101
|
primaryFixed: {
|
|
2196
|
-
palette: (
|
|
2197
|
-
tone: (
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
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
|
+
);
|
|
2204
2114
|
},
|
|
2205
2115
|
isBackground: true,
|
|
2206
|
-
background: (
|
|
2207
|
-
contrastCurve: (
|
|
2116
|
+
background: () => highestSurface(c, colors),
|
|
2117
|
+
contrastCurve: () => c.contrastLevel > 0 ? getCurve(1.5) : void 0
|
|
2208
2118
|
},
|
|
2209
2119
|
primaryFixedDim: {
|
|
2210
|
-
palette: (
|
|
2211
|
-
tone: (
|
|
2120
|
+
palette: () => palettes.get("primary"),
|
|
2121
|
+
tone: () => colors.get("primaryFixed").getTone(),
|
|
2212
2122
|
isBackground: true,
|
|
2213
|
-
adjustTone: (
|
|
2123
|
+
adjustTone: () => toneDeltaPair(
|
|
2214
2124
|
getColor("primaryFixedDim"),
|
|
2215
2125
|
getColor("primaryFixed"),
|
|
2216
2126
|
5,
|
|
@@ -2220,39 +2130,39 @@ const defaultColors = (colorService) => {
|
|
|
2220
2130
|
)
|
|
2221
2131
|
},
|
|
2222
2132
|
onPrimaryFixed: {
|
|
2223
|
-
palette: (
|
|
2224
|
-
background: (
|
|
2225
|
-
contrastCurve: (
|
|
2133
|
+
palette: () => palettes.get("primary"),
|
|
2134
|
+
background: () => colors.get("primaryFixedDim"),
|
|
2135
|
+
contrastCurve: () => getCurve(7)
|
|
2226
2136
|
},
|
|
2227
2137
|
onPrimaryFixedVariant: {
|
|
2228
|
-
palette: (
|
|
2229
|
-
background: (
|
|
2230
|
-
contrastCurve: (
|
|
2138
|
+
palette: () => palettes.get("primary"),
|
|
2139
|
+
background: () => colors.get("primaryFixedDim"),
|
|
2140
|
+
contrastCurve: () => getCurve(4.5)
|
|
2231
2141
|
},
|
|
2232
2142
|
inversePrimary: {
|
|
2233
|
-
palette: (
|
|
2234
|
-
tone: (
|
|
2235
|
-
background: (
|
|
2236
|
-
contrastCurve: (
|
|
2143
|
+
palette: () => palettes.get("primary"),
|
|
2144
|
+
tone: () => tMaxC(palettes.get("primary")),
|
|
2145
|
+
background: () => colors.get("inverseSurface"),
|
|
2146
|
+
contrastCurve: () => getCurve(6)
|
|
2237
2147
|
},
|
|
2238
2148
|
////////////////////////////////////////////////////////////////
|
|
2239
2149
|
// Secondaries [Q] //
|
|
2240
2150
|
////////////////////////////////////////////////////////////////
|
|
2241
2151
|
secondary: {
|
|
2242
|
-
palette: (
|
|
2243
|
-
tone: (
|
|
2244
|
-
if (
|
|
2245
|
-
return
|
|
2246
|
-
} else if (
|
|
2247
|
-
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);
|
|
2248
2158
|
} else {
|
|
2249
|
-
return
|
|
2159
|
+
return c.isDark ? 80 : tMaxC(palettes.get("secondary"));
|
|
2250
2160
|
}
|
|
2251
2161
|
},
|
|
2252
2162
|
isBackground: true,
|
|
2253
|
-
background: (
|
|
2254
|
-
contrastCurve: (
|
|
2255
|
-
adjustTone: (
|
|
2163
|
+
background: () => highestSurface(c, colors),
|
|
2164
|
+
contrastCurve: () => getCurve(4.5),
|
|
2165
|
+
adjustTone: () => toneDeltaPair(
|
|
2256
2166
|
getColor("secondaryContainer"),
|
|
2257
2167
|
getColor("secondary"),
|
|
2258
2168
|
5,
|
|
@@ -2262,18 +2172,18 @@ const defaultColors = (colorService) => {
|
|
|
2262
2172
|
)
|
|
2263
2173
|
},
|
|
2264
2174
|
secondaryDim: {
|
|
2265
|
-
palette: (
|
|
2266
|
-
tone: (
|
|
2267
|
-
if (
|
|
2175
|
+
palette: () => palettes.get("secondary"),
|
|
2176
|
+
tone: () => {
|
|
2177
|
+
if (c.variant.name === "neutral") {
|
|
2268
2178
|
return 85;
|
|
2269
2179
|
} else {
|
|
2270
|
-
return tMaxC(
|
|
2180
|
+
return tMaxC(palettes.get("secondary"), 0, 90);
|
|
2271
2181
|
}
|
|
2272
2182
|
},
|
|
2273
2183
|
isBackground: true,
|
|
2274
|
-
background: (
|
|
2275
|
-
contrastCurve: (
|
|
2276
|
-
adjustTone: (
|
|
2184
|
+
background: () => getColor("surfaceContainerHigh"),
|
|
2185
|
+
contrastCurve: () => getCurve(4.5),
|
|
2186
|
+
adjustTone: () => toneDeltaPair(
|
|
2277
2187
|
getColor("secondaryDim"),
|
|
2278
2188
|
getColor("secondary"),
|
|
2279
2189
|
5,
|
|
@@ -2283,50 +2193,54 @@ const defaultColors = (colorService) => {
|
|
|
2283
2193
|
)
|
|
2284
2194
|
},
|
|
2285
2195
|
onSecondary: {
|
|
2286
|
-
palette: (
|
|
2287
|
-
background: (
|
|
2288
|
-
contrastCurve: (
|
|
2196
|
+
palette: () => palettes.get("secondary"),
|
|
2197
|
+
background: () => getColor("secondary"),
|
|
2198
|
+
contrastCurve: () => getCurve(6)
|
|
2289
2199
|
},
|
|
2290
2200
|
secondaryContainer: {
|
|
2291
|
-
palette: (
|
|
2292
|
-
tone: (
|
|
2293
|
-
if (
|
|
2294
|
-
return
|
|
2295
|
-
} else if (
|
|
2296
|
-
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);
|
|
2297
2207
|
} else {
|
|
2298
|
-
return
|
|
2208
|
+
return c.isDark ? 25 : 90;
|
|
2299
2209
|
}
|
|
2300
2210
|
},
|
|
2301
2211
|
isBackground: true,
|
|
2302
|
-
background: (
|
|
2303
|
-
adjustTone: (
|
|
2304
|
-
contrastCurve: (
|
|
2212
|
+
background: () => highestSurface(c, colors),
|
|
2213
|
+
adjustTone: () => void 0,
|
|
2214
|
+
contrastCurve: () => c.contrastLevel > 0 ? getCurve(1.5) : void 0
|
|
2305
2215
|
},
|
|
2306
2216
|
onSecondaryContainer: {
|
|
2307
|
-
palette: (
|
|
2308
|
-
background: (
|
|
2309
|
-
contrastCurve: (
|
|
2217
|
+
palette: () => palettes.get("secondary"),
|
|
2218
|
+
background: () => getColor("secondaryContainer"),
|
|
2219
|
+
contrastCurve: () => getCurve(6)
|
|
2310
2220
|
},
|
|
2311
2221
|
secondaryFixed: {
|
|
2312
|
-
palette: (
|
|
2313
|
-
tone: (
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
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
|
+
);
|
|
2320
2234
|
},
|
|
2321
2235
|
isBackground: true,
|
|
2322
|
-
background: (
|
|
2323
|
-
contrastCurve: (
|
|
2236
|
+
background: () => highestSurface(c, colors),
|
|
2237
|
+
contrastCurve: () => c.contrastLevel > 0 ? getCurve(1.5) : void 0
|
|
2324
2238
|
},
|
|
2325
2239
|
secondaryFixedDim: {
|
|
2326
|
-
palette: (
|
|
2327
|
-
tone: (
|
|
2240
|
+
palette: () => palettes.get("secondary"),
|
|
2241
|
+
tone: () => getColor("secondaryFixed").getTone(),
|
|
2328
2242
|
isBackground: true,
|
|
2329
|
-
adjustTone: (
|
|
2243
|
+
adjustTone: () => toneDeltaPair(
|
|
2330
2244
|
getColor("secondaryFixedDim"),
|
|
2331
2245
|
getColor("secondaryFixed"),
|
|
2332
2246
|
5,
|
|
@@ -2336,35 +2250,35 @@ const defaultColors = (colorService) => {
|
|
|
2336
2250
|
)
|
|
2337
2251
|
},
|
|
2338
2252
|
onSecondaryFixed: {
|
|
2339
|
-
palette: (
|
|
2340
|
-
background: (
|
|
2341
|
-
contrastCurve: (
|
|
2253
|
+
palette: () => palettes.get("secondary"),
|
|
2254
|
+
background: () => getColor("secondaryFixedDim"),
|
|
2255
|
+
contrastCurve: () => getCurve(7)
|
|
2342
2256
|
},
|
|
2343
2257
|
onSecondaryFixedVariant: {
|
|
2344
|
-
palette: (
|
|
2345
|
-
background: (
|
|
2346
|
-
contrastCurve: (
|
|
2258
|
+
palette: () => palettes.get("secondary"),
|
|
2259
|
+
background: () => getColor("secondaryFixedDim"),
|
|
2260
|
+
contrastCurve: () => getCurve(4.5)
|
|
2347
2261
|
},
|
|
2348
2262
|
////////////////////////////////////////////////////////////////
|
|
2349
2263
|
// Tertiaries [T] //
|
|
2350
2264
|
////////////////////////////////////////////////////////////////
|
|
2351
2265
|
tertiary: {
|
|
2352
|
-
palette: (
|
|
2353
|
-
tone: (
|
|
2354
|
-
if (
|
|
2266
|
+
palette: () => palettes.get("tertiary"),
|
|
2267
|
+
tone: () => {
|
|
2268
|
+
if (c.variant.name === "expressive" || c.variant.name === "vibrant") {
|
|
2355
2269
|
return tMaxC(
|
|
2356
|
-
|
|
2270
|
+
palettes.get("tertiary"),
|
|
2357
2271
|
0,
|
|
2358
|
-
Hct.isCyan(
|
|
2272
|
+
Hct.isCyan(palettes.get("tertiary").hue) ? 88 : c.isDark ? 98 : 100
|
|
2359
2273
|
);
|
|
2360
2274
|
} else {
|
|
2361
|
-
return
|
|
2275
|
+
return c.isDark ? tMaxC(palettes.get("tertiary"), 0, 98) : tMaxC(palettes.get("tertiary"));
|
|
2362
2276
|
}
|
|
2363
2277
|
},
|
|
2364
2278
|
isBackground: true,
|
|
2365
|
-
background: (
|
|
2366
|
-
contrastCurve: (
|
|
2367
|
-
adjustTone: (
|
|
2279
|
+
background: () => highestSurface(c, colors),
|
|
2280
|
+
contrastCurve: () => getCurve(4.5),
|
|
2281
|
+
adjustTone: () => toneDeltaPair(
|
|
2368
2282
|
getColor("tertiaryContainer"),
|
|
2369
2283
|
getColor("tertiary"),
|
|
2370
2284
|
5,
|
|
@@ -2374,18 +2288,18 @@ const defaultColors = (colorService) => {
|
|
|
2374
2288
|
)
|
|
2375
2289
|
},
|
|
2376
2290
|
tertiaryDim: {
|
|
2377
|
-
palette: (
|
|
2378
|
-
tone: (
|
|
2379
|
-
if (
|
|
2380
|
-
return tMaxC(
|
|
2291
|
+
palette: () => palettes.get("tertiary"),
|
|
2292
|
+
tone: () => {
|
|
2293
|
+
if (c.variant.name === "tonalSpot") {
|
|
2294
|
+
return tMaxC(palettes.get("tertiary"), 0, 90);
|
|
2381
2295
|
} else {
|
|
2382
|
-
return tMaxC(
|
|
2296
|
+
return tMaxC(palettes.get("tertiary"));
|
|
2383
2297
|
}
|
|
2384
2298
|
},
|
|
2385
2299
|
isBackground: true,
|
|
2386
|
-
background: (
|
|
2387
|
-
contrastCurve: (
|
|
2388
|
-
adjustTone: (
|
|
2300
|
+
background: () => getColor("surfaceContainerHigh"),
|
|
2301
|
+
contrastCurve: () => getCurve(4.5),
|
|
2302
|
+
adjustTone: () => toneDeltaPair(
|
|
2389
2303
|
getColor("tertiaryDim"),
|
|
2390
2304
|
getColor("tertiary"),
|
|
2391
2305
|
5,
|
|
@@ -2395,56 +2309,60 @@ const defaultColors = (colorService) => {
|
|
|
2395
2309
|
)
|
|
2396
2310
|
},
|
|
2397
2311
|
onTertiary: {
|
|
2398
|
-
palette: (
|
|
2399
|
-
background: (
|
|
2400
|
-
contrastCurve: (
|
|
2312
|
+
palette: () => palettes.get("tertiary"),
|
|
2313
|
+
background: () => getColor("tertiary"),
|
|
2314
|
+
contrastCurve: () => getCurve(6)
|
|
2401
2315
|
},
|
|
2402
2316
|
tertiaryContainer: {
|
|
2403
|
-
palette: (
|
|
2404
|
-
tone: (
|
|
2405
|
-
if (
|
|
2406
|
-
return
|
|
2407
|
-
} else if (
|
|
2408
|
-
return tMaxC(
|
|
2409
|
-
} 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") {
|
|
2410
2324
|
return tMaxC(
|
|
2411
|
-
|
|
2325
|
+
palettes.get("tertiary"),
|
|
2412
2326
|
75,
|
|
2413
|
-
Hct.isCyan(
|
|
2327
|
+
Hct.isCyan(palettes.get("tertiary").hue) ? 88 : c.isDark ? 93 : 100
|
|
2414
2328
|
);
|
|
2415
2329
|
} else {
|
|
2416
|
-
return
|
|
2330
|
+
return c.isDark ? tMaxC(palettes.get("tertiary"), 0, 93) : tMaxC(palettes.get("tertiary"), 72, 100);
|
|
2417
2331
|
}
|
|
2418
2332
|
},
|
|
2419
2333
|
isBackground: true,
|
|
2420
|
-
background: (
|
|
2421
|
-
adjustTone: (
|
|
2422
|
-
contrastCurve: (
|
|
2334
|
+
background: () => highestSurface(c, colors),
|
|
2335
|
+
adjustTone: () => void 0,
|
|
2336
|
+
contrastCurve: () => c.contrastLevel > 0 ? getCurve(1.5) : void 0
|
|
2423
2337
|
},
|
|
2424
2338
|
onTertiaryContainer: {
|
|
2425
|
-
palette: (
|
|
2426
|
-
background: (
|
|
2427
|
-
contrastCurve: (
|
|
2339
|
+
palette: () => palettes.get("tertiary"),
|
|
2340
|
+
background: () => getColor("tertiaryContainer"),
|
|
2341
|
+
contrastCurve: () => getCurve(6)
|
|
2428
2342
|
},
|
|
2429
2343
|
tertiaryFixed: {
|
|
2430
|
-
palette: (
|
|
2431
|
-
tone: (
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
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
|
+
);
|
|
2438
2356
|
},
|
|
2439
2357
|
isBackground: true,
|
|
2440
|
-
background: (
|
|
2441
|
-
contrastCurve: (
|
|
2358
|
+
background: () => highestSurface(c, colors),
|
|
2359
|
+
contrastCurve: () => c.contrastLevel > 0 ? getCurve(1.5) : void 0
|
|
2442
2360
|
},
|
|
2443
2361
|
tertiaryFixedDim: {
|
|
2444
|
-
palette: (
|
|
2445
|
-
tone: (
|
|
2362
|
+
palette: () => palettes.get("tertiary"),
|
|
2363
|
+
tone: () => getColor("tertiaryFixed").getTone(),
|
|
2446
2364
|
isBackground: true,
|
|
2447
|
-
adjustTone: (
|
|
2365
|
+
adjustTone: () => toneDeltaPair(
|
|
2448
2366
|
getColor("tertiaryFixedDim"),
|
|
2449
2367
|
getColor("tertiaryFixed"),
|
|
2450
2368
|
5,
|
|
@@ -2454,29 +2372,29 @@ const defaultColors = (colorService) => {
|
|
|
2454
2372
|
)
|
|
2455
2373
|
},
|
|
2456
2374
|
onTertiaryFixed: {
|
|
2457
|
-
palette: (
|
|
2458
|
-
background: (
|
|
2459
|
-
contrastCurve: (
|
|
2375
|
+
palette: () => palettes.get("tertiary"),
|
|
2376
|
+
background: () => getColor("tertiaryFixedDim"),
|
|
2377
|
+
contrastCurve: () => getCurve(7)
|
|
2460
2378
|
},
|
|
2461
2379
|
onTertiaryFixedVariant: {
|
|
2462
|
-
palette: (
|
|
2463
|
-
background: (
|
|
2464
|
-
contrastCurve: (
|
|
2380
|
+
palette: () => palettes.get("tertiary"),
|
|
2381
|
+
background: () => getColor("tertiaryFixedDim"),
|
|
2382
|
+
contrastCurve: () => getCurve(4.5)
|
|
2465
2383
|
},
|
|
2466
2384
|
////////////////////////////////////////////////////////////////
|
|
2467
2385
|
// Errors [E] //
|
|
2468
2386
|
////////////////////////////////////////////////////////////////
|
|
2469
2387
|
error: {
|
|
2470
|
-
palette: (
|
|
2471
|
-
tone: (
|
|
2472
|
-
return
|
|
2388
|
+
palette: () => palettes.get("error"),
|
|
2389
|
+
tone: () => {
|
|
2390
|
+
return c.isDark ? tMinC(palettes.get("error"), 0, 98) : tMaxC(palettes.get("error"));
|
|
2473
2391
|
},
|
|
2474
2392
|
isBackground: true,
|
|
2475
|
-
background: (
|
|
2476
|
-
contrastCurve: (
|
|
2477
|
-
adjustTone: (
|
|
2478
|
-
|
|
2479
|
-
|
|
2393
|
+
background: () => highestSurface(c, colors),
|
|
2394
|
+
contrastCurve: () => getCurve(4.5),
|
|
2395
|
+
adjustTone: () => toneDeltaPair(
|
|
2396
|
+
colors.get("errorContainer"),
|
|
2397
|
+
colors.get("error"),
|
|
2480
2398
|
5,
|
|
2481
2399
|
"relative_lighter",
|
|
2482
2400
|
true,
|
|
@@ -2484,12 +2402,12 @@ const defaultColors = (colorService) => {
|
|
|
2484
2402
|
)
|
|
2485
2403
|
},
|
|
2486
2404
|
errorDim: {
|
|
2487
|
-
palette: (
|
|
2488
|
-
tone: (
|
|
2405
|
+
palette: () => palettes.get("error"),
|
|
2406
|
+
tone: () => tMinC(palettes.get("error")),
|
|
2489
2407
|
isBackground: true,
|
|
2490
|
-
background: (
|
|
2491
|
-
contrastCurve: (
|
|
2492
|
-
adjustTone: (
|
|
2408
|
+
background: () => getColor("surfaceContainerHigh"),
|
|
2409
|
+
contrastCurve: () => getCurve(4.5),
|
|
2410
|
+
adjustTone: () => toneDeltaPair(
|
|
2493
2411
|
getColor("errorDim"),
|
|
2494
2412
|
getColor("error"),
|
|
2495
2413
|
5,
|
|
@@ -2499,24 +2417,24 @@ const defaultColors = (colorService) => {
|
|
|
2499
2417
|
)
|
|
2500
2418
|
},
|
|
2501
2419
|
onError: {
|
|
2502
|
-
palette: (
|
|
2503
|
-
background: (
|
|
2504
|
-
contrastCurve: (
|
|
2420
|
+
palette: () => palettes.get("error"),
|
|
2421
|
+
background: () => colors.get("error"),
|
|
2422
|
+
contrastCurve: () => getCurve(6)
|
|
2505
2423
|
},
|
|
2506
2424
|
errorContainer: {
|
|
2507
|
-
palette: (
|
|
2508
|
-
tone: (
|
|
2509
|
-
return
|
|
2425
|
+
palette: () => palettes.get("error"),
|
|
2426
|
+
tone: () => {
|
|
2427
|
+
return c.isDark ? tMinC(palettes.get("error"), 30, 93) : tMaxC(palettes.get("error"), 0, 90);
|
|
2510
2428
|
},
|
|
2511
2429
|
isBackground: true,
|
|
2512
|
-
background: (
|
|
2513
|
-
adjustTone: (
|
|
2514
|
-
contrastCurve: (
|
|
2430
|
+
background: () => highestSurface(c, colors),
|
|
2431
|
+
adjustTone: () => void 0,
|
|
2432
|
+
contrastCurve: () => c.contrastLevel > 0 ? getCurve(1.5) : void 0
|
|
2515
2433
|
},
|
|
2516
2434
|
onErrorContainer: {
|
|
2517
|
-
palette: (
|
|
2518
|
-
background: (
|
|
2519
|
-
contrastCurve: (
|
|
2435
|
+
palette: () => palettes.get("error"),
|
|
2436
|
+
background: () => colors.get("errorContainer"),
|
|
2437
|
+
contrastCurve: () => getCurve(4.5)
|
|
2520
2438
|
},
|
|
2521
2439
|
/////////////////////////////////////////////////////////////////
|
|
2522
2440
|
// Remapped Colors //
|
|
@@ -2534,27 +2452,7 @@ const defaultColors = (colorService) => {
|
|
|
2534
2452
|
alias: "onSurface"
|
|
2535
2453
|
}
|
|
2536
2454
|
};
|
|
2537
|
-
return {
|
|
2538
|
-
colors
|
|
2539
|
-
};
|
|
2540
2455
|
};
|
|
2541
|
-
class API {
|
|
2542
|
-
constructor({
|
|
2543
|
-
colorApi,
|
|
2544
|
-
themeApi,
|
|
2545
|
-
pluginApi
|
|
2546
|
-
}) {
|
|
2547
|
-
__publicField(this, "colors");
|
|
2548
|
-
__publicField(this, "themes");
|
|
2549
|
-
__publicField(this, "plugins");
|
|
2550
|
-
this.plugins = pluginApi;
|
|
2551
|
-
this.colors = colorApi;
|
|
2552
|
-
this.themes = themeApi;
|
|
2553
|
-
}
|
|
2554
|
-
async load() {
|
|
2555
|
-
return this.plugins.loadPlugins();
|
|
2556
|
-
}
|
|
2557
|
-
}
|
|
2558
2456
|
const AppModule = {
|
|
2559
2457
|
api: asClass(API).singleton()
|
|
2560
2458
|
};
|
|
@@ -2601,54 +2499,650 @@ class PluginApi {
|
|
|
2601
2499
|
const PluginModule = {
|
|
2602
2500
|
pluginApi: asClass(PluginApi).singleton()
|
|
2603
2501
|
};
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
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
|
+
}
|
|
2608
2511
|
});
|
|
2609
|
-
}
|
|
2610
|
-
|
|
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
|
+
}
|
|
2611
2632
|
}
|
|
2612
|
-
const
|
|
2613
|
-
|
|
2614
|
-
}
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
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
|
+
}
|
|
2618
2732
|
}
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
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
|
|
2623
2824
|
});
|
|
2624
|
-
|
|
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;
|
|
2625
2846
|
};
|
|
2626
|
-
const
|
|
2627
|
-
|
|
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
|
+
);
|
|
3020
|
+
};
|
|
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();
|
|
2628
3127
|
const init = () => {
|
|
2629
3128
|
const {
|
|
2630
3129
|
sourceColor,
|
|
2631
3130
|
contrastLevel = 0,
|
|
2632
3131
|
isDark = false,
|
|
2633
|
-
variant =
|
|
3132
|
+
variant: variant2 = Variants.TonalSpot,
|
|
2634
3133
|
palettes,
|
|
2635
3134
|
colors,
|
|
2636
|
-
useDefaultColors = true,
|
|
2637
3135
|
plugins
|
|
2638
3136
|
} = config;
|
|
2639
|
-
api.
|
|
3137
|
+
api.context.set({
|
|
2640
3138
|
contrastLevel,
|
|
2641
3139
|
isDark,
|
|
2642
|
-
|
|
2643
|
-
variant
|
|
3140
|
+
sourceColor,
|
|
3141
|
+
variant: variant2
|
|
2644
3142
|
});
|
|
3143
|
+
api.colors.addColors(defaultColors);
|
|
2645
3144
|
if (palettes) {
|
|
2646
|
-
|
|
2647
|
-
([key, value]) => api.themes.addCustomPalette(key, value)
|
|
2648
|
-
);
|
|
2649
|
-
}
|
|
2650
|
-
if (useDefaultColors) {
|
|
2651
|
-
api.colors.addColors(defaultColors);
|
|
3145
|
+
api.palettes.add(palettes);
|
|
2652
3146
|
}
|
|
2653
3147
|
if (colors) {
|
|
2654
3148
|
api.colors.addColors(colors);
|
|
@@ -2661,35 +3155,44 @@ const loader = async (config) => {
|
|
|
2661
3155
|
}
|
|
2662
3156
|
};
|
|
2663
3157
|
init();
|
|
2664
|
-
|
|
3158
|
+
if (load) {
|
|
3159
|
+
await api.load();
|
|
3160
|
+
}
|
|
2665
3161
|
return api;
|
|
2666
3162
|
};
|
|
2667
3163
|
export {
|
|
2668
|
-
|
|
3164
|
+
API as A,
|
|
3165
|
+
vibrantVariant as B,
|
|
2669
3166
|
ColorApi as C,
|
|
2670
3167
|
DynamicColor as D,
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
ThemeModule as T,
|
|
3168
|
+
expressiveVariant as E,
|
|
3169
|
+
neutralVariant as F,
|
|
3170
|
+
Palette as P,
|
|
2675
3171
|
Variant as V,
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
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,
|
|
2683
3179
|
highestSurface as h,
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
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
|
|
2695
3198
|
};
|