@udixio/theme 1.3.1 → 2.0.0

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