@udixio/theme 1.3.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/CHANGELOG.md +15 -0
  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-BuN8RpOs.cjs → load-from-path-DZ35yiXK.cjs} +2 -2
  34. package/dist/{load-from-path-BSrT4DOj.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-Bc0bstAD.js → loader-BS_Esfwg.js} +1408 -905
  38. package/dist/{loader-YNN5hAF3.cjs → loader-C8LnOoqg.cjs} +1392 -889
  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-B1QPKKY_.js +0 -430
  102. package/dist/define-config-BGgVazsr.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 -23
  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 -78
  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,380 +1562,147 @@ class ColorManager {
1420
1562
  const colorFixedDimKey = colorKey + "FixedDim";
1421
1563
  const onColorFixedKey = "on" + ColorKey + "Fixed";
1422
1564
  const onColorFixedVariantKey = "on" + ColorKey + "FixedVariant";
1423
- 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
- create(options) {
1698
- this.schemeManager.createOrUpdate({
1699
- ...options,
1700
- sourcesColorHex: { primary: options.sourceColorHex }
1701
- });
1702
- this.variantManager.set(options.variant);
1703
- }
1704
- update(options) {
1705
- const themeOptions = { ...options };
1706
- if (options.sourceColorHex)
1707
- themeOptions.sourcesColorHex = { primary: options.sourceColorHex };
1708
- this.schemeManager.createOrUpdate(themeOptions);
1709
- if (options.variant) this.variantManager.set(options.variant);
1710
- }
1711
- addCustomPalette(key, colorHex) {
1712
- this.variantManager.addCustomPalette(key, colorHex);
1713
- }
1714
- // theme(): SchemeService {
1715
- // return new SchemeService(this.themeOptions, this.colorService)
1716
- // }
1717
- }
1718
- const ThemeModule = {
1719
- schemeManager: asClass(SchemeManager).singleton(),
1720
- variantManager: asClass(VariantManager).singleton(),
1721
- themeApi: asClass(ThemeApi).singleton()
1722
- };
1723
- const getPiecewiseHue = (sourceColorHct, hueBreakpoints, hues) => {
1724
- const size = Math.min(hueBreakpoints.length - 1, hues.length);
1725
- const sourceHue = sourceColorHct.hue;
1726
- for (let i = 0; i < size; i++) {
1727
- if (sourceHue >= hueBreakpoints[i] && sourceHue < hueBreakpoints[i + 1]) {
1728
- return sanitizeDegreesDouble(hues[i]);
1729
- }
1730
- }
1731
- return sourceHue;
1732
- };
1733
- const getRotatedHue = (sourceColorHct, hueBreakpoints, rotations) => {
1734
- let rotation = getPiecewiseHue(sourceColorHct, hueBreakpoints, rotations);
1735
- if (Math.min(hueBreakpoints.length - 1, rotations.length) <= 0) {
1736
- rotation = 0;
1737
- }
1738
- return sanitizeDegreesDouble(sourceColorHct.hue + rotation);
1739
- };
1740
- class Variant {
1741
- constructor(palettes = {}, name, customPalettes, colors) {
1742
- this.palettes = palettes;
1743
- this.name = name;
1744
- this.customPalettes = customPalettes;
1745
- this.colors = colors;
1746
- }
1747
- }
1748
- const tonalSpotVariant = {
1749
- name: "tonalSpot",
1750
- palettes: {
1751
- primary: ({ sourceColorHct, isDark }) => TonalPalette.fromHueAndChroma(sourceColorHct.hue, isDark ? 26 : 32),
1752
- secondary: ({ sourceColorHct }) => TonalPalette.fromHueAndChroma(sourceColorHct.hue, 16),
1753
- tertiary: ({ sourceColorHct }) => TonalPalette.fromHueAndChroma(
1754
- getRotatedHue(
1755
- sourceColorHct,
1756
- [0, 20, 71, 161, 333, 360],
1757
- [-40, 48, -32, 40, -32]
1758
- ),
1759
- 28
1760
- ),
1761
- neutral: ({ sourceColorHct }) => TonalPalette.fromHueAndChroma(sourceColorHct.hue, 5),
1762
- neutralVariant: ({ sourceColorHct }) => TonalPalette.fromHueAndChroma(sourceColorHct.hue, 5 * 1.7),
1763
- error: ({ sourceColorHct }) => {
1764
- const errorHue = getPiecewiseHue(
1765
- sourceColorHct,
1766
- [0, 3, 13, 23, 33, 43, 153, 273, 360],
1767
- [12, 22, 32, 12, 22, 32, 22, 12]
1768
- );
1769
- return TonalPalette.fromHueAndChroma(errorHue, 60);
1770
- }
1771
- },
1772
- customPalettes: ({ colorHct }) => TonalPalette.fromHueAndChroma(colorHct.hue, 16)
1773
- };
1774
1679
  const inverseTone = (tone) => {
1775
1680
  return 100 - tone;
1776
1681
  };
