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