@udixio/theme 1.3.1 → 2.0.0

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