1777
- const defaultColors = (colorService) => {
1682
+ const defaultColors = ({
1683
+ colors,
1684
+ context: c,
1685
+ palettes
1686
+ }) => {
1778
1687
  const getColor = (key) => {
1779
- return colorService.getColor(key).getMaterialColor();
1688
+ return colors.get(key);
1780
1689
  };
1781
- const colors = {
1690
+ return {
1782
1691
  ////////////////////////////////////////////////////////////////
1783
1692
  // Surfaces [S] //
1784
1693
  ////////////////////////////////////////////////////////////////
1785
1694
  surface: {
1786
- palette: (s) => s.getPalette("neutral"),
1787
- tone: (s) => {
1788
- if (s.isDark) {
1695
+ palette: () => palettes.get("neutral"),
1696
+ tone: () => {
1697
+ if (c.isDark) {
1789
1698
  return 4;
1790
1699
  } else {
1791
- if (s.variant == "fidelity") {
1700
+ if (c.variant.name == "fidelity") {
1792
1701
  return 100;
1793
1702
  }
1794
- if (Hct.isYellow(s.getPalette("neutral").hue)) {
1703
+ if (Hct.isYellow(palettes.get("neutral").hue)) {
1795
1704
  return 99;
1796
- } else if (s.variant === "vibrant") {
1705
+ } else if (c.variant.name === "vibrant") {
1797
1706
  return 97;
1798
1707
  } else {
1799
1708
  return 98;
@@ -1803,14 +1712,14 @@ const defaultColors = (colorService) => {
1803
1712
  isBackground: true
1804
1713
  },
1805
1714
  surfaceDim: {
1806
- palette: (s) => s.getPalette("neutral"),
1807
- tone: (s) => {
1808
- if (s.isDark) {
1715
+ palette: () => palettes.get("neutral"),
1716
+ tone: () => {
1717
+ if (c.isDark) {
1809
1718
  return 4;
1810
1719
  } else {
1811
- if (Hct.isYellow(s.getPalette("neutral").hue)) {
1720
+ if (Hct.isYellow(palettes.get("neutral").hue)) {
1812
1721
  return 90;
1813
- } else if (s.variant === "vibrant") {
1722
+ } else if (c.variant.name === "vibrant") {
1814
1723
  return 85;
1815
1724
  } else {
1816
1725
  return 87;
@@ -1818,15 +1727,15 @@ const defaultColors = (colorService) => {
1818
1727
  }
1819
1728
  },
1820
1729
  isBackground: true,
1821
- chromaMultiplier: (s) => {
1822
- if (!s.isDark) {
1823
- if (s.variant === "neutral") {
1730
+ chromaMultiplier: () => {
1731
+ if (!c.isDark) {
1732
+ if (c.variant.name === "neutral") {
1824
1733
  return 2.5;
1825
- } else if (s.variant === "tonalSpot") {
1734
+ } else if (c.variant.name === "tonalSpot") {
1826
1735
  return 1.7;
1827
- } else if (s.variant === "expressive") {
1828
- return Hct.isYellow(s.getPalette("neutral").hue) ? 2.7 : 1.75;
1829
- } 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") {
1830
1739
  return 1.36;
1831
1740
  }
1832
1741
  }
@@ -1834,14 +1743,14 @@ const defaultColors = (colorService) => {
1834
1743
  }
1835
1744
  },
1836
1745
  surfaceBright: {
1837
- palette: (s) => s.getPalette("neutral"),
1838
- tone: (s) => {
1839
- if (s.isDark) {
1746
+ palette: () => palettes.get("neutral"),
1747
+ tone: () => {
1748
+ if (c.isDark) {
1840
1749
  return 18;
1841
1750
  } else {
1842
- if (Hct.isYellow(s.getPalette("neutral").hue)) {
1751
+ if (Hct.isYellow(palettes.get("neutral").hue)) {
1843
1752
  return 99;
1844
- } else if (s.variant === "vibrant") {
1753
+ } else if (c.variant.name === "vibrant") {
1845
1754
  return 97;
1846
1755
  } else {
1847
1756
  return 98;
@@ -1849,15 +1758,15 @@ const defaultColors = (colorService) => {
1849
1758
  }
1850
1759
  },
1851
1760
  isBackground: true,
1852
- chromaMultiplier: (s) => {
1853
- if (s.isDark) {
1854
- if (s.variant === "neutral") {
1761
+ chromaMultiplier: () => {
1762
+ if (c.isDark) {
1763
+ if (c.variant.name === "neutral") {
1855
1764
  return 2.5;
1856
- } else if (s.variant === "tonalSpot") {
1765
+ } else if (c.variant.name === "tonalSpot") {
1857
1766
  return 1.7;
1858
- } else if (s.variant === "expressive") {
1859
- return Hct.isYellow(s.getPalette("neutral").hue) ? 2.7 : 1.75;
1860
- } 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") {
1861
1770
  return 1.36;
1862
1771
  }
1863
1772
  }
@@ -1865,19 +1774,19 @@ const defaultColors = (colorService) => {
1865
1774
  }
1866
1775
  },
1867
1776
  surfaceContainerLowest: {
1868
- palette: (s) => s.getPalette("neutral"),
1869
- tone: (s) => s.isDark ? 0 : 100,
1777
+ palette: () => palettes.get("neutral"),
1778
+ tone: () => c.isDark ? 0 : 100,
1870
1779
  isBackground: true
1871
1780
  },
1872
1781
  surfaceContainerLow: {
1873
- palette: (s) => s.getPalette("neutral"),
1874
- tone: (s) => {
1875
- if (s.isDark) {
1782
+ palette: () => palettes.get("neutral"),
1783
+ tone: () => {
1784
+ if (c.isDark) {
1876
1785
  return 6;
1877
1786
  } else {
1878
- if (Hct.isYellow(s.getPalette("neutral").hue)) {
1787
+ if (Hct.isYellow(palettes.get("neutral").hue)) {
1879
1788
  return 98;
1880
- } else if (s.variant === "vibrant") {
1789
+ } else if (c.variant.name === "vibrant") {
1881
1790
  return 95;
1882
1791
  } else {
1883
1792
  return 96;
@@ -1885,28 +1794,28 @@ const defaultColors = (colorService) => {
1885
1794
  }
1886
1795
  },
1887
1796
  isBackground: true,
1888
- chromaMultiplier: (s) => {
1889
- if (s.variant === "neutral") {
1797
+ chromaMultiplier: () => {
1798
+ if (c.variant.name === "neutral") {
1890
1799
  return 1.3;
1891
- } else if (s.variant === "tonalSpot") {
1800
+ } else if (c.variant.name === "tonalSpot") {
1892
1801
  return 1.25;
1893
- } else if (s.variant === "expressive") {
1894
- return Hct.isYellow(s.getPalette("neutral").hue) ? 1.3 : 1.15;
1895
- } 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") {
1896
1805
  return 1.08;
1897
1806
  }
1898
1807
  return 1;
1899
1808
  }
1900
1809
  },
1901
1810
  surfaceContainer: {
1902
- palette: (s) => s.getPalette("neutral"),
1903
- tone: (s) => {
1904
- if (s.isDark) {
1811
+ palette: () => palettes.get("neutral"),
1812
+ tone: () => {
1813
+ if (c.isDark) {
1905
1814
  return 9;
1906
1815
  } else {
1907
- if (Hct.isYellow(s.getPalette("neutral").hue)) {
1816
+ if (Hct.isYellow(palettes.get("neutral").hue)) {
1908
1817
  return 96;
1909
- } else if (s.variant === "vibrant") {
1818
+ } else if (c.variant.name === "vibrant") {
1910
1819
  return 92;
1911
1820
  } else {
1912
1821
  return 94;
@@ -1914,28 +1823,28 @@ const defaultColors = (colorService) => {
1914
1823
  }
1915
1824
  },
1916
1825
  isBackground: true,
1917
- chromaMultiplier: (s) => {
1918
- if (s.variant === "neutral") {
1826
+ chromaMultiplier: () => {
1827
+ if (c.variant.name === "neutral") {
1919
1828
  return 1.6;
1920
- } else if (s.variant === "tonalSpot") {
1829
+ } else if (c.variant.name === "tonalSpot") {
1921
1830
  return 1.4;
1922
- } else if (s.variant === "expressive") {
1923
- return Hct.isYellow(s.getPalette("neutral").hue) ? 1.6 : 1.3;
1924
- } 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") {
1925
1834
  return 1.15;
1926
1835
  }
1927
1836
  return 1;
1928
1837
  }
1929
1838
  },
1930
1839
  surfaceContainerHigh: {
1931
- palette: (s) => s.getPalette("neutral"),
1932
- tone: (s) => {
1933
- if (s.isDark) {
1840
+ palette: () => palettes.get("neutral"),
1841
+ tone: () => {
1842
+ if (c.isDark) {
1934
1843
  return 12;
1935
1844
  } else {
1936
- if (Hct.isYellow(s.getPalette("neutral").hue)) {
1845
+ if (Hct.isYellow(palettes.get("neutral").hue)) {
1937
1846
  return 94;
1938
- } else if (s.variant === "vibrant") {
1847
+ } else if (c.variant.name === "vibrant") {
1939
1848
  return 90;
1940
1849
  } else {
1941
1850
  return 92;
@@ -1943,28 +1852,28 @@ const defaultColors = (colorService) => {
1943
1852
  }
1944
1853
  },
1945
1854
  isBackground: true,
1946
- chromaMultiplier: (s) => {
1947
- if (s.variant === "neutral") {
1855
+ chromaMultiplier: () => {
1856
+ if (c.variant.name === "neutral") {
1948
1857
  return 1.9;
1949
- } else if (s.variant === "tonalSpot") {
1858
+ } else if (c.variant.name === "tonalSpot") {
1950
1859
  return 1.5;
1951
- } else if (s.variant === "expressive") {
1952
- return Hct.isYellow(s.getPalette("neutral").hue) ? 1.95 : 1.45;
1953
- } 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") {
1954
1863
  return 1.22;
1955
1864
  }
1956
1865
  return 1;
1957
1866
  }
1958
1867
  },
1959
1868
  surfaceContainerHighest: {
1960
- palette: (s) => s.getPalette("neutral"),
1961
- tone: (s) => {
1962
- if (s.isDark) {
1869
+ palette: () => palettes.get("neutral"),
1870
+ tone: () => {
1871
+ if (c.isDark) {
1963
1872
  return 15;
1964
1873
  } else {
1965
- if (Hct.isYellow(s.getPalette("neutral").hue)) {
1874
+ if (Hct.isYellow(palettes.get("neutral").hue)) {
1966
1875
  return 92;
1967
- } else if (s.variant === "vibrant") {
1876
+ } else if (c.variant.name === "vibrant") {
1968
1877
  return 88;
1969
1878
  } else {
1970
1879
  return 90;
@@ -1972,14 +1881,14 @@ const defaultColors = (colorService) => {
1972
1881
  }
1973
1882
  },
1974
1883
  isBackground: true,
1975
- chromaMultiplier: (s) => {
1976
- if (s.variant === "neutral") {
1884
+ chromaMultiplier: () => {
1885
+ if (c.variant.name === "neutral") {
1977
1886
  return 2.2;
1978
- } else if (s.variant === "tonalSpot") {
1887
+ } else if (c.variant.name === "tonalSpot") {
1979
1888
  return 1.7;
1980
- } else if (s.variant === "expressive") {
1981
- return Hct.isYellow(s.getPalette("neutral").hue) ? 2.3 : 1.6;
1982
- } 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") {
1983
1892
  return 1.29;
1984
1893
  } else {
1985
1894
  return 1;
@@ -1987,132 +1896,133 @@ const defaultColors = (colorService) => {
1987
1896
  }
1988
1897
  },
1989
1898
  onSurface: {
1990
- palette: (s) => s.getPalette("neutral"),
1991
- tone: (s) => {
1992
- if (s.variant === "vibrant") {
1993
- 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);
1994
1903
  } else {
1995
- return DynamicColor.getInitialToneFromBackground(
1996
- (s2) => highestSurface(s2, colorService)
1997
- )(s);
1904
+ return getInitialToneFromBackground(highestSurface(c, colors));
1998
1905
  }
1999
1906
  },
2000
- chromaMultiplier: (s) => {
2001
- if (s.variant === "neutral") {
1907
+ chromaMultiplier: () => {
1908
+ if (c.variant.name === "neutral") {
2002
1909
  return 2.2;
2003
- } else if (s.variant === "tonalSpot") {
1910
+ } else if (c.variant.name === "tonalSpot") {
2004
1911
  return 1.7;
2005
- } else if (s.variant === "expressive") {
2006
- 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;
2007
1914
  }
2008
1915
  return 1;
2009
1916
  },
2010
- background: (s) => highestSurface(s, colorService),
2011
- contrastCurve: (s) => s.isDark ? getCurve(11) : getCurve(9)
1917
+ background: () => highestSurface(c, colors),
1918
+ contrastCurve: () => c.isDark ? getCurve(11) : getCurve(9)
2012
1919
  },
2013
1920
  onSurfaceVariant: {
2014
- palette: (s) => s.getPalette("neutralVariant"),
2015
- chromaMultiplier: (s) => {
2016
- if (s.variant === "neutral") {
1921
+ palette: () => palettes.get("neutralVariant"),
1922
+ chromaMultiplier: () => {
1923
+ if (c.variant.name === "neutral") {
2017
1924
  return 2.2;
2018
- } else if (s.variant === "tonalSpot") {
1925
+ } else if (c.variant.name === "tonalSpot") {
2019
1926
  return 1.7;
2020
- } else if (s.variant === "expressive") {
2021
- 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;
2022
1929
  }
2023
1930
  return 1;
2024
1931
  },
2025
- background: (s) => highestSurface(s, colorService),
2026
- contrastCurve: (s) => s.isDark ? getCurve(6) : getCurve(4.5)
1932
+ background: () => highestSurface(c, colors),
1933
+ contrastCurve: () => c.isDark ? getCurve(6) : getCurve(4.5)
2027
1934
  },
2028
1935
  outline: {
2029
- palette: (s) => s.getPalette("neutralVariant"),
2030
- chromaMultiplier: (s) => {
2031
- if (s.variant === "neutral") {
1936
+ palette: () => palettes.get("neutralVariant"),
1937
+ chromaMultiplier: () => {
1938
+ if (c.variant.name === "neutral") {
2032
1939
  return 2.2;
2033
- } else if (s.variant === "tonalSpot") {
1940
+ } else if (c.variant.name === "tonalSpot") {
2034
1941
  return 1.7;
2035
- } else if (s.variant === "expressive") {
2036
- 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;
2037
1944
  }
2038
1945
  return 1;
2039
1946
  },
2040
- background: (s) => highestSurface(s, colorService),
2041
- contrastCurve: (s) => getCurve(3)
1947
+ background: () => highestSurface(c, colors),
1948
+ contrastCurve: () => getCurve(3)
2042
1949
  },
2043
1950
  outlineVariant: {
2044
- palette: (s) => s.getPalette("neutralVariant"),
2045
- chromaMultiplier: (s) => {
2046
- if (s.variant === "neutral") {
1951
+ palette: () => palettes.get("neutralVariant"),
1952
+ chromaMultiplier: () => {
1953
+ if (c.variant.name === "neutral") {
2047
1954
  return 2.2;
2048
- } else if (s.variant === "tonalSpot") {
1955
+ } else if (c.variant.name === "tonalSpot") {
2049
1956
  return 1.7;
2050
- } else if (s.variant === "expressive") {
2051
- 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;
2052
1959
  }
2053
1960
  return 1;
2054
1961
  },
2055
- background: (s) => highestSurface(s, colorService),
2056
- contrastCurve: (s) => getCurve(1.5)
1962
+ background: () => highestSurface(c, colors),
1963
+ contrastCurve: () => getCurve(1.5)
2057
1964
  },
2058
1965
  inverseSurface: {
2059
- palette: (s) => s.getPalette("neutral"),
2060
- tone: (s) => s.isDark ? 98 : 4,
1966
+ palette: () => palettes.get("neutral"),
1967
+ tone: () => c.isDark ? 98 : 4,
2061
1968
  isBackground: true
2062
1969
  },
2063
1970
  inverseOnSurface: {
2064
- palette: (s) => s.getPalette("neutral"),
2065
- tone: (s) => s.isDark ? 20 : 95,
2066
- background: (s) => colorService.getColor("inverseSurface").getMaterialColor(),
2067
- contrastCurve: (s) => getCurve(7)
1971
+ palette: () => palettes.get("neutral"),
1972
+ tone: () => c.isDark ? 20 : 95,
1973
+ background: () => colors.get("inverseSurface"),
1974
+ contrastCurve: () => getCurve(7)
2068
1975
  },
2069
1976
  ////////////////////////////////////////////////////////////////
2070
1977
  // Primaries [P] //
2071
1978
  ////////////////////////////////////////////////////////////////
2072
1979
  primary: {
2073
- palette: (s) => s.getPalette("primary"),
2074
- tone: (s) => {
2075
- if (s.variant === "neutral") {
2076
- return s.isDark ? 80 : 40;
2077
- } else if (s.variant === "tonalSpot") {
2078
- 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) {
2079
1986
  return 80;
2080
1987
  } else {
2081
- return tMaxC(s.getPalette("primary"));
1988
+ return tMaxC(palettes.get("primary"));
2082
1989
  }
2083
- } else if (s.variant === "expressive") {
1990
+ } else if (c.variant.name === "expressive") {
2084
1991
  return tMaxC(
2085
- s.getPalette("primary"),
1992
+ palettes.get("primary"),
2086
1993
  0,
2087
- 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
2088
1995
  );
2089
- } else if (s.variant == "fidelity") {
2090
- return s.sourceColorHct.tone;
1996
+ } else if (c.variant.name == "fidelity") {
1997
+ return c.sourceColor.tone;
2091
1998
  } else {
2092
1999
  return tMaxC(
2093
- s.getPalette("primary"),
2000
+ palettes.get("primary"),
2094
2001
  0,
2095
- Hct.isCyan(s.getPalette("primary").hue) ? 88 : 98
2002
+ Hct.isCyan(palettes.get("primary").hue) ? 88 : 98
2096
2003
  );
2097
2004
  }
2098
2005
  },
2099
2006
  isBackground: true,
2100
- background: (s) => highestSurface(s, colorService),
2101
- contrastCurve: (s) => getCurve(4.5),
2102
- adjustTone: (s) => s.variant == "fidelity" ? () => {
2103
- const surfaceTone = colorService.getColor("surface").getMaterialColor().tone(s);
2104
- 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;
2105
2012
  let selfTone = primaryTone;
2106
2013
  if (Contrast.ratioOfTones(surfaceTone, selfTone) < 3) {
2107
- const result = inverseTone(primaryTone);
2108
- if (Contrast.ratioOfTones(surfaceTone, result) >= 3) {
2109
- selfTone = result;
2110
- }
2014
+ const ratio = calculateToneAdjustmentPercentage(
2015
+ surfaceTone,
2016
+ selfTone,
2017
+ 3
2018
+ );
2019
+ const inverseT = inverseTone(primaryTone);
2020
+ selfTone = selfTone + (inverseT - selfTone) * ratio;
2111
2021
  }
2112
2022
  return selfTone;
2113
2023
  } : toneDeltaPair(
2114
- colorService.getColor("primaryContainer").getMaterialColor(),
2115
- colorService.getColor("primary").getMaterialColor(),
2024
+ colors.get("primaryContainer"),
2025
+ colors.get("primary"),
2116
2026
  5,
2117
2027
  "relative_lighter",
2118
2028
  true,
@@ -2120,22 +2030,22 @@ const defaultColors = (colorService) => {
2120
2030
  )
2121
2031
  },
2122
2032
  primaryDim: {
2123
- palette: (s) => s.getPalette("primary"),
2124
- tone: (s) => {
2125
- if (s.variant === "neutral") {
2033
+ palette: () => palettes.get("primary"),
2034
+ tone: () => {
2035
+ if (c.variant.name === "neutral") {
2126
2036
  return 85;
2127
- } else if (s.variant === "tonalSpot") {
2128
- return tMaxC(s.getPalette("primary"), 0, 90);
2037
+ } else if (c.variant.name === "tonalSpot") {
2038
+ return tMaxC(palettes.get("primary"), 0, 90);
2129
2039
  } else {
2130
- return tMaxC(s.getPalette("primary"));
2040
+ return tMaxC(palettes.get("primary"));
2131
2041
  }
2132
2042
  },
2133
2043
  isBackground: true,
2134
- background: (s) => getColor("surfaceContainerHigh"),
2135
- contrastCurve: (s) => getCurve(4.5),
2136
- adjustTone: (s) => toneDeltaPair(
2137
- colorService.getColor("primaryDim").getMaterialColor(),
2138
- colorService.getColor("primary").getMaterialColor(),
2044
+ background: () => getColor("surfaceContainerHigh"),
2045
+ contrastCurve: () => getCurve(4.5),
2046
+ adjustTone: () => toneDeltaPair(
2047
+ colors.get("primaryDim"),
2048
+ colors.get("primary"),
2139
2049
  5,
2140
2050
  "darker",
2141
2051
  true,
@@ -2143,74 +2053,74 @@ const defaultColors = (colorService) => {
2143
2053
  )
2144
2054
  },
2145
2055
  onPrimary: {
2146
- palette: (s) => s.getPalette("primary"),
2147
- background: (s) => colorService.getColor("primary").getMaterialColor(),
2148
- contrastCurve: (s) => getCurve(6)
2056
+ palette: () => palettes.get("primary"),
2057
+ background: () => colors.get("primary"),
2058
+ contrastCurve: () => getCurve(6)
2149
2059
  },
2150
2060
  primaryContainer: {
2151
- palette: (s) => s.getPalette("primary"),
2152
- tone: (s) => {
2153
- if (s.variant === "neutral") {
2154
- return s.isDark ? 30 : 90;
2155
- } else if (s.variant === "tonalSpot") {
2156
- return s.isDark ? tMinC(s.getPalette("primary"), 35, 93) : tMaxC(s.getPalette("primary"), 0, 90);
2157
- } else if (s.variant === "expressive") {
2158
- return s.isDark ? tMaxC(s.getPalette("primary"), 30, 93) : tMaxC(
2159
- 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"),
2160
2070
  78,
2161
- Hct.isCyan(s.getPalette("primary").hue) ? 88 : 90
2071
+ Hct.isCyan(palettes.get("primary").hue) ? 88 : 90
2162
2072
  );
2163
2073
  }
2164
- if (s.variant == "fidelity") {
2165
- return s.isDark ? tMaxC(s.getPalette("primary"), 30, 93) : tMaxC(
2166
- s.getPalette("primary"),
2167
- 78,
2168
- Hct.isCyan(s.getPalette("primary").hue) ? 88 : 90
2169
- );
2074
+ if (c.variant.name == "fidelity") {
2075
+ return c.isDark ? tMinC(palettes.get("primary"), 35, 93) : tMaxC(palettes.get("primary"), 0, 90);
2170
2076
  } else {
2171
- return s.isDark ? tMinC(s.getPalette("primary"), 66, 93) : tMaxC(
2172
- s.getPalette("primary"),
2077
+ return c.isDark ? tMinC(palettes.get("primary"), 66, 93) : tMaxC(
2078
+ palettes.get("primary"),
2173
2079
  66,
2174
- Hct.isCyan(s.getPalette("primary").hue) ? 88 : 93
2080
+ Hct.isCyan(palettes.get("primary").hue) ? 88 : 93
2175
2081
  );
2176
2082
  }
2177
2083
  },
2178
2084
  isBackground: true,
2179
- background: (s) => highestSurface(s, colorService),
2180
- adjustTone: (s) => s.variant == "fidelity" ? toneDeltaPair(
2181
- colorService.getColor("primary").getMaterialColor(),
2182
- colorService.getColor("primaryContainer").getMaterialColor(),
2085
+ background: () => highestSurface(c, colors),
2086
+ adjustTone: () => c.variant.name == "fidelity" ? toneDeltaPair(
2087
+ colors.get("primary"),
2088
+ colors.get("primaryContainer"),
2183
2089
  15,
2184
2090
  "relative_darker",
2185
2091
  true,
2186
2092
  "farther"
2187
2093
  ) : void 0,
2188
- contrastCurve: (s) => s.contrastLevel > 0 ? getCurve(1.5) : void 0
2094
+ contrastCurve: () => c.contrastLevel > 0 ? getCurve(1.5) : void 0
2189
2095
  },
2190
2096
  onPrimaryContainer: {
2191
- palette: (s) => s.getPalette("primary"),
2192
- background: (s) => colorService.getColor("primaryContainer").getMaterialColor(),
2193
- contrastCurve: (s) => getCurve(6)
2097
+ palette: () => palettes.get("primary"),
2098
+ background: () => colors.get("primaryContainer"),
2099
+ contrastCurve: () => getCurve(6)
2194
2100
  },
2195
2101
  primaryFixed: {
2196
- palette: (s) => s.getPalette("primary"),
2197
- tone: (s) => {
2198
- const tempS = new Scheme({
2199
- ...s.options,
2200
- isDark: false,
2201
- contrastLevel: 0
2202
- });
2203
- 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
+ );
2204
2114
  },
2205
2115
  isBackground: true,
2206
- background: (s) => highestSurface(s, colorService),
2207
- 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
2208
2118
  },
2209
2119
  primaryFixedDim: {
2210
- palette: (s) => s.getPalette("primary"),
2211
- tone: (s) => colorService.getColor("primaryFixed").getMaterialColor().getTone(s),
2120
+ palette: () => palettes.get("primary"),
2121
+ tone: () => colors.get("primaryFixed").getTone(),
2212
2122
  isBackground: true,
2213
- adjustTone: (s) => toneDeltaPair(
2123
+ adjustTone: () => toneDeltaPair(
2214
2124
  getColor("primaryFixedDim"),
2215
2125
  getColor("primaryFixed"),
2216
2126
  5,
@@ -2220,39 +2130,39 @@ const defaultColors = (colorService) => {
2220
2130
  )
2221
2131
  },
2222
2132
  onPrimaryFixed: {
2223
- palette: (s) => s.getPalette("primary"),
2224
- background: (s) => colorService.getColor("primaryFixedDim").getMaterialColor(),
2225
- contrastCurve: (s) => getCurve(7)
2133
+ palette: () => palettes.get("primary"),
2134
+ background: () => colors.get("primaryFixedDim"),
2135
+ contrastCurve: () => getCurve(7)
2226
2136
  },
2227
2137
  onPrimaryFixedVariant: {
2228
- palette: (s) => s.getPalette("primary"),
2229
- background: (s) => colorService.getColor("primaryFixedDim").getMaterialColor(),
2230
- contrastCurve: (s) => getCurve(4.5)
2138
+ palette: () => palettes.get("primary"),
2139
+ background: () => colors.get("primaryFixedDim"),
2140
+ contrastCurve: () => getCurve(4.5)
2231
2141
  },
2232
2142
  inversePrimary: {
2233
- palette: (s) => s.getPalette("primary"),
2234
- tone: (s) => tMaxC(s.getPalette("primary")),
2235
- background: (s) => colorService.getColor("inverseSurface").getMaterialColor(),
2236
- contrastCurve: (s) => getCurve(6)
2143
+ palette: () => palettes.get("primary"),
2144
+ tone: () => tMaxC(palettes.get("primary")),
2145
+ background: () => colors.get("inverseSurface"),
2146
+ contrastCurve: () => getCurve(6)
2237
2147
  },
2238
2148
  ////////////////////////////////////////////////////////////////
2239
2149
  // Secondaries [Q] //
2240
2150
  ////////////////////////////////////////////////////////////////
2241
2151
  secondary: {
2242
- palette: (s) => s.getPalette("secondary"),
2243
- tone: (s) => {
2244
- if (s.variant === "neutral") {
2245
- return s.isDark ? tMinC(s.getPalette("secondary"), 0, 98) : tMaxC(s.getPalette("secondary"));
2246
- } else if (s.variant === "vibrant") {
2247
- 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);
2248
2158
  } else {
2249
- return s.isDark ? 80 : tMaxC(s.getPalette("secondary"));
2159
+ return c.isDark ? 80 : tMaxC(palettes.get("secondary"));
2250
2160
  }
2251
2161
  },
2252
2162
  isBackground: true,
2253
- background: (s) => highestSurface(s, colorService),
2254
- contrastCurve: (s) => getCurve(4.5),
2255
- adjustTone: (s) => toneDeltaPair(
2163
+ background: () => highestSurface(c, colors),
2164
+ contrastCurve: () => getCurve(4.5),
2165
+ adjustTone: () => toneDeltaPair(
2256
2166
  getColor("secondaryContainer"),
2257
2167
  getColor("secondary"),
2258
2168
  5,
@@ -2262,18 +2172,18 @@ const defaultColors = (colorService) => {
2262
2172
  )
2263
2173
  },
2264
2174
  secondaryDim: {
2265
- palette: (s) => s.getPalette("secondary"),
2266
- tone: (s) => {
2267
- if (s.variant === "neutral") {
2175
+ palette: () => palettes.get("secondary"),
2176
+ tone: () => {
2177
+ if (c.variant.name === "neutral") {
2268
2178
  return 85;
2269
2179
  } else {
2270
- return tMaxC(s.getPalette("secondary"), 0, 90);
2180
+ return tMaxC(palettes.get("secondary"), 0, 90);
2271
2181
  }
2272
2182
  },
2273
2183
  isBackground: true,
2274
- background: (s) => getColor("surfaceContainerHigh"),
2275
- contrastCurve: (s) => getCurve(4.5),
2276
- adjustTone: (s) => toneDeltaPair(
2184
+ background: () => getColor("surfaceContainerHigh"),
2185
+ contrastCurve: () => getCurve(4.5),
2186
+ adjustTone: () => toneDeltaPair(
2277
2187
  getColor("secondaryDim"),
2278
2188
  getColor("secondary"),
2279
2189
  5,
@@ -2283,50 +2193,54 @@ const defaultColors = (colorService) => {
2283
2193
  )
2284
2194
  },
2285
2195
  onSecondary: {
2286
- palette: (s) => s.getPalette("secondary"),
2287
- background: (s) => getColor("secondary"),
2288
- contrastCurve: (s) => getCurve(6)
2196
+ palette: () => palettes.get("secondary"),
2197
+ background: () => getColor("secondary"),
2198
+ contrastCurve: () => getCurve(6)
2289
2199
  },
2290
2200
  secondaryContainer: {
2291
- palette: (s) => s.getPalette("secondary"),
2292
- tone: (s) => {
2293
- if (s.variant === "vibrant") {
2294
- return s.isDark ? tMinC(s.getPalette("secondary"), 30, 40) : tMaxC(s.getPalette("secondary"), 84, 90);
2295
- } else if (s.variant === "expressive") {
2296
- 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);
2297
2207
  } else {
2298
- return s.isDark ? 25 : 90;
2208
+ return c.isDark ? 25 : 90;
2299
2209
  }
2300
2210
  },
2301
2211
  isBackground: true,
2302
- background: (s) => highestSurface(s, colorService),
2303
- adjustTone: (s) => void 0,
2304
- 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
2305
2215
  },
2306
2216
  onSecondaryContainer: {
2307
- palette: (s) => s.getPalette("secondary"),
2308
- background: (s) => getColor("secondaryContainer"),
2309
- contrastCurve: (s) => getCurve(6)
2217
+ palette: () => palettes.get("secondary"),
2218
+ background: () => getColor("secondaryContainer"),
2219
+ contrastCurve: () => getCurve(6)
2310
2220
  },
2311
2221
  secondaryFixed: {
2312
- palette: (s) => s.getPalette("secondary"),
2313
- tone: (s) => {
2314
- const tempS = new Scheme({
2315
- ...s.options,
2316
- isDark: false,
2317
- contrastLevel: 0
2318
- });
2319
- 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
+ );
2320
2234
  },
2321
2235
  isBackground: true,
2322
- background: (s) => highestSurface(s, colorService),
2323
- 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
2324
2238
  },
2325
2239
  secondaryFixedDim: {
2326
- palette: (s) => s.getPalette("secondary"),
2327
- tone: (s) => getColor("secondaryFixed").getTone(s),
2240
+ palette: () => palettes.get("secondary"),
2241
+ tone: () => getColor("secondaryFixed").getTone(),
2328
2242
  isBackground: true,
2329
- adjustTone: (s) => toneDeltaPair(
2243
+ adjustTone: () => toneDeltaPair(
2330
2244
  getColor("secondaryFixedDim"),
2331
2245
  getColor("secondaryFixed"),
2332
2246
  5,
@@ -2336,35 +2250,35 @@ const defaultColors = (colorService) => {
2336
2250
  )
2337
2251
  },
2338
2252
  onSecondaryFixed: {
2339
- palette: (s) => s.getPalette("secondary"),
2340
- background: (s) => getColor("secondaryFixedDim"),
2341
- contrastCurve: (s) => getCurve(7)
2253
+ palette: () => palettes.get("secondary"),
2254
+ background: () => getColor("secondaryFixedDim"),
2255
+ contrastCurve: () => getCurve(7)
2342
2256
  },
2343
2257
  onSecondaryFixedVariant: {
2344
- palette: (s) => s.getPalette("secondary"),
2345
- background: (s) => getColor("secondaryFixedDim"),
2346
- contrastCurve: (s) => getCurve(4.5)
2258
+ palette: () => palettes.get("secondary"),
2259
+ background: () => getColor("secondaryFixedDim"),
2260
+ contrastCurve: () => getCurve(4.5)
2347
2261
  },
2348
2262
  ////////////////////////////////////////////////////////////////
2349
2263
  // Tertiaries [T] //
2350
2264
  ////////////////////////////////////////////////////////////////
2351
2265
  tertiary: {
2352
- palette: (s) => s.getPalette("tertiary"),
2353
- tone: (s) => {
2354
- if (s.variant === "expressive" || s.variant === "vibrant") {
2266
+ palette: () => palettes.get("tertiary"),
2267
+ tone: () => {
2268
+ if (c.variant.name === "expressive" || c.variant.name === "vibrant") {
2355
2269
  return tMaxC(
2356
- s.getPalette("tertiary"),
2270
+ palettes.get("tertiary"),
2357
2271
  0,
2358
- Hct.isCyan(s.getPalette("tertiary").hue) ? 88 : s.isDark ? 98 : 100
2272
+ Hct.isCyan(palettes.get("tertiary").hue) ? 88 : c.isDark ? 98 : 100
2359
2273
  );
2360
2274
  } else {
2361
- 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"));
2362
2276
  }
2363
2277
  },
2364
2278
  isBackground: true,
2365
- background: (s) => highestSurface(s, colorService),
2366
- contrastCurve: (s) => getCurve(4.5),
2367
- adjustTone: (s) => toneDeltaPair(
2279
+ background: () => highestSurface(c, colors),
2280
+ contrastCurve: () => getCurve(4.5),
2281
+ adjustTone: () => toneDeltaPair(
2368
2282
  getColor("tertiaryContainer"),
2369
2283
  getColor("tertiary"),
2370
2284
  5,
@@ -2374,18 +2288,18 @@ const defaultColors = (colorService) => {
2374
2288
  )
2375
2289
  },
2376
2290
  tertiaryDim: {
2377
- palette: (s) => s.getPalette("tertiary"),
2378
- tone: (s) => {
2379
- if (s.variant === "tonalSpot") {
2380
- 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);
2381
2295
  } else {
2382
- return tMaxC(s.getPalette("tertiary"));
2296
+ return tMaxC(palettes.get("tertiary"));
2383
2297
  }
2384
2298
  },
2385
2299
  isBackground: true,
2386
- background: (s) => getColor("surfaceContainerHigh"),
2387
- contrastCurve: (s) => getCurve(4.5),
2388
- adjustTone: (s) => toneDeltaPair(
2300
+ background: () => getColor("surfaceContainerHigh"),
2301
+ contrastCurve: () => getCurve(4.5),
2302
+ adjustTone: () => toneDeltaPair(
2389
2303
  getColor("tertiaryDim"),
2390
2304
  getColor("tertiary"),
2391
2305
  5,
@@ -2395,56 +2309,60 @@ const defaultColors = (colorService) => {
2395
2309
  )
2396
2310
  },
2397
2311
  onTertiary: {
2398
- palette: (s) => s.getPalette("tertiary"),
2399
- background: (s) => getColor("tertiary"),
2400
- contrastCurve: (s) => getCurve(6)
2312
+ palette: () => palettes.get("tertiary"),
2313
+ background: () => getColor("tertiary"),
2314
+ contrastCurve: () => getCurve(6)
2401
2315
  },
2402
2316
  tertiaryContainer: {
2403
- palette: (s) => s.getPalette("tertiary"),
2404
- tone: (s) => {
2405
- if (s.variant === "neutral") {
2406
- return s.isDark ? tMaxC(s.getPalette("tertiary"), 0, 93) : tMaxC(s.getPalette("tertiary"), 0, 96);
2407
- } else if (s.variant === "tonalSpot") {
2408
- return tMaxC(s.getPalette("tertiary"), 0, s.isDark ? 93 : 100);
2409
- } 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") {
2410
2324
  return tMaxC(
2411
- s.getPalette("tertiary"),
2325
+ palettes.get("tertiary"),
2412
2326
  75,
2413
- Hct.isCyan(s.getPalette("tertiary").hue) ? 88 : s.isDark ? 93 : 100
2327
+ Hct.isCyan(palettes.get("tertiary").hue) ? 88 : c.isDark ? 93 : 100
2414
2328
  );
2415
2329
  } else {
2416
- 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);
2417
2331
  }
2418
2332
  },
2419
2333
  isBackground: true,
2420
- background: (s) => highestSurface(s, colorService),
2421
- adjustTone: (s) => void 0,
2422
- 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
2423
2337
  },
2424
2338
  onTertiaryContainer: {
2425
- palette: (s) => s.getPalette("tertiary"),
2426
- background: (s) => getColor("tertiaryContainer"),
2427
- contrastCurve: (s) => getCurve(6)
2339
+ palette: () => palettes.get("tertiary"),
2340
+ background: () => getColor("tertiaryContainer"),
2341
+ contrastCurve: () => getCurve(6)
2428
2342
  },
2429
2343
  tertiaryFixed: {
2430
- palette: (s) => s.getPalette("tertiary"),
2431
- tone: (s) => {
2432
- const tempS = new Scheme({
2433
- ...s.options,
2434
- isDark: false,
2435
- contrastLevel: 0
2436
- });
2437
- 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
+ );
2438
2356
  },
2439
2357
  isBackground: true,
2440
- background: (s) => highestSurface(s, colorService),
2441
- 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
2442
2360
  },
2443
2361
  tertiaryFixedDim: {
2444
- palette: (s) => s.getPalette("tertiary"),
2445
- tone: (s) => getColor("tertiaryFixed").getTone(s),
2362
+ palette: () => palettes.get("tertiary"),
2363
+ tone: () => getColor("tertiaryFixed").getTone(),
2446
2364
  isBackground: true,
2447
- adjustTone: (s) => toneDeltaPair(
2365
+ adjustTone: () => toneDeltaPair(
2448
2366
  getColor("tertiaryFixedDim"),
2449
2367
  getColor("tertiaryFixed"),
2450
2368
  5,
@@ -2454,29 +2372,29 @@ const defaultColors = (colorService) => {
2454
2372
  )
2455
2373
  },
2456
2374
  onTertiaryFixed: {
2457
- palette: (s) => s.getPalette("tertiary"),
2458
- background: (s) => getColor("tertiaryFixedDim"),
2459
- contrastCurve: (s) => getCurve(7)
2375
+ palette: () => palettes.get("tertiary"),
2376
+ background: () => getColor("tertiaryFixedDim"),
2377
+ contrastCurve: () => getCurve(7)
2460
2378
  },
2461
2379
  onTertiaryFixedVariant: {
2462
- palette: (s) => s.getPalette("tertiary"),
2463
- background: (s) => getColor("tertiaryFixedDim"),
2464
- contrastCurve: (s) => getCurve(4.5)
2380
+ palette: () => palettes.get("tertiary"),
2381
+ background: () => getColor("tertiaryFixedDim"),
2382
+ contrastCurve: () => getCurve(4.5)
2465
2383
  },
2466
2384
  ////////////////////////////////////////////////////////////////
2467
2385
  // Errors [E] //
2468
2386
  ////////////////////////////////////////////////////////////////
2469
2387
  error: {
2470
- palette: (s) => s.getPalette("error"),
2471
- tone: (s) => {
2472
- 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"));
2473
2391
  },
2474
2392
  isBackground: true,
2475
- background: (s) => highestSurface(s, colorService),
2476
- contrastCurve: (s) => getCurve(4.5),
2477
- adjustTone: (s) => toneDeltaPair(
2478
- colorService.getColor("errorContainer").getMaterialColor(),
2479
- 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"),
2480
2398
  5,
2481
2399
  "relative_lighter",
2482
2400
  true,
@@ -2484,12 +2402,12 @@ const defaultColors = (colorService) => {
2484
2402
  )
2485
2403
  },
2486
2404
  errorDim: {
2487
- palette: (s) => s.getPalette("error"),
2488
- tone: (s) => tMinC(s.getPalette("error")),
2405
+ palette: () => palettes.get("error"),
2406
+ tone: () => tMinC(palettes.get("error")),
2489
2407
  isBackground: true,
2490
- background: (s) => getColor("surfaceContainerHigh"),
2491
- contrastCurve: (s) => getCurve(4.5),
2492
- adjustTone: (s) => toneDeltaPair(
2408
+ background: () => getColor("surfaceContainerHigh"),
2409
+ contrastCurve: () => getCurve(4.5),
2410
+ adjustTone: () => toneDeltaPair(
2493
2411
  getColor("errorDim"),
2494
2412
  getColor("error"),
2495
2413
  5,
@@ -2499,24 +2417,24 @@ const defaultColors = (colorService) => {
2499
2417
  )
2500
2418
  },
2501
2419
  onError: {
2502
- palette: (s) => s.getPalette("error"),
2503
- background: (s) => colorService.getColor("error").getMaterialColor(),
2504
- contrastCurve: (s) => getCurve(6)
2420
+ palette: () => palettes.get("error"),
2421
+ background: () => colors.get("error"),
2422
+ contrastCurve: () => getCurve(6)
2505
2423
  },
2506
2424
  errorContainer: {
2507
- palette: (s) => s.getPalette("error"),
2508
- tone: (s) => {
2509
- 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);
2510
2428
  },
2511
2429
  isBackground: true,
2512
- background: (s) => highestSurface(s, colorService),
2513
- adjustTone: (s) => void 0,
2514
- 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
2515
2433
  },
2516
2434
  onErrorContainer: {
2517
- palette: (s) => s.getPalette("error"),
2518
- background: (s) => colorService.getColor("errorContainer").getMaterialColor(),
2519
- contrastCurve: (s) => getCurve(4.5)
2435
+ palette: () => palettes.get("error"),
2436
+ background: () => colors.get("errorContainer"),
2437
+ contrastCurve: () => getCurve(4.5)
2520
2438
  },
2521
2439
  /////////////////////////////////////////////////////////////////
2522
2440
  // Remapped Colors //
@@ -2534,27 +2452,7 @@ const defaultColors = (colorService) => {
2534
2452
  alias: "onSurface"
2535
2453
  }
2536
2454
  };
2537
- return {
2538
- colors
2539
- };
2540
2455
  };
2541
- class API {
2542
- constructor({
2543
- colorApi,
2544
- themeApi,
2545
- pluginApi
2546
- }) {
2547
- __publicField(this, "colors");
2548
- __publicField(this, "themes");
2549
- __publicField(this, "plugins");
2550
- this.plugins = pluginApi;
2551
- this.colors = colorApi;
2552
- this.themes = themeApi;
2553
- }
2554
- async load() {
2555
- return this.plugins.loadPlugins();
2556
- }
2557
- }
2558
2456
  const AppModule = {
2559
2457
  api: asClass(API).singleton()
2560
2458
  };
@@ -2601,54 +2499,650 @@ class PluginApi {
2601
2499
  const PluginModule = {
2602
2500
  pluginApi: asClass(PluginApi).singleton()
2603
2501
  };
2604
- function registerModule(...modules) {
2605
- modules.forEach((module) => {
2606
- Object.entries(module).forEach(([name, moduleClass]) => {
2607
- 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
+ }
2608
2511
  });
2609
- });
2610
- 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
+ }
2611
2632
  }
2612
- const AppContainer = createContainer({
2613
- injectionMode: InjectionMode.PROXY
2614
- });
2615
- registerModule(AppModule, PluginModule, ColorModule, ThemeModule);
2616
- function bootstrap() {
2617
- 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
+ }
2618
2732
  }
2619
- const initializeApi = () => {
2620
- const api = bootstrap();
2621
- registerModule({
2622
- 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
2623
2824
  });
2624
- 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;
2625
2846
  };
2626
- const loader = async (config) => {
2627
- const api = initializeApi();
2847
+ const getRotatedHue = (sourceColor, hueBreakpoints, rotations) => {
2848
+ let rotation = getPiecewiseHue(sourceColor, hueBreakpoints, rotations);
2849
+ if (Math.min(hueBreakpoints.length - 1, rotations.length) <= 0) {
2850
+ rotation = 0;
2851
+ }
2852
+ return sanitizeDegreesDouble(sourceColor.hue + rotation);
2853
+ };
2854
+ class Variant {
2855
+ constructor(options) {
2856
+ __publicField(this, "_palettes");
2857
+ __publicField(this, "customPalettes");
2858
+ __publicField(this, "colors");
2859
+ __publicField(this, "name");
2860
+ __publicField(this, "context");
2861
+ this.options = options;
2862
+ this.customPalettes = options.customPalettes;
2863
+ this.colors = options.colors || {};
2864
+ this.name = options.name;
2865
+ }
2866
+ get palettes() {
2867
+ if (!this._palettes) {
2868
+ throw new Error("Variant not initialized");
2869
+ }
2870
+ return this._palettes;
2871
+ }
2872
+ init(context) {
2873
+ if (this.context) return;
2874
+ this.context = context;
2875
+ this._palettes = Object.entries(this.options.palettes).reduce(
2876
+ (acc, [key, callback]) => ({
2877
+ ...acc,
2878
+ [key]: new Palette(key, callback, context)
2879
+ }),
2880
+ {}
2881
+ );
2882
+ }
2883
+ }
2884
+ const variant = (args) => new Variant(args);
2885
+ const getExpressiveNeutralHue = (sourceColor) => {
2886
+ const hue = getRotatedHue(
2887
+ sourceColor,
2888
+ [0, 71, 124, 253, 278, 300, 360],
2889
+ [10, 0, 10, 0, 10, 0]
2890
+ );
2891
+ return hue;
2892
+ };
2893
+ const getExpressiveNeutralChroma = (sourceColor, isDark) => {
2894
+ const neutralHue = getExpressiveNeutralHue(sourceColor);
2895
+ return isDark ? Hct.isYellow(neutralHue) ? 6 : 14 : 18;
2896
+ };
2897
+ const expressiveVariant = variant({
2898
+ name: "expressive",
2899
+ palettes: {
2900
+ primary: ({ sourceColor, isDark }) => ({
2901
+ hue: sourceColor.hue,
2902
+ chroma: isDark ? 36 : 48
2903
+ }),
2904
+ secondary: ({ sourceColor, isDark }) => ({
2905
+ hue: getRotatedHue(
2906
+ sourceColor,
2907
+ [0, 105, 140, 204, 253, 278, 300, 333, 360],
2908
+ [-160, 155, -100, 96, -96, -156, -165, -160]
2909
+ ),
2910
+ chroma: isDark ? 16 : 24
2911
+ }),
2912
+ tertiary: ({ sourceColor }) => TonalPalette.fromHueAndChroma(
2913
+ getRotatedHue(
2914
+ sourceColor,
2915
+ [0, 105, 140, 204, 253, 278, 300, 333, 360],
2916
+ [-165, 160, -105, 101, -101, -160, -170, -165]
2917
+ ),
2918
+ 48
2919
+ ),
2920
+ neutral: ({ sourceColor, isDark }) => TonalPalette.fromHueAndChroma(
2921
+ getExpressiveNeutralHue(sourceColor),
2922
+ getExpressiveNeutralChroma(sourceColor, isDark)
2923
+ ),
2924
+ neutralVariant: ({ sourceColor, isDark }) => {
2925
+ const expressiveNeutralHue = getExpressiveNeutralHue(sourceColor);
2926
+ const expressiveNeutralChroma = getExpressiveNeutralChroma(
2927
+ sourceColor,
2928
+ isDark
2929
+ );
2930
+ return TonalPalette.fromHueAndChroma(
2931
+ expressiveNeutralHue,
2932
+ expressiveNeutralChroma * (expressiveNeutralHue >= 105 && expressiveNeutralHue < 125 ? 1.6 : 2.3)
2933
+ );
2934
+ },
2935
+ error: ({ sourceColor }) => {
2936
+ const errorHue = getPiecewiseHue(
2937
+ sourceColor,
2938
+ [0, 3, 13, 23, 33, 43, 153, 273, 360],
2939
+ [12, 22, 32, 12, 22, 32, 22, 12]
2940
+ );
2941
+ return TonalPalette.fromHueAndChroma(errorHue, 64);
2942
+ }
2943
+ },
2944
+ customPalettes: ({ isDark }, color) => TonalPalette.fromHueAndChroma(
2945
+ getRotatedHue(
2946
+ color,
2947
+ [0, 105, 140, 204, 253, 278, 300, 333, 360],
2948
+ [-160, 155, -100, 96, -96, -156, -165, -160]
2949
+ ),
2950
+ isDark ? 16 : 24
2951
+ )
2952
+ });
2953
+ const neutralVariant = variant({
2954
+ name: "neutral",
2955
+ palettes: {
2956
+ primary: ({ sourceColor }) => TonalPalette.fromHueAndChroma(
2957
+ sourceColor.hue,
2958
+ Hct.isBlue(sourceColor.hue) ? 12 : 8
2959
+ ),
2960
+ secondary: ({ sourceColor }) => TonalPalette.fromHueAndChroma(
2961
+ sourceColor.hue,
2962
+ Hct.isBlue(sourceColor.hue) ? 6 : 4
2963
+ ),
2964
+ tertiary: ({ sourceColor }) => TonalPalette.fromHueAndChroma(
2965
+ getRotatedHue(
2966
+ sourceColor,
2967
+ [0, 38, 105, 161, 204, 278, 333, 360],
2968
+ [-32, 26, 10, -39, 24, -15, -32]
2969
+ ),
2970
+ 20
2971
+ ),
2972
+ neutral: ({ sourceColor }) => TonalPalette.fromHueAndChroma(sourceColor.hue, 1.4),
2973
+ neutralVariant: ({ sourceColor }) => TonalPalette.fromHueAndChroma(sourceColor.hue, 1.4 * 2.2),
2974
+ error: ({ sourceColor }) => {
2975
+ const errorHue = getPiecewiseHue(
2976
+ sourceColor,
2977
+ [0, 3, 13, 23, 33, 43, 153, 273, 360],
2978
+ [12, 22, 32, 12, 22, 32, 22, 12]
2979
+ );
2980
+ return TonalPalette.fromHueAndChroma(errorHue, 50);
2981
+ }
2982
+ },
2983
+ customPalettes: (_, colorHct) => TonalPalette.fromHueAndChroma(
2984
+ colorHct.hue,
2985
+ Hct.isBlue(colorHct.hue) ? 6 : 4
2986
+ )
2987
+ });
2988
+ const tonalSpotVariant = variant({
2989
+ name: "tonalSpot",
2990
+ palettes: {
2991
+ primary: ({ sourceColor, isDark }) => TonalPalette.fromHueAndChroma(sourceColor.hue, isDark ? 26 : 32),
2992
+ secondary: ({ sourceColor }) => TonalPalette.fromHueAndChroma(sourceColor.hue, 16),
2993
+ tertiary: ({ sourceColor }) => TonalPalette.fromHueAndChroma(
2994
+ getRotatedHue(
2995
+ sourceColor,
2996
+ [0, 20, 71, 161, 333, 360],
2997
+ [-40, 48, -32, 40, -32]
2998
+ ),
2999
+ 28
3000
+ ),
3001
+ neutral: ({ sourceColor }) => TonalPalette.fromHueAndChroma(sourceColor.hue, 5),
3002
+ neutralVariant: ({ sourceColor }) => TonalPalette.fromHueAndChroma(sourceColor.hue, 5 * 1.7),
3003
+ error: ({ sourceColor }) => {
3004
+ const errorHue = getPiecewiseHue(
3005
+ sourceColor,
3006
+ [0, 3, 13, 23, 33, 43, 153, 273, 360],
3007
+ [12, 22, 32, 12, 22, 32, 22, 12]
3008
+ );
3009
+ return TonalPalette.fromHueAndChroma(errorHue, 60);
3010
+ }
3011
+ },
3012
+ customPalettes: (_, colorHct) => TonalPalette.fromHueAndChroma(colorHct.hue, 16)
3013
+ });
3014
+ const getVibrantNeutralHue = (sourceColor) => {
3015
+ return getRotatedHue(
3016
+ sourceColor,
3017
+ [0, 38, 105, 140, 333, 360],
3018
+ [-14, 10, -14, 10, -14]
3019
+ );
3020
+ };
3021
+ const getVibrantNeutralChroma = (sourceColor) => {
3022
+ return 28;
3023
+ };
3024
+ const vibrantVariant = variant({
3025
+ name: "vibrant",
3026
+ palettes: {
3027
+ primary: ({ sourceColor }) => TonalPalette.fromHueAndChroma(sourceColor.hue, 74),
3028
+ secondary: ({ sourceColor }) => TonalPalette.fromHueAndChroma(
3029
+ getRotatedHue(
3030
+ sourceColor,
3031
+ [0, 38, 105, 140, 333, 360],
3032
+ [-14, 10, -14, 10, -14]
3033
+ ),
3034
+ 56
3035
+ ),
3036
+ tertiary: ({ sourceColor }) => TonalPalette.fromHueAndChroma(
3037
+ getRotatedHue(
3038
+ sourceColor,
3039
+ [0, 38, 71, 105, 140, 161, 253, 333, 360],
3040
+ [-72, 35, 24, -24, 62, 50, 62, -72]
3041
+ ),
3042
+ 56
3043
+ ),
3044
+ neutral: ({ sourceColor }) => TonalPalette.fromHueAndChroma(
3045
+ getVibrantNeutralHue(sourceColor),
3046
+ getVibrantNeutralChroma()
3047
+ ),
3048
+ neutralVariant: ({ sourceColor }) => {
3049
+ const vibrantNeutralHue = getVibrantNeutralHue(sourceColor);
3050
+ const vibrantNeutralChroma = getVibrantNeutralChroma();
3051
+ return TonalPalette.fromHueAndChroma(
3052
+ vibrantNeutralHue,
3053
+ vibrantNeutralChroma * 1.29
3054
+ );
3055
+ },
3056
+ error: ({ sourceColor }) => {
3057
+ const errorHue = getPiecewiseHue(
3058
+ sourceColor,
3059
+ [0, 3, 13, 23, 33, 43, 153, 273, 360],
3060
+ [12, 22, 32, 12, 22, 32, 22, 12]
3061
+ );
3062
+ return TonalPalette.fromHueAndChroma(errorHue, 80);
3063
+ }
3064
+ },
3065
+ customPalettes: (_, colorHct) => TonalPalette.fromHueAndChroma(
3066
+ getRotatedHue(
3067
+ colorHct,
3068
+ [0, 38, 105, 140, 333, 360],
3069
+ [-14, 10, -14, 10, -14]
3070
+ ),
3071
+ 56
3072
+ )
3073
+ });
3074
+ const fidelityVariant = variant({
3075
+ name: "fidelity",
3076
+ palettes: {
3077
+ primary: ({ sourceColor }) => ({
3078
+ hue: sourceColor.hue,
3079
+ chroma: sourceColor.chroma
3080
+ }),
3081
+ secondary: ({ sourceColor }) => ({
3082
+ hue: sourceColor.hue,
3083
+ chroma: sourceColor.chroma / 1.4
3084
+ }),
3085
+ tertiary: ({ sourceColor }) => ({
3086
+ hue: getRotatedHue(
3087
+ sourceColor,
3088
+ [0, 20, 71, 161, 333, 360],
3089
+ [-40, 48, -32, 40, -32]
3090
+ ),
3091
+ chroma: sourceColor.chroma
3092
+ }),
3093
+ neutral: ({ sourceColor }) => ({
3094
+ hue: sourceColor.hue,
3095
+ chroma: 5
3096
+ }),
3097
+ neutralVariant: ({ sourceColor }) => ({
3098
+ hue: sourceColor.hue,
3099
+ chroma: 5 * 1.7
3100
+ }),
3101
+ error: ({ sourceColor }) => {
3102
+ const errorHue = getPiecewiseHue(
3103
+ sourceColor,
3104
+ [0, 3, 13, 23, 33, 43, 153, 273, 360],
3105
+ [12, 22, 32, 12, 22, 32, 22, 12]
3106
+ );
3107
+ return {
3108
+ hue: errorHue,
3109
+ chroma: 60
3110
+ };
3111
+ }
3112
+ },
3113
+ customPalettes: ({ sourceColor }, colorHct) => ({
3114
+ hue: colorHct.hue,
3115
+ chroma: sourceColor.chroma
3116
+ })
3117
+ });
3118
+ const Variants = {
3119
+ Expressive: expressiveVariant,
3120
+ Neutral: neutralVariant,
3121
+ TonalSpot: tonalSpotVariant,
3122
+ Vibrant: vibrantVariant,
3123
+ Fidelity: fidelityVariant
3124
+ };
3125
+ const loader = async (config, load = true) => {
3126
+ const api = bootstrap();
2628
3127
  const init = () => {
2629
3128
  const {
2630
3129
  sourceColor,
2631
3130
  contrastLevel = 0,
2632
3131
  isDark = false,
2633
- variant = tonalSpotVariant,
3132
+ variant: variant2 = Variants.TonalSpot,
2634
3133
  palettes,
2635
3134
  colors,
2636
- useDefaultColors = true,
2637
3135
  plugins
2638
3136
  } = config;
2639
- api.themes.create({
3137
+ api.context.set({
2640
3138
  contrastLevel,
2641
3139
  isDark,
2642
- sourceColorHex: sourceColor,
2643
- variant
3140
+ sourceColor,
3141
+ variant: variant2
2644
3142
  });
3143
+ api.colors.addColors(defaultColors);
2645
3144
  if (palettes) {
2646
- Object.entries(palettes).forEach(
2647
- ([key, value]) => api.themes.addCustomPalette(key, value)
2648
- );
2649
- }
2650
- if (useDefaultColors) {
2651
- api.colors.addColors(defaultColors);
3145
+ api.palettes.add(palettes);
2652
3146
  }
2653
3147
  if (colors) {
2654
3148
  api.colors.addColors(colors);
@@ -2661,35 +3155,44 @@ const loader = async (config) => {
2661
3155
  }
2662
3156
  };
2663
3157
  init();
2664
- await api.load();
3158
+ if (load) {
3159
+ await api.load();
3160
+ }
2665
3161
  return api;
2666
3162
  };
2667
3163
  export {
2668
- AppContainer as A,
3164
+ API as A,
3165
+ vibrantVariant as B,
2669
3166
  ColorApi as C,
2670
3167
  DynamicColor as D,
2671
- Hct as H,
2672
- PluginModule as P,
2673
- SchemeManager as S,
2674
- ThemeModule as T,
3168
+ expressiveVariant as E,
3169
+ neutralVariant as F,
3170
+ Palette as P,
2675
3171
  Variant as V,
2676
- AppModule as a,
2677
- API as b,
2678
- ColorManager as c,
2679
- ColorModule as d,
2680
- ConfigurableColor as e,
2681
- defaultColors as f,
2682
- 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,
2683
3179
  highestSurface as h,
2684
- ContrastCurve as i,
2685
- PluginApi as j,
2686
- tonalSpotVariant as k,
2687
- loader as l,
2688
- Scheme as m,
2689
- ThemeApi as n,
2690
- getPiecewiseHue as o,
2691
- getRotatedHue as p,
2692
- VariantManager as q,
2693
- registerModule as r,
2694
- 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
2695
3198
  };