@udixio/theme 0.4.2 → 0.5.1

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 (91) hide show
  1. package/CHANGELOG.md +111 -0
  2. package/README.md +11 -0
  3. package/index.cjs +3092 -0
  4. package/index.js +3070 -0
  5. package/package.json +5 -5
  6. package/src/{lib/API.d.ts → API.d.ts} +1 -0
  7. package/src/API.d.ts.map +1 -0
  8. package/src/{lib/app.container.d.ts → app.container.d.ts} +1 -0
  9. package/src/app.container.d.ts.map +1 -0
  10. package/src/{lib/app.module.d.ts → app.module.d.ts} +1 -0
  11. package/src/app.module.d.ts.map +1 -0
  12. package/src/{lib/color → color}/color.api.d.ts +1 -0
  13. package/src/color/color.api.d.ts.map +1 -0
  14. package/src/{lib/color → color}/color.manager.d.ts +1 -0
  15. package/src/color/color.manager.d.ts.map +1 -0
  16. package/src/color/color.module.d.ts +3 -0
  17. package/src/color/color.module.d.ts.map +1 -0
  18. package/src/{lib/color → color}/color.utils.d.ts +1 -0
  19. package/src/color/color.utils.d.ts.map +1 -0
  20. package/src/{lib/color → color}/configurable-color.d.ts +1 -0
  21. package/src/color/configurable-color.d.ts.map +1 -0
  22. package/src/{lib/color → color}/default-color.d.ts +1 -0
  23. package/src/color/default-color.d.ts.map +1 -0
  24. package/src/{lib/color → color}/index.d.ts +1 -0
  25. package/src/color/index.d.ts.map +1 -0
  26. package/src/{lib/config → config}/config.interface.d.ts +1 -0
  27. package/src/config/config.interface.d.ts.map +1 -0
  28. package/src/{lib/config → config}/config.module.d.ts +1 -0
  29. package/src/config/config.module.d.ts.map +1 -0
  30. package/src/{lib/config → config}/config.service.d.ts +2 -1
  31. package/src/config/config.service.d.ts.map +1 -0
  32. package/src/{lib/config → config}/index.d.ts +1 -0
  33. package/src/config/index.d.ts.map +1 -0
  34. package/src/index.d.ts +12 -1
  35. package/src/index.d.ts.map +1 -0
  36. package/src/{lib/main.d.ts → main.d.ts} +2 -1
  37. package/src/main.d.ts.map +1 -0
  38. package/src/{lib/material-color-utilities → material-color-utilities}/contrastCurve.d.ts +1 -0
  39. package/src/material-color-utilities/contrastCurve.d.ts.map +1 -0
  40. package/src/{lib/material-color-utilities → material-color-utilities}/dynamic_color.d.ts +1 -16
  41. package/src/material-color-utilities/dynamic_color.d.ts.map +1 -0
  42. package/src/{lib/material-color-utilities → material-color-utilities}/hct_solver.d.ts +1 -16
  43. package/src/material-color-utilities/hct_solver.d.ts.map +1 -0
  44. package/src/{lib/material-color-utilities → material-color-utilities}/htc.d.ts +1 -31
  45. package/src/material-color-utilities/htc.d.ts.map +1 -0
  46. package/src/{lib/material-color-utilities → material-color-utilities}/index.d.ts +1 -0
  47. package/src/material-color-utilities/index.d.ts.map +1 -0
  48. package/src/{lib/material-color-utilities → material-color-utilities}/toneDeltaPair.d.ts +2 -17
  49. package/src/material-color-utilities/toneDeltaPair.d.ts.map +1 -0
  50. package/src/{lib/plugin → plugin}/index.d.ts +1 -0
  51. package/src/plugin/index.d.ts.map +1 -0
  52. package/src/{lib/plugin → plugin}/plugin.module.d.ts +1 -0
  53. package/src/plugin/plugin.module.d.ts.map +1 -0
  54. package/src/{lib/plugin → plugin}/pluginAbstract.d.ts +1 -0
  55. package/src/plugin/pluginAbstract.d.ts.map +1 -0
  56. package/src/{lib/plugin → plugin}/pluginApi.d.ts +1 -0
  57. package/src/plugin/pluginApi.d.ts.map +1 -0
  58. package/src/{lib/plugins → plugins}/font/font.plugin.d.ts +1 -0
  59. package/src/plugins/font/font.plugin.d.ts.map +1 -0
  60. package/src/plugins/font/index.d.ts +2 -0
  61. package/src/plugins/font/index.d.ts.map +1 -0
  62. package/src/{lib/theme → theme}/index.d.ts +1 -0
  63. package/src/theme/index.d.ts.map +1 -0
  64. package/src/{lib/theme → theme}/scheme.d.ts +1 -0
  65. package/src/theme/scheme.d.ts.map +1 -0
  66. package/src/{lib/theme → theme}/scheme.manager.d.ts +1 -0
  67. package/src/theme/scheme.manager.d.ts.map +1 -0
  68. package/src/{lib/theme → theme}/theme.api.d.ts +1 -0
  69. package/src/theme/theme.api.d.ts.map +1 -0
  70. package/src/{lib/theme → theme}/theme.module.d.ts +1 -0
  71. package/src/theme/theme.module.d.ts.map +1 -0
  72. package/src/{lib/theme → theme}/variant.d.ts +1 -0
  73. package/src/theme/variant.d.ts.map +1 -0
  74. package/src/{lib/theme → theme}/variant.manager.d.ts +1 -0
  75. package/src/theme/variant.manager.d.ts.map +1 -0
  76. package/src/{lib/theme → theme}/variants/expressive.variant.d.ts +1 -0
  77. package/src/theme/variants/expressive.variant.d.ts.map +1 -0
  78. package/src/{lib/theme → theme}/variants/index.d.ts +5 -4
  79. package/src/theme/variants/index.d.ts.map +1 -0
  80. package/src/{lib/theme → theme}/variants/neutral.variant.d.ts +1 -0
  81. package/src/theme/variants/neutral.variant.d.ts.map +1 -0
  82. package/src/{lib/theme → theme}/variants/tonal-spot.variant.d.ts +1 -0
  83. package/src/theme/variants/tonal-spot.variant.d.ts.map +1 -0
  84. package/src/{lib/theme → theme}/variants/vibrant.variant.d.ts +1 -0
  85. package/src/theme/variants/vibrant.variant.d.ts.map +1 -0
  86. package/index.cjs.js +0 -2880
  87. package/index.d.ts +0 -1
  88. package/index.esm.js +0 -2842
  89. package/src/lib/color/color.module.d.ts +0 -2
  90. package/src/lib/index.d.ts +0 -11
  91. package/src/lib/plugins/font/index.d.ts +0 -1
package/index.cjs ADDED
@@ -0,0 +1,3092 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
25
+ const awilix = require("awilix");
26
+ const materialColorUtilities = require("@material/material-color-utilities");
27
+ class ColorApi {
28
+ constructor({ colorManager }) {
29
+ this.colorManager = colorManager;
30
+ }
31
+ getColors() {
32
+ return this.colorManager.getAll();
33
+ }
34
+ addColor(key, color) {
35
+ return this.colorManager.createOrUpdate(key, color);
36
+ }
37
+ addColors(args) {
38
+ if (!Array.isArray(args)) args = [args];
39
+ args.forEach((args2) => {
40
+ if (typeof args2 === "function") {
41
+ args2 = args2(this);
42
+ }
43
+ if (args2.fromPalettes) {
44
+ if (!Array.isArray(args2.fromPalettes))
45
+ args2.fromPalettes = [args2.fromPalettes];
46
+ args2.fromPalettes.map((paletteKey) => {
47
+ this.colorManager.addFromPalette(paletteKey);
48
+ });
49
+ }
50
+ if (args2.colors) {
51
+ Object.keys(args2.colors).map(
52
+ (key) => this.addColor(key, args2.colors[key])
53
+ );
54
+ }
55
+ });
56
+ }
57
+ getColor(key) {
58
+ return this.colorManager.get(key);
59
+ }
60
+ removeColor(key) {
61
+ return this.colorManager.remove(key);
62
+ }
63
+ updateColor(key, newColor) {
64
+ return this.colorManager.createOrUpdate(key, newColor);
65
+ }
66
+ }
67
+ /**
68
+ * @license
69
+ * Copyright 2023 Google LLC
70
+ *
71
+ * Licensed under the Apache License, Version 2.0 (the "License");
72
+ * you may not use this file except in compliance with the License.
73
+ * You may obtain a copy of the License at
74
+ *
75
+ * http://www.apache.org/licenses/LICENSE-2.0
76
+ *
77
+ * Unless required by applicable law or agreed to in writing, software
78
+ * distributed under the License is distributed on an "AS IS" BASIS,
79
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
80
+ * See the License for the specific language governing permissions and
81
+ * limitations under the License.
82
+ */
83
+ class ContrastCurve {
84
+ /**
85
+ * Creates a `ContrastCurve` object.
86
+ *
87
+ * @param low Value for contrast level -1.0
88
+ * @param normal Value for contrast level 0.0
89
+ * @param medium Value for contrast level 0.5
90
+ * @param high Value for contrast level 1.0
91
+ */
92
+ constructor(low, normal, medium, high) {
93
+ this.low = low;
94
+ this.normal = normal;
95
+ this.medium = medium;
96
+ this.high = high;
97
+ }
98
+ /**
99
+ * Returns the value at a given contrast level.
100
+ *
101
+ * @param contrastLevel The contrast level. 0.0 is the default (normal); -1.0
102
+ * is the lowest; 1.0 is the highest.
103
+ * @return The value. For contrast ratios, a number between 1.0 and 21.0.
104
+ */
105
+ get(contrastLevel) {
106
+ if (contrastLevel <= -1) {
107
+ return this.low;
108
+ } else if (contrastLevel < 0) {
109
+ return materialColorUtilities.lerp(this.low, this.normal, (contrastLevel - -1) / 1);
110
+ } else if (contrastLevel < 0.5) {
111
+ return materialColorUtilities.lerp(this.normal, this.medium, (contrastLevel - 0) / 0.5);
112
+ } else if (contrastLevel < 1) {
113
+ return materialColorUtilities.lerp(this.medium, this.high, (contrastLevel - 0.5) / 0.5);
114
+ } else {
115
+ return this.high;
116
+ }
117
+ }
118
+ }
119
+ /**
120
+ * @license
121
+ * Copyright 2021 Google LLC
122
+ *
123
+ * Licensed under the Apache License, Version 2.0 (the "License");
124
+ * you may not use this file except in compliance with the License.
125
+ * You may obtain a copy of the License at
126
+ *
127
+ * http://www.apache.org/licenses/LICENSE-2.0
128
+ *
129
+ * Unless required by applicable law or agreed to in writing, software
130
+ * distributed under the License is distributed on an "AS IS" BASIS,
131
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
132
+ * See the License for the specific language governing permissions and
133
+ * limitations under the License.
134
+ */
135
+ const _HctSolver = class _HctSolver {
136
+ /**
137
+ * Finds an sRGB color with the given hue, chroma, and L*, if
138
+ * possible.
139
+ *
140
+ * @param hueDegrees The desired hue, in degrees.
141
+ * @param chroma The desired chroma.
142
+ * @param lstar The desired L*.
143
+ * @return A hexadecimal representing the sRGB color. The color
144
+ * has sufficiently close hue, chroma, and L* to the desired
145
+ * values, if possible; otherwise, the hue and L* will be
146
+ * sufficiently close, and chroma will be maximized.
147
+ */
148
+ static solveToInt(hueDegrees, chroma, lstar) {
149
+ if (chroma < 1e-4 || lstar < 1e-4 || lstar > 99.9999) {
150
+ return materialColorUtilities.argbFromLstar(lstar);
151
+ }
152
+ hueDegrees = materialColorUtilities.sanitizeDegreesDouble(hueDegrees);
153
+ const hueRadians = hueDegrees / 180 * Math.PI;
154
+ const y = materialColorUtilities.yFromLstar(lstar);
155
+ const exactAnswer = _HctSolver.findResultByJ(hueRadians, chroma, y);
156
+ if (exactAnswer !== 0) {
157
+ return exactAnswer;
158
+ }
159
+ const linrgb = _HctSolver.bisectToLimit(y, hueRadians);
160
+ return materialColorUtilities.argbFromLinrgb(linrgb);
161
+ }
162
+ /**
163
+ * Finds an sRGB color with the given hue, chroma, and L*, if
164
+ * possible.
165
+ *
166
+ * @param hueDegrees The desired hue, in degrees.
167
+ * @param chroma The desired chroma.
168
+ * @param lstar The desired L*.
169
+ * @return An CAM16 object representing the sRGB color. The color
170
+ * has sufficiently close hue, chroma, and L* to the desired
171
+ * values, if possible; otherwise, the hue and L* will be
172
+ * sufficiently close, and chroma will be maximized.
173
+ */
174
+ static solveToCam(hueDegrees, chroma, lstar) {
175
+ return materialColorUtilities.Cam16.fromInt(_HctSolver.solveToInt(hueDegrees, chroma, lstar));
176
+ }
177
+ /**
178
+ * Sanitizes a small enough angle in radians.
179
+ *
180
+ * @param angle An angle in radians; must not deviate too much
181
+ * from 0.
182
+ * @return A coterminal angle between 0 and 2pi.
183
+ */
184
+ static sanitizeRadians(angle) {
185
+ return (angle + Math.PI * 8) % (Math.PI * 2);
186
+ }
187
+ /**
188
+ * Delinearizes an RGB component, returning a floating-point
189
+ * number.
190
+ *
191
+ * @param rgbComponent 0.0 <= rgb_component <= 100.0, represents
192
+ * linear R/G/B channel
193
+ * @return 0.0 <= output <= 255.0, color channel converted to
194
+ * regular RGB space
195
+ */
196
+ static trueDelinearized(rgbComponent) {
197
+ const normalized = rgbComponent / 100;
198
+ let delinearized = 0;
199
+ if (normalized <= 31308e-7) {
200
+ delinearized = normalized * 12.92;
201
+ } else {
202
+ delinearized = 1.055 * Math.pow(normalized, 1 / 2.4) - 0.055;
203
+ }
204
+ return delinearized * 255;
205
+ }
206
+ static chromaticAdaptation(component) {
207
+ const af = Math.pow(Math.abs(component), 0.42);
208
+ return materialColorUtilities.signum(component) * 400 * af / (af + 27.13);
209
+ }
210
+ /**
211
+ * Returns the hue of a linear RGB color in CAM16.
212
+ *
213
+ * @param linrgb The linear RGB coordinates of a color.
214
+ * @return The hue of the color in CAM16, in radians.
215
+ */
216
+ static hueOf(linrgb) {
217
+ const scaledDiscount = materialColorUtilities.matrixMultiply(
218
+ linrgb,
219
+ _HctSolver.SCALED_DISCOUNT_FROM_LINRGB
220
+ );
221
+ const rA = _HctSolver.chromaticAdaptation(scaledDiscount[0]);
222
+ const gA = _HctSolver.chromaticAdaptation(scaledDiscount[1]);
223
+ const bA = _HctSolver.chromaticAdaptation(scaledDiscount[2]);
224
+ const a = (11 * rA + -12 * gA + bA) / 11;
225
+ const b = (rA + gA - 2 * bA) / 9;
226
+ return Math.atan2(b, a);
227
+ }
228
+ static areInCyclicOrder(a, b, c) {
229
+ const deltaAB = _HctSolver.sanitizeRadians(b - a);
230
+ const deltaAC = _HctSolver.sanitizeRadians(c - a);
231
+ return deltaAB < deltaAC;
232
+ }
233
+ /**
234
+ * Solves the lerp equation.
235
+ *
236
+ * @param source The starting number.
237
+ * @param mid The number in the middle.
238
+ * @param target The ending number.
239
+ * @return A number t such that lerp(source, target, t) = mid.
240
+ */
241
+ static intercept(source, mid, target) {
242
+ return (mid - source) / (target - source);
243
+ }
244
+ static lerpPoint(source, t, target) {
245
+ return [
246
+ source[0] + (target[0] - source[0]) * t,
247
+ source[1] + (target[1] - source[1]) * t,
248
+ source[2] + (target[2] - source[2]) * t
249
+ ];
250
+ }
251
+ /**
252
+ * Intersects a segment with a plane.
253
+ *
254
+ * @param source The coordinates of point A.
255
+ * @param coordinate The R-, G-, or B-coordinate of the plane.
256
+ * @param target The coordinates of point B.
257
+ * @param axis The axis the plane is perpendicular with. (0: R, 1:
258
+ * G, 2: B)
259
+ * @return The intersection point of the segment AB with the plane
260
+ * R=coordinate, G=coordinate, or B=coordinate
261
+ */
262
+ static setCoordinate(source, coordinate, target, axis) {
263
+ const t = _HctSolver.intercept(source[axis], coordinate, target[axis]);
264
+ return _HctSolver.lerpPoint(source, t, target);
265
+ }
266
+ static isBounded(x) {
267
+ return 0 <= x && x <= 100;
268
+ }
269
+ /**
270
+ * Returns the nth possible vertex of the polygonal intersection.
271
+ *
272
+ * @param y The Y value of the plane.
273
+ * @param n The zero-based index of the point. 0 <= n <= 11.
274
+ * @return The nth possible vertex of the polygonal intersection
275
+ * of the y plane and the RGB cube, in linear RGB coordinates, if
276
+ * it exists. If this possible vertex lies outside of the cube,
277
+ * [-1.0, -1.0, -1.0] is returned.
278
+ */
279
+ static nthVertex(y, n) {
280
+ const kR = _HctSolver.Y_FROM_LINRGB[0];
281
+ const kG = _HctSolver.Y_FROM_LINRGB[1];
282
+ const kB = _HctSolver.Y_FROM_LINRGB[2];
283
+ const coordA = n % 4 <= 1 ? 0 : 100;
284
+ const coordB = n % 2 === 0 ? 0 : 100;
285
+ if (n < 4) {
286
+ const g = coordA;
287
+ const b = coordB;
288
+ const r = (y - g * kG - b * kB) / kR;
289
+ if (_HctSolver.isBounded(r)) {
290
+ return [r, g, b];
291
+ } else {
292
+ return [-1, -1, -1];
293
+ }
294
+ } else if (n < 8) {
295
+ const b = coordA;
296
+ const r = coordB;
297
+ const g = (y - r * kR - b * kB) / kG;
298
+ if (_HctSolver.isBounded(g)) {
299
+ return [r, g, b];
300
+ } else {
301
+ return [-1, -1, -1];
302
+ }
303
+ } else {
304
+ const r = coordA;
305
+ const g = coordB;
306
+ const b = (y - r * kR - g * kG) / kB;
307
+ if (_HctSolver.isBounded(b)) {
308
+ return [r, g, b];
309
+ } else {
310
+ return [-1, -1, -1];
311
+ }
312
+ }
313
+ }
314
+ /**
315
+ * Finds the segment containing the desired color.
316
+ *
317
+ * @param y The Y value of the color.
318
+ * @param targetHue The hue of the color.
319
+ * @return A list of two sets of linear RGB coordinates, each
320
+ * corresponding to an endpoint of the segment containing the
321
+ * desired color.
322
+ */
323
+ static bisectToSegment(y, targetHue) {
324
+ let left = [-1, -1, -1];
325
+ let right = left;
326
+ let leftHue = 0;
327
+ let rightHue = 0;
328
+ let initialized = false;
329
+ let uncut = true;
330
+ for (let n = 0; n < 12; n++) {
331
+ const mid = _HctSolver.nthVertex(y, n);
332
+ if (mid[0] < 0) {
333
+ continue;
334
+ }
335
+ const midHue = _HctSolver.hueOf(mid);
336
+ if (!initialized) {
337
+ left = mid;
338
+ right = mid;
339
+ leftHue = midHue;
340
+ rightHue = midHue;
341
+ initialized = true;
342
+ continue;
343
+ }
344
+ if (uncut || _HctSolver.areInCyclicOrder(leftHue, midHue, rightHue)) {
345
+ uncut = false;
346
+ if (_HctSolver.areInCyclicOrder(leftHue, targetHue, midHue)) {
347
+ right = mid;
348
+ rightHue = midHue;
349
+ } else {
350
+ left = mid;
351
+ leftHue = midHue;
352
+ }
353
+ }
354
+ }
355
+ return [left, right];
356
+ }
357
+ static midpoint(a, b) {
358
+ return [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2, (a[2] + b[2]) / 2];
359
+ }
360
+ static criticalPlaneBelow(x) {
361
+ return Math.floor(x - 0.5);
362
+ }
363
+ static criticalPlaneAbove(x) {
364
+ return Math.ceil(x - 0.5);
365
+ }
366
+ /**
367
+ * Finds a color with the given Y and hue on the boundary of the
368
+ * cube.
369
+ *
370
+ * @param y The Y value of the color.
371
+ * @param targetHue The hue of the color.
372
+ * @return The desired color, in linear RGB coordinates.
373
+ */
374
+ static bisectToLimit(y, targetHue) {
375
+ const segment = _HctSolver.bisectToSegment(y, targetHue);
376
+ let left = segment[0];
377
+ let leftHue = _HctSolver.hueOf(left);
378
+ let right = segment[1];
379
+ for (let axis = 0; axis < 3; axis++) {
380
+ if (left[axis] !== right[axis]) {
381
+ let lPlane = -1;
382
+ let rPlane = 255;
383
+ if (left[axis] < right[axis]) {
384
+ lPlane = _HctSolver.criticalPlaneBelow(
385
+ _HctSolver.trueDelinearized(left[axis])
386
+ );
387
+ rPlane = _HctSolver.criticalPlaneAbove(
388
+ _HctSolver.trueDelinearized(right[axis])
389
+ );
390
+ } else {
391
+ lPlane = _HctSolver.criticalPlaneAbove(
392
+ _HctSolver.trueDelinearized(left[axis])
393
+ );
394
+ rPlane = _HctSolver.criticalPlaneBelow(
395
+ _HctSolver.trueDelinearized(right[axis])
396
+ );
397
+ }
398
+ for (let i = 0; i < 8; i++) {
399
+ if (Math.abs(rPlane - lPlane) <= 1) {
400
+ break;
401
+ } else {
402
+ const mPlane = Math.floor((lPlane + rPlane) / 2);
403
+ const midPlaneCoordinate = _HctSolver.CRITICAL_PLANES[mPlane];
404
+ const mid = _HctSolver.setCoordinate(
405
+ left,
406
+ midPlaneCoordinate,
407
+ right,
408
+ axis
409
+ );
410
+ const midHue = _HctSolver.hueOf(mid);
411
+ if (_HctSolver.areInCyclicOrder(leftHue, targetHue, midHue)) {
412
+ right = mid;
413
+ rPlane = mPlane;
414
+ } else {
415
+ left = mid;
416
+ leftHue = midHue;
417
+ lPlane = mPlane;
418
+ }
419
+ }
420
+ }
421
+ }
422
+ }
423
+ return _HctSolver.midpoint(left, right);
424
+ }
425
+ static inverseChromaticAdaptation(adapted) {
426
+ const adaptedAbs = Math.abs(adapted);
427
+ const base = Math.max(0, 27.13 * adaptedAbs / (400 - adaptedAbs));
428
+ return materialColorUtilities.signum(adapted) * Math.pow(base, 1 / 0.42);
429
+ }
430
+ /**
431
+ * Finds a color with the given hue, chroma, and Y.
432
+ *
433
+ * @param hueRadians The desired hue in radians.
434
+ * @param chroma The desired chroma.
435
+ * @param y The desired Y.
436
+ * @return The desired color as a hexadecimal integer, if found; 0
437
+ * otherwise.
438
+ */
439
+ static findResultByJ(hueRadians, chroma, y) {
440
+ let j = Math.sqrt(y) * 11;
441
+ const viewingConditions = materialColorUtilities.ViewingConditions.DEFAULT;
442
+ const tInnerCoeff = 1 / Math.pow(1.64 - Math.pow(0.29, viewingConditions.n), 0.73);
443
+ const eHue = 0.25 * (Math.cos(hueRadians + 2) + 3.8);
444
+ const p1 = eHue * (5e4 / 13) * viewingConditions.nc * viewingConditions.ncb;
445
+ const hSin = Math.sin(hueRadians);
446
+ const hCos = Math.cos(hueRadians);
447
+ for (let iterationRound = 0; iterationRound < 5; iterationRound++) {
448
+ const jNormalized = j / 100;
449
+ const alpha = chroma === 0 || j === 0 ? 0 : chroma / Math.sqrt(jNormalized);
450
+ const t = Math.pow(alpha * tInnerCoeff, 1 / 0.9);
451
+ const ac = viewingConditions.aw * Math.pow(jNormalized, 1 / viewingConditions.c / viewingConditions.z);
452
+ const p2 = ac / viewingConditions.nbb;
453
+ const gamma = 23 * (p2 + 0.305) * t / (23 * p1 + 11 * t * hCos + 108 * t * hSin);
454
+ const a = gamma * hCos;
455
+ const b = gamma * hSin;
456
+ const rA = (460 * p2 + 451 * a + 288 * b) / 1403;
457
+ const gA = (460 * p2 - 891 * a - 261 * b) / 1403;
458
+ const bA = (460 * p2 - 220 * a - 6300 * b) / 1403;
459
+ const rCScaled = _HctSolver.inverseChromaticAdaptation(rA);
460
+ const gCScaled = _HctSolver.inverseChromaticAdaptation(gA);
461
+ const bCScaled = _HctSolver.inverseChromaticAdaptation(bA);
462
+ const linrgb = materialColorUtilities.matrixMultiply(
463
+ [rCScaled, gCScaled, bCScaled],
464
+ _HctSolver.LINRGB_FROM_SCALED_DISCOUNT
465
+ );
466
+ if (linrgb[0] < 0 || linrgb[1] < 0 || linrgb[2] < 0) {
467
+ return 0;
468
+ }
469
+ const kR = _HctSolver.Y_FROM_LINRGB[0];
470
+ const kG = _HctSolver.Y_FROM_LINRGB[1];
471
+ const kB = _HctSolver.Y_FROM_LINRGB[2];
472
+ const fnj = kR * linrgb[0] + kG * linrgb[1] + kB * linrgb[2];
473
+ if (fnj <= 0) {
474
+ return 0;
475
+ }
476
+ if (iterationRound === 4 || Math.abs(fnj - y) < 2e-3) {
477
+ if (linrgb[0] > 100.01 || linrgb[1] > 100.01 || linrgb[2] > 100.01) {
478
+ return 0;
479
+ }
480
+ return materialColorUtilities.argbFromLinrgb(linrgb);
481
+ }
482
+ j = j - (fnj - y) * j / (2 * fnj);
483
+ }
484
+ return 0;
485
+ }
486
+ };
487
+ _HctSolver.SCALED_DISCOUNT_FROM_LINRGB = [
488
+ [0.001200833568784504, 0.002389694492170889, 2795742885861124e-19],
489
+ [5891086651375999e-19, 0.0029785502573438758, 3270666104008398e-19],
490
+ [10146692491640572e-20, 5364214359186694e-19, 0.0032979401770712076]
491
+ ];
492
+ _HctSolver.LINRGB_FROM_SCALED_DISCOUNT = [
493
+ [1373.2198709594231, -1100.4251190754821, -7.278681089101213],
494
+ [-271.815969077903, 559.6580465940733, -32.46047482791194],
495
+ [1.9622899599665666, -57.173814538844006, 308.7233197812385]
496
+ ];
497
+ _HctSolver.Y_FROM_LINRGB = [0.2126, 0.7152, 0.0722];
498
+ _HctSolver.CRITICAL_PLANES = [
499
+ 0.015176349177441876,
500
+ 0.045529047532325624,
501
+ 0.07588174588720938,
502
+ 0.10623444424209313,
503
+ 0.13658714259697685,
504
+ 0.16693984095186062,
505
+ 0.19729253930674434,
506
+ 0.2276452376616281,
507
+ 0.2579979360165119,
508
+ 0.28835063437139563,
509
+ 0.3188300904430532,
510
+ 0.350925934958123,
511
+ 0.3848314933096426,
512
+ 0.42057480301049466,
513
+ 0.458183274052838,
514
+ 0.4976837250274023,
515
+ 0.5391024159806381,
516
+ 0.5824650784040898,
517
+ 0.6277969426914107,
518
+ 0.6751227633498623,
519
+ 0.7244668422128921,
520
+ 0.775853049866786,
521
+ 0.829304845476233,
522
+ 0.8848452951698498,
523
+ 0.942497089126609,
524
+ 1.0022825574869039,
525
+ 1.0642236851973577,
526
+ 1.1283421258858297,
527
+ 1.1946592148522128,
528
+ 1.2631959812511864,
529
+ 1.3339731595349034,
530
+ 1.407011200216447,
531
+ 1.4823302800086415,
532
+ 1.5599503113873272,
533
+ 1.6398909516233677,
534
+ 1.7221716113234105,
535
+ 1.8068114625156377,
536
+ 1.8938294463134073,
537
+ 1.9832442801866852,
538
+ 2.075074464868551,
539
+ 2.1693382909216234,
540
+ 2.2660538449872063,
541
+ 2.36523901573795,
542
+ 2.4669114995532007,
543
+ 2.5710888059345764,
544
+ 2.6777882626779785,
545
+ 2.7870270208169257,
546
+ 2.898822059350997,
547
+ 3.0131901897720907,
548
+ 3.1301480604002863,
549
+ 3.2497121605402226,
550
+ 3.3718988244681087,
551
+ 3.4967242352587946,
552
+ 3.624204428461639,
553
+ 3.754355295633311,
554
+ 3.887192587735158,
555
+ 4.022731918402185,
556
+ 4.160988767090289,
557
+ 4.301978482107941,
558
+ 4.445716283538092,
559
+ 4.592217266055746,
560
+ 4.741496401646282,
561
+ 4.893568542229298,
562
+ 5.048448422192488,
563
+ 5.20615066083972,
564
+ 5.3666897647573375,
565
+ 5.5300801301023865,
566
+ 5.696336044816294,
567
+ 5.865471690767354,
568
+ 6.037501145825082,
569
+ 6.212438385869475,
570
+ 6.390297286737924,
571
+ 6.571091626112461,
572
+ 6.7548350853498045,
573
+ 6.941541251256611,
574
+ 7.131223617812143,
575
+ 7.323895587840543,
576
+ 7.5195704746346665,
577
+ 7.7182615035334345,
578
+ 7.919981813454504,
579
+ 8.124744458384042,
580
+ 8.332562408825165,
581
+ 8.543448553206703,
582
+ 8.757415699253682,
583
+ 8.974476575321063,
584
+ 9.194643831691977,
585
+ 9.417930041841839,
586
+ 9.644347703669503,
587
+ 9.873909240696694,
588
+ 10.106627003236781,
589
+ 10.342513269534024,
590
+ 10.58158024687427,
591
+ 10.8238400726681,
592
+ 11.069304815507364,
593
+ 11.317986476196008,
594
+ 11.569896988756009,
595
+ 11.825048221409341,
596
+ 12.083451977536606,
597
+ 12.345119996613247,
598
+ 12.610063955123938,
599
+ 12.878295467455942,
600
+ 13.149826086772048,
601
+ 13.42466730586372,
602
+ 13.702830557985108,
603
+ 13.984327217668513,
604
+ 14.269168601521828,
605
+ 14.55736596900856,
606
+ 14.848930523210871,
607
+ 15.143873411576273,
608
+ 15.44220572664832,
609
+ 15.743938506781891,
610
+ 16.04908273684337,
611
+ 16.35764934889634,
612
+ 16.66964922287304,
613
+ 16.985093187232053,
614
+ 17.30399201960269,
615
+ 17.62635644741625,
616
+ 17.95219714852476,
617
+ 18.281524751807332,
618
+ 18.614349837764564,
619
+ 18.95068293910138,
620
+ 19.290534541298456,
621
+ 19.633915083172692,
622
+ 19.98083495742689,
623
+ 20.331304511189067,
624
+ 20.685334046541502,
625
+ 21.042933821039977,
626
+ 21.404114048223256,
627
+ 21.76888489811322,
628
+ 22.137256497705877,
629
+ 22.50923893145328,
630
+ 22.884842241736916,
631
+ 23.264076429332462,
632
+ 23.6469514538663,
633
+ 24.033477234264016,
634
+ 24.42366364919083,
635
+ 24.817520537484558,
636
+ 25.21505769858089,
637
+ 25.61628489293138,
638
+ 26.021211842414342,
639
+ 26.429848230738664,
640
+ 26.842203703840827,
641
+ 27.258287870275353,
642
+ 27.678110301598522,
643
+ 28.10168053274597,
644
+ 28.529008062403893,
645
+ 28.96010235337422,
646
+ 29.39497283293396,
647
+ 29.83362889318845,
648
+ 30.276079891419332,
649
+ 30.722335150426627,
650
+ 31.172403958865512,
651
+ 31.62629557157785,
652
+ 32.08401920991837,
653
+ 32.54558406207592,
654
+ 33.010999283389665,
655
+ 33.4802739966603,
656
+ 33.953417292456834,
657
+ 34.430438229418264,
658
+ 34.911345834551085,
659
+ 35.39614910352207,
660
+ 35.88485700094671,
661
+ 36.37747846067349,
662
+ 36.87402238606382,
663
+ 37.37449765026789,
664
+ 37.87891309649659,
665
+ 38.38727753828926,
666
+ 38.89959975977785,
667
+ 39.41588851594697,
668
+ 39.93615253289054,
669
+ 40.460400508064545,
670
+ 40.98864111053629,
671
+ 41.520882981230194,
672
+ 42.05713473317016,
673
+ 42.597404951718396,
674
+ 43.141702194811224,
675
+ 43.6900349931913,
676
+ 44.24241185063697,
677
+ 44.798841244188324,
678
+ 45.35933162437017,
679
+ 45.92389141541209,
680
+ 46.49252901546552,
681
+ 47.065252796817916,
682
+ 47.64207110610409,
683
+ 48.22299226451468,
684
+ 48.808024568002054,
685
+ 49.3971762874833,
686
+ 49.9904556690408,
687
+ 50.587870934119984,
688
+ 51.189430279724725,
689
+ 51.79514187861014,
690
+ 52.40501387947288,
691
+ 53.0190544071392,
692
+ 53.637271562750364,
693
+ 54.259673423945976,
694
+ 54.88626804504493,
695
+ 55.517063457223934,
696
+ 56.15206766869424,
697
+ 56.79128866487574,
698
+ 57.43473440856916,
699
+ 58.08241284012621,
700
+ 58.734331877617365,
701
+ 59.39049941699807,
702
+ 60.05092333227251,
703
+ 60.715611475655585,
704
+ 61.38457167773311,
705
+ 62.057811747619894,
706
+ 62.7353394731159,
707
+ 63.417162620860914,
708
+ 64.10328893648692,
709
+ 64.79372614476921,
710
+ 65.48848194977529,
711
+ 66.18756403501224,
712
+ 66.89098006357258,
713
+ 67.59873767827808,
714
+ 68.31084450182222,
715
+ 69.02730813691093,
716
+ 69.74813616640164,
717
+ 70.47333615344107,
718
+ 71.20291564160104,
719
+ 71.93688215501312,
720
+ 72.67524319850172,
721
+ 73.41800625771542,
722
+ 74.16517879925733,
723
+ 74.9167682708136,
724
+ 75.67278210128072,
725
+ 76.43322770089146,
726
+ 77.1981124613393,
727
+ 77.96744375590167,
728
+ 78.74122893956174,
729
+ 79.51947534912904,
730
+ 80.30219030335869,
731
+ 81.08938110306934,
732
+ 81.88105503125999,
733
+ 82.67721935322541,
734
+ 83.4778813166706,
735
+ 84.28304815182372,
736
+ 85.09272707154808,
737
+ 85.90692527145302,
738
+ 86.72564993000343,
739
+ 87.54890820862819,
740
+ 88.3767072518277,
741
+ 89.2090541872801,
742
+ 90.04595612594655,
743
+ 90.88742016217518,
744
+ 91.73345337380438,
745
+ 92.58406282226491,
746
+ 93.43925555268066,
747
+ 94.29903859396902,
748
+ 95.16341895893969,
749
+ 96.03240364439274,
750
+ 96.9059996312159,
751
+ 97.78421388448044,
752
+ 98.6670533535366,
753
+ 99.55452497210776
754
+ ];
755
+ let HctSolver = _HctSolver;
756
+ /**
757
+ * @license
758
+ * Copyright 2021 Google LLC
759
+ *
760
+ * Licensed under the Apache License, Version 2.0 (the "License");
761
+ * you may not use this file except in compliance with the License.
762
+ * You may obtain a copy of the License at
763
+ *
764
+ * http://www.apache.org/licenses/LICENSE-2.0
765
+ *
766
+ * Unless required by applicable law or agreed to in writing, software
767
+ * distributed under the License is distributed on an "AS IS" BASIS,
768
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
769
+ * See the License for the specific language governing permissions and
770
+ * limitations under the License.
771
+ */
772
+ class Hct {
773
+ constructor(argb) {
774
+ this.argb = argb;
775
+ const cam = materialColorUtilities.Cam16.fromInt(argb);
776
+ this.internalHue = cam.hue;
777
+ this.internalChroma = cam.chroma;
778
+ this.internalTone = materialColorUtilities.lstarFromArgb(argb);
779
+ this.argb = argb;
780
+ }
781
+ /**
782
+ * A number, in degrees, representing ex. red, orange, yellow, etc.
783
+ * Ranges from 0 <= hue < 360.
784
+ */
785
+ get hue() {
786
+ return this.internalHue;
787
+ }
788
+ /**
789
+ * @param newHue 0 <= newHue < 360; invalid values are corrected.
790
+ * Chroma may decrease because chroma has a different maximum for any given
791
+ * hue and tone.
792
+ */
793
+ set hue(newHue) {
794
+ this.setInternalState(
795
+ HctSolver.solveToInt(newHue, this.internalChroma, this.internalTone)
796
+ );
797
+ }
798
+ get chroma() {
799
+ return this.internalChroma;
800
+ }
801
+ /**
802
+ * @param newChroma 0 <= newChroma < ?
803
+ * Chroma may decrease because chroma has a different maximum for any given
804
+ * hue and tone.
805
+ */
806
+ set chroma(newChroma) {
807
+ this.setInternalState(
808
+ HctSolver.solveToInt(this.internalHue, newChroma, this.internalTone)
809
+ );
810
+ }
811
+ /** Lightness. Ranges from 0 to 100. */
812
+ get tone() {
813
+ return this.internalTone;
814
+ }
815
+ /**
816
+ * @param newTone 0 <= newTone <= 100; invalid valids are corrected.
817
+ * Chroma may decrease because chroma has a different maximum for any given
818
+ * hue and tone.
819
+ */
820
+ set tone(newTone) {
821
+ this.setInternalState(
822
+ HctSolver.solveToInt(this.internalHue, this.internalChroma, newTone)
823
+ );
824
+ }
825
+ static from(hue, chroma, tone) {
826
+ return new Hct(HctSolver.solveToInt(hue, chroma, tone));
827
+ }
828
+ /**
829
+ * @param argb ARGB representation of a color.
830
+ * @return HCT representation of a color in default viewing conditions
831
+ */
832
+ static fromInt(argb) {
833
+ return new Hct(argb);
834
+ }
835
+ static isBlue(hue) {
836
+ return hue >= 250 && hue < 270;
837
+ }
838
+ static isYellow(hue) {
839
+ return hue >= 105 && hue < 125;
840
+ }
841
+ static isCyan(hue) {
842
+ return hue >= 170 && hue < 207;
843
+ }
844
+ toInt() {
845
+ return this.argb;
846
+ }
847
+ /** Sets a property of the Hct object. */
848
+ setValue(propertyName, value) {
849
+ this[propertyName] = value;
850
+ }
851
+ toString() {
852
+ return `HCT(${this.hue.toFixed(0)}, ${this.chroma.toFixed(0)}, ${this.tone.toFixed(
853
+ 0
854
+ )})`;
855
+ }
856
+ /**
857
+ * Translates a color into different [ViewingConditions].
858
+ *
859
+ * Colors change appearance. They look different with lights on versus off,
860
+ * the same color, as in hex code, on white looks different when on black.
861
+ * This is called color relativity, most famously explicated by Josef Albers
862
+ * in Interaction of Color.
863
+ *
864
+ * In color science, color appearance models can account for this and
865
+ * calculate the appearance of a color in different settings. HCT is based on
866
+ * CAM16, a color appearance model, and uses it to make these calculations.
867
+ *
868
+ * See [ViewingConditions.make] for parameters affecting color appearance.
869
+ */
870
+ inViewingConditions(vc) {
871
+ const cam = materialColorUtilities.Cam16.fromInt(this.toInt());
872
+ const viewedInVc = cam.xyzInViewingConditions(vc);
873
+ const recastInVc = materialColorUtilities.Cam16.fromXyzInViewingConditions(
874
+ viewedInVc[0],
875
+ viewedInVc[1],
876
+ viewedInVc[2],
877
+ materialColorUtilities.ViewingConditions.make()
878
+ );
879
+ const recastHct = Hct.from(
880
+ recastInVc.hue,
881
+ recastInVc.chroma,
882
+ materialColorUtilities.lstarFromY(viewedInVc[1])
883
+ );
884
+ return recastHct;
885
+ }
886
+ setInternalState(argb) {
887
+ const cam = materialColorUtilities.Cam16.fromInt(argb);
888
+ this.internalHue = cam.hue;
889
+ this.internalChroma = cam.chroma;
890
+ this.internalTone = materialColorUtilities.lstarFromArgb(argb);
891
+ this.argb = argb;
892
+ }
893
+ }
894
+ /**
895
+ * @license
896
+ * Copyright 2022 Google LLC
897
+ *
898
+ * Licensed under the Apache License, Version 2.0 (the "License");
899
+ * you may not use this file except in compliance with the License.
900
+ * You may obtain a copy of the License at
901
+ *
902
+ * http://www.apache.org/licenses/LICENSE-2.0
903
+ *
904
+ * Unless required by applicable law or agreed to in writing, software
905
+ * distributed under the License is distributed on an "AS IS" BASIS,
906
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
907
+ * See the License for the specific language governing permissions and
908
+ * limitations under the License.
909
+ */
910
+ function extendSpecVersion(originlColor, extendedColor) {
911
+ return DynamicColor.fromPalette({
912
+ name: originlColor.name,
913
+ palette: (s) => extendedColor.palette(s),
914
+ tone: (s) => extendedColor.tone(s),
915
+ isBackground: originlColor.isBackground,
916
+ chromaMultiplier: (s) => {
917
+ const chromaMultiplier = extendedColor.chromaMultiplier;
918
+ return chromaMultiplier !== void 0 ? chromaMultiplier(s) : 1;
919
+ },
920
+ background: (s) => {
921
+ const background = extendedColor.background;
922
+ return background !== void 0 ? background(s) : void 0;
923
+ },
924
+ secondBackground: (s) => {
925
+ const secondBackground = extendedColor.secondBackground;
926
+ return secondBackground !== void 0 ? secondBackground(s) : void 0;
927
+ },
928
+ contrastCurve: (s) => {
929
+ const contrastCurve = extendedColor.contrastCurve;
930
+ return contrastCurve !== void 0 ? contrastCurve(s) : void 0;
931
+ },
932
+ toneDeltaPair: (s) => {
933
+ const toneDeltaPair = extendedColor.toneDeltaPair;
934
+ return toneDeltaPair !== void 0 ? toneDeltaPair(s) : void 0;
935
+ }
936
+ });
937
+ }
938
+ class DynamicColor {
939
+ /**
940
+ * The base constructor for DynamicColor.
941
+ *
942
+ * _Strongly_ prefer using one of the convenience constructors. This class is
943
+ * arguably too flexible to ensure it can support any scenario. Functional
944
+ * arguments allow overriding without risks that come with subclasses.
945
+ *
946
+ * For example, the default behavior of adjust tone at max contrast
947
+ * to be at a 7.0 ratio with its background is principled and
948
+ * matches accessibility guidance. That does not mean it's the desired
949
+ * approach for _every_ design system, and every color pairing,
950
+ * always, in every case.
951
+ *
952
+ * @param name The name of the dynamic color. Defaults to empty.
953
+ * @param palette Function that provides a TonalPalette given DynamicScheme. A
954
+ * TonalPalette is defined by a hue and chroma, so this replaces the need
955
+ * to specify hue/chroma. By providing a tonal palette, when contrast
956
+ * adjustments are made, intended chroma can be preserved.
957
+ * @param tone Function that provides a tone, given a DynamicScheme.
958
+ * @param isBackground Whether this dynamic color is a background, with some
959
+ * other color as the foreground. Defaults to false.
960
+ * @param chromaMultiplier A factor that multiplies the chroma for this color.
961
+ * @param background The background of the dynamic color (as a function of a
962
+ * `DynamicScheme`), if it exists.
963
+ * @param secondBackground A second background of the dynamic color (as a
964
+ * function of a `DynamicScheme`), if it exists.
965
+ * @param contrastCurve A `ContrastCurve` object specifying how its contrast
966
+ * against its background should behave in various contrast levels
967
+ * options.
968
+ * @param toneDeltaPair A `ToneDeltaPair` object specifying a tone delta
969
+ * constraint between two colors. One of them must be the color being
970
+ * constructed.
971
+ */
972
+ constructor(name, palette, tone, isBackground, chromaMultiplier, background, secondBackground, contrastCurve, toneDeltaPair) {
973
+ this.name = name;
974
+ this.palette = palette;
975
+ this.tone = tone;
976
+ this.isBackground = isBackground;
977
+ this.chromaMultiplier = chromaMultiplier;
978
+ this.background = background;
979
+ this.secondBackground = secondBackground;
980
+ this.contrastCurve = contrastCurve;
981
+ this.toneDeltaPair = toneDeltaPair;
982
+ this.hctCache = /* @__PURE__ */ new Map();
983
+ if (!background && secondBackground) {
984
+ throw new Error(
985
+ `Color ${name} has secondBackgrounddefined, but background is not defined.`
986
+ );
987
+ }
988
+ if (!background && contrastCurve) {
989
+ throw new Error(
990
+ `Color ${name} has contrastCurvedefined, but background is not defined.`
991
+ );
992
+ }
993
+ if (background && !contrastCurve) {
994
+ throw new Error(
995
+ `Color ${name} has backgrounddefined, but contrastCurve is not defined.`
996
+ );
997
+ }
998
+ }
999
+ /**
1000
+ * Create a DynamicColor defined by a TonalPalette and HCT tone.
1001
+ *
1002
+ * @param args Functions with DynamicScheme as input. Must provide a palette
1003
+ * and tone. May provide a background DynamicColor and ToneDeltaPair.
1004
+ */
1005
+ static fromPalette(args) {
1006
+ return new DynamicColor(
1007
+ args.name ?? "",
1008
+ args.palette,
1009
+ args.tone ?? DynamicColor.getInitialToneFromBackground(args.background),
1010
+ args.isBackground ?? false,
1011
+ args.chromaMultiplier,
1012
+ args.background,
1013
+ args.secondBackground,
1014
+ args.contrastCurve,
1015
+ args.toneDeltaPair
1016
+ );
1017
+ }
1018
+ static getInitialToneFromBackground(background) {
1019
+ if (background === void 0) {
1020
+ return (s) => 50;
1021
+ }
1022
+ return (s) => background(s) ? background(s).getTone(s) : 50;
1023
+ }
1024
+ /**
1025
+ * Given a background tone, finds a foreground tone, while ensuring they reach
1026
+ * a contrast ratio that is as close to [ratio] as possible.
1027
+ *
1028
+ * @param bgTone Tone in HCT. Range is 0 to 100, undefined behavior when it
1029
+ * falls outside that range.
1030
+ * @param ratio The contrast ratio desired between bgTone and the return
1031
+ * value.
1032
+ */
1033
+ static foregroundTone(bgTone, ratio) {
1034
+ const lighterTone = materialColorUtilities.Contrast.lighterUnsafe(bgTone, ratio);
1035
+ const darkerTone = materialColorUtilities.Contrast.darkerUnsafe(bgTone, ratio);
1036
+ const lighterRatio = materialColorUtilities.Contrast.ratioOfTones(lighterTone, bgTone);
1037
+ const darkerRatio = materialColorUtilities.Contrast.ratioOfTones(darkerTone, bgTone);
1038
+ const preferLighter = DynamicColor.tonePrefersLightForeground(bgTone);
1039
+ if (preferLighter) {
1040
+ const negligibleDifference = Math.abs(lighterRatio - darkerRatio) < 0.1 && lighterRatio < ratio && darkerRatio < ratio;
1041
+ return lighterRatio >= ratio || lighterRatio >= darkerRatio || negligibleDifference ? lighterTone : darkerTone;
1042
+ } else {
1043
+ return darkerRatio >= ratio || darkerRatio >= lighterRatio ? darkerTone : lighterTone;
1044
+ }
1045
+ }
1046
+ /**
1047
+ * Returns whether [tone] prefers a light foreground.
1048
+ *
1049
+ * People prefer white foregrounds on ~T60-70. Observed over time, and also
1050
+ * by Andrew Somers during research for APCA.
1051
+ *
1052
+ * T60 used as to create the smallest discontinuity possible when skipping
1053
+ * down to T49 in order to ensure light foregrounds.
1054
+ * Since `tertiaryContainer` in dark monochrome scheme requires a tone of
1055
+ * 60, it should not be adjusted. Therefore, 60 is excluded here.
1056
+ */
1057
+ static tonePrefersLightForeground(tone) {
1058
+ return Math.round(tone) < 60;
1059
+ }
1060
+ /**
1061
+ * Returns whether [tone] can reach a contrast ratio of 4.5 with a lighter
1062
+ * color.
1063
+ */
1064
+ static toneAllowsLightForeground(tone) {
1065
+ return Math.round(tone) <= 49;
1066
+ }
1067
+ /**
1068
+ * Adjusts a tone such that white has 4.5 contrast, if the tone is
1069
+ * reasonably close to supporting it.
1070
+ */
1071
+ static enableLightForeground(tone) {
1072
+ if (DynamicColor.tonePrefersLightForeground(tone) && !DynamicColor.toneAllowsLightForeground(tone)) {
1073
+ return 49;
1074
+ }
1075
+ return tone;
1076
+ }
1077
+ /**
1078
+ * Returns a deep copy of this DynamicColor.
1079
+ */
1080
+ clone() {
1081
+ return DynamicColor.fromPalette({
1082
+ name: this.name,
1083
+ palette: this.palette,
1084
+ tone: this.tone,
1085
+ isBackground: this.isBackground,
1086
+ chromaMultiplier: this.chromaMultiplier,
1087
+ background: this.background,
1088
+ secondBackground: this.secondBackground,
1089
+ contrastCurve: this.contrastCurve,
1090
+ toneDeltaPair: this.toneDeltaPair
1091
+ });
1092
+ }
1093
+ /**
1094
+ * Clears the cache of HCT values for this color. For testing or debugging
1095
+ * purposes.
1096
+ */
1097
+ clearCache() {
1098
+ this.hctCache.clear();
1099
+ }
1100
+ /**
1101
+ * Returns a ARGB integer (i.e. a hex code).
1102
+ *
1103
+ * @param scheme Defines the conditions of the user interface, for example,
1104
+ * whether or not it is dark mode or light mode, and what the desired
1105
+ * contrast level is.
1106
+ */
1107
+ getArgb(scheme) {
1108
+ return this.getHct(scheme).toInt();
1109
+ }
1110
+ /**
1111
+ * Returns a color, expressed in the HCT color space, that this
1112
+ * DynamicColor is under the conditions in scheme.
1113
+ *
1114
+ * @param scheme Defines the conditions of the user interface, for example,
1115
+ * whether or not it is dark mode or light mode, and what the desired
1116
+ * contrast level is.
1117
+ */
1118
+ getHct(scheme) {
1119
+ const palette = this.palette(scheme);
1120
+ const tone = this.getTone(scheme);
1121
+ const hue = palette.hue;
1122
+ const chroma = palette.chroma * (this.chromaMultiplier ? this.chromaMultiplier(scheme) : 1);
1123
+ return Hct.from(hue, chroma, tone);
1124
+ }
1125
+ /**
1126
+ * Returns a tone, T in the HCT color space, that this DynamicColor is under
1127
+ * the conditions in scheme.
1128
+ *
1129
+ * @param scheme Defines the conditions of the user interface, for example,
1130
+ * whether or not it is dark mode or light mode, and what the desired
1131
+ * contrast level is.
1132
+ */
1133
+ getTone(scheme) {
1134
+ const toneDeltaPair = this.toneDeltaPair ? this.toneDeltaPair(scheme) : void 0;
1135
+ if (toneDeltaPair) {
1136
+ const roleA = toneDeltaPair.roleA;
1137
+ const roleB = toneDeltaPair.roleB;
1138
+ const polarity = toneDeltaPair.polarity;
1139
+ const constraint = toneDeltaPair.constraint;
1140
+ const absoluteDelta = polarity === "darker" || polarity === "relative_lighter" && scheme.isDark || polarity === "relative_darker" && !scheme.isDark ? -toneDeltaPair.delta : toneDeltaPair.delta;
1141
+ const amRoleA = this.name === roleA.name;
1142
+ const selfRole = amRoleA ? roleA : roleB;
1143
+ const refRole = amRoleA ? roleB : roleA;
1144
+ let selfTone = selfRole.tone(scheme);
1145
+ const refTone = refRole.getTone(scheme);
1146
+ const relativeDelta = absoluteDelta * (amRoleA ? 1 : -1);
1147
+ if (constraint === "exact") {
1148
+ selfTone = materialColorUtilities.clampDouble(0, 100, refTone + relativeDelta);
1149
+ } else if (constraint === "nearer") {
1150
+ if (relativeDelta > 0) {
1151
+ selfTone = materialColorUtilities.clampDouble(
1152
+ 0,
1153
+ 100,
1154
+ materialColorUtilities.clampDouble(refTone, refTone + relativeDelta, selfTone)
1155
+ );
1156
+ } else {
1157
+ selfTone = materialColorUtilities.clampDouble(
1158
+ 0,
1159
+ 100,
1160
+ materialColorUtilities.clampDouble(refTone + relativeDelta, refTone, selfTone)
1161
+ );
1162
+ }
1163
+ } else if (constraint === "farther") {
1164
+ if (relativeDelta > 0) {
1165
+ selfTone = materialColorUtilities.clampDouble(refTone + relativeDelta, 100, selfTone);
1166
+ } else {
1167
+ selfTone = materialColorUtilities.clampDouble(0, refTone + relativeDelta, selfTone);
1168
+ }
1169
+ }
1170
+ if (this.background && this.contrastCurve) {
1171
+ const background = this.background(scheme);
1172
+ const contrastCurve = this.contrastCurve(scheme);
1173
+ if (background && contrastCurve) {
1174
+ const bgTone = background.getTone(scheme);
1175
+ const selfContrast = contrastCurve.get(scheme.contrastLevel);
1176
+ selfTone = materialColorUtilities.Contrast.ratioOfTones(bgTone, selfTone) >= selfContrast && scheme.contrastLevel >= 0 ? selfTone : DynamicColor.foregroundTone(bgTone, selfContrast);
1177
+ }
1178
+ }
1179
+ if (this.isBackground && !this.name.endsWith("_fixed_dim")) {
1180
+ if (selfTone >= 57) {
1181
+ selfTone = materialColorUtilities.clampDouble(65, 100, selfTone);
1182
+ } else {
1183
+ selfTone = materialColorUtilities.clampDouble(0, 49, selfTone);
1184
+ }
1185
+ }
1186
+ return selfTone;
1187
+ } else {
1188
+ let answer = this.tone(scheme);
1189
+ if (this.background == void 0 || this.background(scheme) === void 0 || this.contrastCurve == void 0 || this.contrastCurve(scheme) === void 0) {
1190
+ return answer;
1191
+ }
1192
+ const bgTone = this.background(scheme).getTone(scheme);
1193
+ const desiredRatio = this.contrastCurve(scheme).get(
1194
+ scheme.contrastLevel
1195
+ );
1196
+ answer = materialColorUtilities.Contrast.ratioOfTones(bgTone, answer) >= desiredRatio && scheme.contrastLevel >= 0 ? answer : DynamicColor.foregroundTone(bgTone, desiredRatio);
1197
+ if (this.isBackground && !this.name.endsWith("_fixed_dim")) {
1198
+ if (answer >= 57) {
1199
+ answer = materialColorUtilities.clampDouble(65, 100, answer);
1200
+ } else {
1201
+ answer = materialColorUtilities.clampDouble(0, 49, answer);
1202
+ }
1203
+ }
1204
+ if (this.secondBackground == void 0 || this.secondBackground(scheme) === void 0) {
1205
+ return answer;
1206
+ }
1207
+ const [bg1, bg2] = [this.background, this.secondBackground];
1208
+ const [bgTone1, bgTone2] = [
1209
+ bg1(scheme).getTone(scheme),
1210
+ bg2(scheme).getTone(scheme)
1211
+ ];
1212
+ const [upper, lower] = [
1213
+ Math.max(bgTone1, bgTone2),
1214
+ Math.min(bgTone1, bgTone2)
1215
+ ];
1216
+ if (materialColorUtilities.Contrast.ratioOfTones(upper, answer) >= desiredRatio && materialColorUtilities.Contrast.ratioOfTones(lower, answer) >= desiredRatio) {
1217
+ return answer;
1218
+ }
1219
+ const lightOption = materialColorUtilities.Contrast.lighter(upper, desiredRatio);
1220
+ const darkOption = materialColorUtilities.Contrast.darker(lower, desiredRatio);
1221
+ const availables = [];
1222
+ if (lightOption !== -1) availables.push(lightOption);
1223
+ if (darkOption !== -1) availables.push(darkOption);
1224
+ const prefersLight = DynamicColor.tonePrefersLightForeground(bgTone1) || DynamicColor.tonePrefersLightForeground(bgTone2);
1225
+ if (prefersLight) {
1226
+ return lightOption < 0 ? 100 : lightOption;
1227
+ }
1228
+ if (availables.length === 1) {
1229
+ return availables[0];
1230
+ }
1231
+ return darkOption < 0 ? 0 : darkOption;
1232
+ }
1233
+ }
1234
+ }
1235
+ /**
1236
+ * @license
1237
+ * Copyright 2023 Google LLC
1238
+ *
1239
+ * Licensed under the Apache License, Version 2.0 (the "License");
1240
+ * you may not use this file except in compliance with the License.
1241
+ * You may obtain a copy of the License at
1242
+ *
1243
+ * http://www.apache.org/licenses/LICENSE-2.0
1244
+ *
1245
+ * Unless required by applicable law or agreed to in writing, software
1246
+ * distributed under the License is distributed on an "AS IS" BASIS,
1247
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1248
+ * See the License for the specific language governing permissions and
1249
+ * limitations under the License.
1250
+ */
1251
+ class ToneDeltaPair {
1252
+ /**
1253
+ * Documents a constraint in tone distance between two DynamicColors.
1254
+ *
1255
+ * The polarity is an adjective that describes "A", compared to "B".
1256
+ *
1257
+ * For instance, ToneDeltaPair(A, B, 15, 'darker', 'exact') states that
1258
+ * A's tone should be exactly 15 darker than B's.
1259
+ *
1260
+ * 'relative_darker' and 'relative_lighter' describes the tone adjustment
1261
+ * relative to the surface color trend (white in light mode; black in dark
1262
+ * mode). For instance, ToneDeltaPair(A, B, 10, 'relative_lighter',
1263
+ * 'farther') states that A should be at least 10 lighter than B in light
1264
+ * mode, and at least 10 darker than B in dark mode.
1265
+ *
1266
+ * @param roleA The first role in a pair.
1267
+ * @param roleB The second role in a pair.
1268
+ * @param delta Required difference between tones. Absolute value, negative
1269
+ * values have undefined behavior.
1270
+ * @param polarity The relative relation between tones of roleA and roleB,
1271
+ * as described above.
1272
+ * @param constraint How to fulfill the tone delta pair constraint.
1273
+ * @param stayTogether Whether these two roles should stay on the same side
1274
+ * of the "awkward zone" (T50-59). This is necessary for certain cases where
1275
+ * one role has two backgrounds.
1276
+ */
1277
+ constructor(roleA, roleB, delta, polarity, stayTogether, constraint) {
1278
+ this.roleA = roleA;
1279
+ this.roleB = roleB;
1280
+ this.delta = delta;
1281
+ this.polarity = polarity;
1282
+ this.stayTogether = stayTogether;
1283
+ this.constraint = constraint;
1284
+ this.constraint = constraint ?? "exact";
1285
+ }
1286
+ }
1287
+ function argbToRgb(argb) {
1288
+ return {
1289
+ r: argb >> 16 & 255,
1290
+ g: argb >> 8 & 255,
1291
+ b: argb & 255
1292
+ };
1293
+ }
1294
+ class ConfigurableColor {
1295
+ constructor(option, schemeService, colorService) {
1296
+ this.option = option;
1297
+ this.schemeService = schemeService;
1298
+ this.colorService = colorService;
1299
+ this.dynamicColor = null;
1300
+ }
1301
+ update(args) {
1302
+ this.dynamicColor = null;
1303
+ this.option = { ...this.option, ...args };
1304
+ }
1305
+ getHex() {
1306
+ return materialColorUtilities.hexFromArgb(this.getArgb());
1307
+ }
1308
+ getArgb() {
1309
+ return this.getMaterialColor().getArgb(this.schemeService.get());
1310
+ }
1311
+ getRgb() {
1312
+ return argbToRgb(this.getArgb());
1313
+ }
1314
+ getName() {
1315
+ return this.option.name.replace(/([A-Z])/g, "_$1").toLowerCase();
1316
+ }
1317
+ getMaterialColor() {
1318
+ if ("alias" in this.option) {
1319
+ if (!this.option.alias) {
1320
+ throw new Error("Alias option must be defined");
1321
+ }
1322
+ return this.colorService.get(this.option.alias).getMaterialColor();
1323
+ }
1324
+ if (!this.dynamicColor) {
1325
+ this.dynamicColor = DynamicColor.fromPalette({
1326
+ ...this.option,
1327
+ name: this.getName()
1328
+ });
1329
+ }
1330
+ return this.dynamicColor;
1331
+ }
1332
+ }
1333
+ function getCurve(defaultContrast) {
1334
+ if (defaultContrast === 1.5) {
1335
+ return new ContrastCurve(1.5, 1.5, 3, 4.5);
1336
+ } else if (defaultContrast === 3) {
1337
+ return new ContrastCurve(3, 3, 4.5, 7);
1338
+ } else if (defaultContrast === 4.5) {
1339
+ return new ContrastCurve(4.5, 4.5, 7, 11);
1340
+ } else if (defaultContrast === 6) {
1341
+ return new ContrastCurve(6, 6, 7, 11);
1342
+ } else if (defaultContrast === 7) {
1343
+ return new ContrastCurve(7, 7, 11, 21);
1344
+ } else if (defaultContrast === 9) {
1345
+ return new ContrastCurve(9, 9, 11, 21);
1346
+ } else if (defaultContrast === 11) {
1347
+ return new ContrastCurve(11, 11, 21, 21);
1348
+ } else if (defaultContrast === 21) {
1349
+ return new ContrastCurve(21, 21, 21, 21);
1350
+ } else {
1351
+ return new ContrastCurve(defaultContrast, defaultContrast, 7, 21);
1352
+ }
1353
+ }
1354
+ function tMaxC(palette, lowerBound = 0, upperBound = 100, chromaMultiplier = 1) {
1355
+ const answer = findBestToneForChroma(
1356
+ palette.hue,
1357
+ palette.chroma * chromaMultiplier,
1358
+ 100,
1359
+ true
1360
+ );
1361
+ return materialColorUtilities.clampDouble(lowerBound, upperBound, answer);
1362
+ }
1363
+ function tMinC(palette, lowerBound = 0, upperBound = 100) {
1364
+ const answer = findBestToneForChroma(palette.hue, palette.chroma, 0, false);
1365
+ return materialColorUtilities.clampDouble(lowerBound, upperBound, answer);
1366
+ }
1367
+ function findBestToneForChroma(hue, chroma, tone, byDecreasingTone) {
1368
+ let answer = tone;
1369
+ let bestCandidate = Hct.from(hue, chroma, answer);
1370
+ while (bestCandidate.chroma < chroma) {
1371
+ if (tone < 0 || tone > 100) {
1372
+ break;
1373
+ }
1374
+ tone += byDecreasingTone ? -1 : 1;
1375
+ const newCandidate = Hct.from(hue, chroma, tone);
1376
+ if (bestCandidate.chroma < newCandidate.chroma) {
1377
+ bestCandidate = newCandidate;
1378
+ answer = tone;
1379
+ }
1380
+ }
1381
+ return answer;
1382
+ }
1383
+ function capitalizeFirstLetter(string) {
1384
+ return string.charAt(0).toUpperCase() + string.slice(1);
1385
+ }
1386
+ const highestSurface = (s, colorService) => {
1387
+ if (colorService instanceof ColorApi) {
1388
+ return s.isDark ? colorService.getColor("surfaceBright").getMaterialColor() : colorService.getColor("surfaceDim").getMaterialColor();
1389
+ } else {
1390
+ return s.isDark ? colorService.get("surfaceBright").getMaterialColor() : colorService.get("surfaceDim").getMaterialColor();
1391
+ }
1392
+ };
1393
+ class ColorManager {
1394
+ constructor({ schemeManager }) {
1395
+ this.colorMap = /* @__PURE__ */ new Map();
1396
+ this.schemeManager = schemeManager;
1397
+ }
1398
+ createOrUpdate(key, args) {
1399
+ let colorEntity = this.colorMap.get(key);
1400
+ if (!colorEntity) {
1401
+ const { palette, alias } = args;
1402
+ if (palette) {
1403
+ colorEntity = new ConfigurableColor(
1404
+ { ...args, palette, name: key },
1405
+ this.schemeManager,
1406
+ this
1407
+ );
1408
+ this.colorMap.set(key, colorEntity);
1409
+ } else if (alias) {
1410
+ colorEntity = new ConfigurableColor(
1411
+ { ...args, alias, name: key },
1412
+ this.schemeManager,
1413
+ this
1414
+ );
1415
+ this.colorMap.set(key, colorEntity);
1416
+ } else {
1417
+ throw new Error(`Palette ${palette} does not exist from ${key}`);
1418
+ }
1419
+ } else {
1420
+ colorEntity.update({ ...args, name: key });
1421
+ this.colorMap.set(key, colorEntity);
1422
+ }
1423
+ return colorEntity;
1424
+ }
1425
+ remove(key) {
1426
+ return this.colorMap.delete(key);
1427
+ }
1428
+ get(key) {
1429
+ const colorEntity = this.colorMap.get(key);
1430
+ if (colorEntity) {
1431
+ return colorEntity;
1432
+ } else {
1433
+ throw new Error(`Color ${key} does not exist`);
1434
+ }
1435
+ }
1436
+ getAll() {
1437
+ return this.colorMap;
1438
+ }
1439
+ addFromPalette(key) {
1440
+ const colorKey = key;
1441
+ const colorDimKey = colorKey + "Dim";
1442
+ const ColorKey = capitalizeFirstLetter(key);
1443
+ const onColorKey = "on" + ColorKey;
1444
+ const colorContainerKey = colorKey + "Container";
1445
+ const onColorContainerKey = "on" + ColorKey + "Container";
1446
+ const colorFixedKey = colorKey + "Fixed";
1447
+ const colorFixedDimKey = colorKey + "FixedDim";
1448
+ const onColorFixedKey = "on" + ColorKey + "Fixed";
1449
+ const onColorFixedVariantKey = "on" + ColorKey + "FixedVariant";
1450
+ this.createOrUpdate(colorKey, {
1451
+ palette: (s) => s.getPalette(colorKey),
1452
+ tone: (s) => {
1453
+ if (s.variant === "neutral") {
1454
+ return s.isDark ? tMinC(s.getPalette(colorKey), 0, 98) : tMaxC(s.getPalette(colorKey));
1455
+ } else if (s.variant === "vibrant") {
1456
+ return tMaxC(s.getPalette(colorKey), 0, s.isDark ? 90 : 98);
1457
+ } else {
1458
+ return s.isDark ? 80 : tMaxC(s.getPalette(colorKey));
1459
+ }
1460
+ },
1461
+ isBackground: true,
1462
+ background: (s) => highestSurface(s, this),
1463
+ contrastCurve: (s) => getCurve(4.5),
1464
+ toneDeltaPair: (s) => new ToneDeltaPair(
1465
+ this.get(colorContainerKey).getMaterialColor(),
1466
+ this.get(colorKey).getMaterialColor(),
1467
+ 5,
1468
+ "relative_lighter",
1469
+ true,
1470
+ "farther"
1471
+ )
1472
+ });
1473
+ this.createOrUpdate(colorDimKey, {
1474
+ palette: (s) => s.getPalette(colorKey),
1475
+ tone: (s) => {
1476
+ if (s.variant === "neutral") {
1477
+ return 85;
1478
+ } else {
1479
+ return tMaxC(s.getPalette(colorKey), 0, 90);
1480
+ }
1481
+ },
1482
+ isBackground: true,
1483
+ background: (s) => this.get("surfaceContainerHigh").getMaterialColor(),
1484
+ contrastCurve: (s) => getCurve(4.5),
1485
+ toneDeltaPair: (s) => new ToneDeltaPair(
1486
+ this.get(colorDimKey).getMaterialColor(),
1487
+ this.get(colorKey).getMaterialColor(),
1488
+ 5,
1489
+ "darker",
1490
+ true,
1491
+ "farther"
1492
+ )
1493
+ });
1494
+ this.createOrUpdate(onColorKey, {
1495
+ palette: (s) => s.getPalette(colorKey),
1496
+ background: (s) => this.get(colorKey).getMaterialColor(),
1497
+ contrastCurve: (s) => getCurve(6)
1498
+ });
1499
+ this.createOrUpdate(colorContainerKey, {
1500
+ palette: (s) => s.getPalette(colorKey),
1501
+ tone: (s) => {
1502
+ if (s.variant === "vibrant") {
1503
+ return s.isDark ? tMinC(s.getPalette(colorKey), 30, 40) : tMaxC(s.getPalette(colorKey), 84, 90);
1504
+ } else if (s.variant === "expressive") {
1505
+ return s.isDark ? 15 : tMaxC(s.getPalette(colorKey), 90, 95);
1506
+ } else {
1507
+ return s.isDark ? 25 : 90;
1508
+ }
1509
+ },
1510
+ isBackground: true,
1511
+ background: (s) => highestSurface(s, this),
1512
+ toneDeltaPair: (s) => void 0,
1513
+ contrastCurve: (s) => s.contrastLevel > 0 ? getCurve(1.5) : void 0
1514
+ });
1515
+ this.createOrUpdate(onColorContainerKey, {
1516
+ palette: (s) => s.getPalette(colorKey),
1517
+ background: (s) => this.get(colorContainerKey).getMaterialColor(),
1518
+ contrastCurve: (s) => getCurve(6)
1519
+ });
1520
+ this.createOrUpdate(colorFixedKey, {
1521
+ palette: (s) => s.getPalette(colorKey),
1522
+ tone: (s) => {
1523
+ const tempS = Object.assign({}, s, { isDark: false, contrastLevel: 0 });
1524
+ return this.get(colorContainerKey).getMaterialColor().getTone(tempS);
1525
+ },
1526
+ isBackground: true,
1527
+ background: (s) => highestSurface(s, this),
1528
+ contrastCurve: (s) => s.contrastLevel > 0 ? getCurve(1.5) : void 0
1529
+ });
1530
+ this.createOrUpdate(colorFixedDimKey, {
1531
+ palette: (s) => s.getPalette(colorKey),
1532
+ tone: (s) => this.get(colorFixedKey).getMaterialColor().getTone(s),
1533
+ isBackground: true,
1534
+ toneDeltaPair: (s) => new ToneDeltaPair(
1535
+ this.get(colorFixedDimKey).getMaterialColor(),
1536
+ this.get(colorFixedKey).getMaterialColor(),
1537
+ 5,
1538
+ "darker",
1539
+ true,
1540
+ "exact"
1541
+ )
1542
+ });
1543
+ this.createOrUpdate(onColorFixedKey, {
1544
+ palette: (s) => s.getPalette(colorKey),
1545
+ background: (s) => this.get(colorFixedDimKey).getMaterialColor(),
1546
+ contrastCurve: (s) => getCurve(7)
1547
+ });
1548
+ this.createOrUpdate(onColorFixedVariantKey, {
1549
+ palette: (s) => s.getPalette(colorKey),
1550
+ background: (s) => this.get(colorFixedDimKey).getMaterialColor(),
1551
+ contrastCurve: (s) => getCurve(4.5)
1552
+ });
1553
+ }
1554
+ }
1555
+ const ColorModule = {
1556
+ colorManager: awilix.asClass(ColorManager).singleton(),
1557
+ colorApi: awilix.asClass(ColorApi).singleton()
1558
+ };
1559
+ class Scheme {
1560
+ constructor(options) {
1561
+ this.options = options;
1562
+ }
1563
+ get variant() {
1564
+ return this.options.variant.name;
1565
+ }
1566
+ get contrastLevel() {
1567
+ if (!this.options) {
1568
+ throw new Error("Scheme options is not set");
1569
+ }
1570
+ return this.options.contrastLevel;
1571
+ }
1572
+ get isDark() {
1573
+ if (!this.options) {
1574
+ throw new Error("Scheme options is not set");
1575
+ }
1576
+ return this.options.isDark;
1577
+ }
1578
+ get sourceColorHct() {
1579
+ if (!this.options) {
1580
+ throw new Error("Scheme options is not set");
1581
+ }
1582
+ return Hct.fromInt(this.options.sourceColorArgb);
1583
+ }
1584
+ getPalette(key) {
1585
+ if (!this.options) {
1586
+ throw new Error("Scheme options is not set");
1587
+ }
1588
+ const palette = this.options.palettes.get(key);
1589
+ if (!palette) {
1590
+ throw new Error(`Palette ${key} not found`);
1591
+ }
1592
+ return palette;
1593
+ }
1594
+ }
1595
+ class SchemeManager {
1596
+ createOrUpdate(options) {
1597
+ var _a, _b;
1598
+ this.options = {
1599
+ ...this.options,
1600
+ ...options,
1601
+ sourcesColorHex: {
1602
+ ...(_a = this.options) == null ? void 0 : _a.sourcesColorHex,
1603
+ ...options.sourcesColorHex
1604
+ },
1605
+ palettes: {
1606
+ ...(_b = this.options) == null ? void 0 : _b.palettes,
1607
+ ...options.palettes
1608
+ }
1609
+ };
1610
+ const palettes = /* @__PURE__ */ new Map();
1611
+ if (!this.options.sourcesColorHex.primary) {
1612
+ throw new Error("Primary source color is not set");
1613
+ }
1614
+ const sourceColorArgb = materialColorUtilities.argbFromHex(this.options.sourcesColorHex.primary);
1615
+ const sourceColorHct = Hct.fromInt(sourceColorArgb);
1616
+ if (!this.options.palettes) {
1617
+ return;
1618
+ }
1619
+ for (const [
1620
+ key,
1621
+ { sourceColorkey, tonalPalette: paletteFunction }
1622
+ ] of Object.entries(this.options.palettes)) {
1623
+ let palette;
1624
+ if (typeof sourceColorkey != "string") {
1625
+ palette = paletteFunction({
1626
+ sourceColorHct,
1627
+ isDark: options.isDark ?? false
1628
+ });
1629
+ } else {
1630
+ const sourceColorArgb2 = materialColorUtilities.argbFromHex(
1631
+ this.options.sourcesColorHex[sourceColorkey]
1632
+ );
1633
+ const colorHct = Hct.fromInt(sourceColorArgb2);
1634
+ palette = paletteFunction({
1635
+ sourceColorHct,
1636
+ colorHct,
1637
+ isDark: options.isDark ?? false
1638
+ });
1639
+ }
1640
+ palettes.set(key, palette);
1641
+ }
1642
+ this.schemeEntity = new Scheme({
1643
+ ...this.options,
1644
+ palettes,
1645
+ sourceColorArgb
1646
+ });
1647
+ }
1648
+ get() {
1649
+ if (!this.schemeEntity) {
1650
+ throw new Error("Scheme is not created");
1651
+ }
1652
+ return this.schemeEntity;
1653
+ }
1654
+ }
1655
+ class VariantManager {
1656
+ constructor({ schemeManager }) {
1657
+ this.customPalettes = {};
1658
+ this.schemeManager = schemeManager;
1659
+ }
1660
+ addCustomPalette(key, colorHex) {
1661
+ this.customPalettes[key] = colorHex;
1662
+ this.update();
1663
+ }
1664
+ set(variantEntity) {
1665
+ this.variantEntity = variantEntity;
1666
+ this.update();
1667
+ }
1668
+ update() {
1669
+ if (!this.variantEntity) return;
1670
+ const palettes = {};
1671
+ Object.keys(this.variantEntity.palettes).forEach((key) => {
1672
+ palettes[key] = { tonalPalette: this.variantEntity.palettes[key] };
1673
+ });
1674
+ const customPalettes = this.variantEntity.customPalettes;
1675
+ if (customPalettes) {
1676
+ Object.keys(this.customPalettes).forEach((key) => {
1677
+ palettes[key] = {
1678
+ sourceColorkey: key,
1679
+ tonalPalette: customPalettes
1680
+ };
1681
+ });
1682
+ }
1683
+ this.schemeManager.createOrUpdate({
1684
+ sourcesColorHex: this.customPalettes,
1685
+ palettes
1686
+ });
1687
+ }
1688
+ }
1689
+ materialColorUtilities.DynamicColor.fromPalette({
1690
+ name: "primary_palette_key_color",
1691
+ palette: (s) => s.primaryPalette,
1692
+ tone: (s) => s.primaryPalette.keyColor.tone
1693
+ });
1694
+ class ThemeApi {
1695
+ constructor({
1696
+ schemeManager,
1697
+ variantManager
1698
+ }) {
1699
+ this.schemeManager = schemeManager;
1700
+ this.variantManager = variantManager;
1701
+ }
1702
+ // addPalette({key, palette, addDefaultColors}: {key: string; palette: TonalPalette; addDefaultColors: boolean}) {
1703
+ // this.themeOptions.palettes.set(key, palette);
1704
+ // if (addDefaultColors){
1705
+ // this.colorService.addPalette(key)
1706
+ // }
1707
+ // }
1708
+ // create(args: ThemeOptions): SchemeService {
1709
+ // return new SchemeService(args, this.colorService)
1710
+ // }
1711
+ //
1712
+ // update(options: Partial<ThemeOptions>): SchemeService {
1713
+ // Object.assign(this.themeOptions, options);
1714
+ // return this.theme();
1715
+ // }
1716
+ create(options) {
1717
+ this.schemeManager.createOrUpdate({
1718
+ ...options,
1719
+ sourcesColorHex: { primary: options.sourceColorHex }
1720
+ });
1721
+ this.variantManager.set(options.variant);
1722
+ }
1723
+ update(options) {
1724
+ const themeOptions = { ...options };
1725
+ if (options.sourceColorHex)
1726
+ themeOptions.sourcesColorHex = { primary: options.sourceColorHex };
1727
+ this.schemeManager.createOrUpdate(themeOptions);
1728
+ if (options.variant) this.variantManager.set(options.variant);
1729
+ }
1730
+ addCustomPalette(key, colorHex) {
1731
+ this.variantManager.addCustomPalette(key, colorHex);
1732
+ }
1733
+ // theme(): SchemeService {
1734
+ // return new SchemeService(this.themeOptions, this.colorService)
1735
+ // }
1736
+ }
1737
+ const ThemeModule = {
1738
+ schemeManager: awilix.asClass(SchemeManager).singleton(),
1739
+ variantManager: awilix.asClass(VariantManager).singleton(),
1740
+ themeApi: awilix.asClass(ThemeApi).singleton()
1741
+ };
1742
+ const getPiecewiseHue = (sourceColorHct, hueBreakpoints, hues) => {
1743
+ const size = Math.min(hueBreakpoints.length - 1, hues.length);
1744
+ const sourceHue = sourceColorHct.hue;
1745
+ for (let i = 0; i < size; i++) {
1746
+ if (sourceHue >= hueBreakpoints[i] && sourceHue < hueBreakpoints[i + 1]) {
1747
+ return materialColorUtilities.sanitizeDegreesDouble(hues[i]);
1748
+ }
1749
+ }
1750
+ return sourceHue;
1751
+ };
1752
+ const getRotatedHue = (sourceColorHct, hueBreakpoints, rotations) => {
1753
+ let rotation = getPiecewiseHue(sourceColorHct, hueBreakpoints, rotations);
1754
+ if (Math.min(hueBreakpoints.length - 1, rotations.length) <= 0) {
1755
+ rotation = 0;
1756
+ }
1757
+ return materialColorUtilities.sanitizeDegreesDouble(sourceColorHct.hue + rotation);
1758
+ };
1759
+ class Variant {
1760
+ constructor(palettes = {}, name, customPalettes, colors) {
1761
+ this.palettes = palettes;
1762
+ this.name = name;
1763
+ this.customPalettes = customPalettes;
1764
+ this.colors = colors;
1765
+ }
1766
+ }
1767
+ const getExpressiveNeutralHue = (sourceColorHct) => {
1768
+ const hue = getRotatedHue(
1769
+ sourceColorHct,
1770
+ [0, 71, 124, 253, 278, 300, 360],
1771
+ [10, 0, 10, 0, 10, 0]
1772
+ );
1773
+ return hue;
1774
+ };
1775
+ const getExpressiveNeutralChroma = (sourceColorHct, isDark) => {
1776
+ const neutralHue = getExpressiveNeutralHue(sourceColorHct);
1777
+ return isDark ? Hct.isYellow(neutralHue) ? 6 : 14 : 18;
1778
+ };
1779
+ const expressiveVariant = {
1780
+ name: "expressive",
1781
+ palettes: {
1782
+ primary: ({ sourceColorHct, isDark }) => materialColorUtilities.TonalPalette.fromHueAndChroma(sourceColorHct.hue, isDark ? 36 : 48),
1783
+ secondary: ({ sourceColorHct, isDark }) => materialColorUtilities.TonalPalette.fromHueAndChroma(
1784
+ getRotatedHue(
1785
+ sourceColorHct,
1786
+ [0, 105, 140, 204, 253, 278, 300, 333, 360],
1787
+ [-160, 155, -100, 96, -96, -156, -165, -160]
1788
+ ),
1789
+ isDark ? 16 : 24
1790
+ ),
1791
+ tertiary: ({ sourceColorHct }) => materialColorUtilities.TonalPalette.fromHueAndChroma(
1792
+ getRotatedHue(
1793
+ sourceColorHct,
1794
+ [0, 105, 140, 204, 253, 278, 300, 333, 360],
1795
+ [-165, 160, -105, 101, -101, -160, -170, -165]
1796
+ ),
1797
+ 48
1798
+ ),
1799
+ neutral: ({ sourceColorHct, isDark }) => materialColorUtilities.TonalPalette.fromHueAndChroma(
1800
+ getExpressiveNeutralHue(sourceColorHct),
1801
+ getExpressiveNeutralChroma(sourceColorHct, isDark)
1802
+ ),
1803
+ neutralVariant: ({ sourceColorHct, isDark }) => {
1804
+ const expressiveNeutralHue = getExpressiveNeutralHue(sourceColorHct);
1805
+ const expressiveNeutralChroma = getExpressiveNeutralChroma(
1806
+ sourceColorHct,
1807
+ isDark
1808
+ );
1809
+ return materialColorUtilities.TonalPalette.fromHueAndChroma(
1810
+ expressiveNeutralHue,
1811
+ expressiveNeutralChroma * (expressiveNeutralHue >= 105 && expressiveNeutralHue < 125 ? 1.6 : 2.3)
1812
+ );
1813
+ },
1814
+ error: ({ sourceColorHct }) => {
1815
+ const errorHue = getPiecewiseHue(
1816
+ sourceColorHct,
1817
+ [0, 3, 13, 23, 33, 43, 153, 273, 360],
1818
+ [12, 22, 32, 12, 22, 32, 22, 12]
1819
+ );
1820
+ return materialColorUtilities.TonalPalette.fromHueAndChroma(errorHue, 64);
1821
+ }
1822
+ },
1823
+ customPalettes: ({ colorHct, isDark }) => materialColorUtilities.TonalPalette.fromHueAndChroma(
1824
+ getRotatedHue(
1825
+ colorHct,
1826
+ [0, 105, 140, 204, 253, 278, 300, 333, 360],
1827
+ [-160, 155, -100, 96, -96, -156, -165, -160]
1828
+ ),
1829
+ isDark ? 16 : 24
1830
+ )
1831
+ };
1832
+ const neutralVariant = {
1833
+ name: "neutral",
1834
+ palettes: {
1835
+ primary: ({ sourceColorHct }) => materialColorUtilities.TonalPalette.fromHueAndChroma(
1836
+ sourceColorHct.hue,
1837
+ Hct.isBlue(sourceColorHct.hue) ? 12 : 8
1838
+ ),
1839
+ secondary: ({ sourceColorHct }) => materialColorUtilities.TonalPalette.fromHueAndChroma(
1840
+ sourceColorHct.hue,
1841
+ Hct.isBlue(sourceColorHct.hue) ? 6 : 4
1842
+ ),
1843
+ tertiary: ({ sourceColorHct }) => materialColorUtilities.TonalPalette.fromHueAndChroma(
1844
+ getRotatedHue(
1845
+ sourceColorHct,
1846
+ [0, 38, 105, 161, 204, 278, 333, 360],
1847
+ [-32, 26, 10, -39, 24, -15, -32]
1848
+ ),
1849
+ 20
1850
+ ),
1851
+ neutral: ({ sourceColorHct }) => materialColorUtilities.TonalPalette.fromHueAndChroma(sourceColorHct.hue, 1.4),
1852
+ neutralVariant: ({ sourceColorHct }) => materialColorUtilities.TonalPalette.fromHueAndChroma(sourceColorHct.hue, 1.4 * 2.2),
1853
+ error: ({ sourceColorHct }) => {
1854
+ const errorHue = getPiecewiseHue(
1855
+ sourceColorHct,
1856
+ [0, 3, 13, 23, 33, 43, 153, 273, 360],
1857
+ [12, 22, 32, 12, 22, 32, 22, 12]
1858
+ );
1859
+ return materialColorUtilities.TonalPalette.fromHueAndChroma(errorHue, 50);
1860
+ }
1861
+ },
1862
+ customPalettes: ({ colorHct }) => materialColorUtilities.TonalPalette.fromHueAndChroma(
1863
+ colorHct.hue,
1864
+ Hct.isBlue(colorHct.hue) ? 6 : 4
1865
+ )
1866
+ };
1867
+ const tonalSpotVariant = {
1868
+ name: "tonalSpot",
1869
+ palettes: {
1870
+ primary: ({ sourceColorHct, isDark }) => materialColorUtilities.TonalPalette.fromHueAndChroma(sourceColorHct.hue, isDark ? 26 : 32),
1871
+ secondary: ({ sourceColorHct }) => materialColorUtilities.TonalPalette.fromHueAndChroma(sourceColorHct.hue, 16),
1872
+ tertiary: ({ sourceColorHct }) => materialColorUtilities.TonalPalette.fromHueAndChroma(
1873
+ getRotatedHue(
1874
+ sourceColorHct,
1875
+ [0, 20, 71, 161, 333, 360],
1876
+ [-40, 48, -32, 40, -32]
1877
+ ),
1878
+ 28
1879
+ ),
1880
+ neutral: ({ sourceColorHct }) => materialColorUtilities.TonalPalette.fromHueAndChroma(sourceColorHct.hue, 5),
1881
+ neutralVariant: ({ sourceColorHct }) => materialColorUtilities.TonalPalette.fromHueAndChroma(sourceColorHct.hue, 5 * 1.7),
1882
+ error: ({ sourceColorHct }) => {
1883
+ const errorHue = getPiecewiseHue(
1884
+ sourceColorHct,
1885
+ [0, 3, 13, 23, 33, 43, 153, 273, 360],
1886
+ [12, 22, 32, 12, 22, 32, 22, 12]
1887
+ );
1888
+ return materialColorUtilities.TonalPalette.fromHueAndChroma(errorHue, 60);
1889
+ }
1890
+ },
1891
+ customPalettes: ({ colorHct }) => materialColorUtilities.TonalPalette.fromHueAndChroma(colorHct.hue, 16)
1892
+ };
1893
+ const getVibrantNeutralHue = (sourceColorHct) => {
1894
+ return getRotatedHue(
1895
+ sourceColorHct,
1896
+ [0, 38, 105, 140, 333, 360],
1897
+ [-14, 10, -14, 10, -14]
1898
+ );
1899
+ };
1900
+ const getVibrantNeutralChroma = (sourceColorHct) => {
1901
+ getVibrantNeutralHue(sourceColorHct);
1902
+ return 28;
1903
+ };
1904
+ const vibrantVariant = {
1905
+ name: "vibrant",
1906
+ palettes: {
1907
+ primary: ({ sourceColorHct }) => materialColorUtilities.TonalPalette.fromHueAndChroma(sourceColorHct.hue, 74),
1908
+ secondary: ({ sourceColorHct }) => materialColorUtilities.TonalPalette.fromHueAndChroma(
1909
+ getRotatedHue(
1910
+ sourceColorHct,
1911
+ [0, 38, 105, 140, 333, 360],
1912
+ [-14, 10, -14, 10, -14]
1913
+ ),
1914
+ 56
1915
+ ),
1916
+ tertiary: ({ sourceColorHct }) => materialColorUtilities.TonalPalette.fromHueAndChroma(
1917
+ getRotatedHue(
1918
+ sourceColorHct,
1919
+ [0, 38, 71, 105, 140, 161, 253, 333, 360],
1920
+ [-72, 35, 24, -24, 62, 50, 62, -72]
1921
+ ),
1922
+ 56
1923
+ ),
1924
+ neutral: ({ sourceColorHct }) => materialColorUtilities.TonalPalette.fromHueAndChroma(
1925
+ getVibrantNeutralHue(sourceColorHct),
1926
+ getVibrantNeutralChroma(sourceColorHct)
1927
+ ),
1928
+ neutralVariant: ({ sourceColorHct }) => {
1929
+ const vibrantNeutralHue = getVibrantNeutralHue(sourceColorHct);
1930
+ const vibrantNeutralChroma = getVibrantNeutralChroma(sourceColorHct);
1931
+ return materialColorUtilities.TonalPalette.fromHueAndChroma(
1932
+ vibrantNeutralHue,
1933
+ vibrantNeutralChroma * 1.29
1934
+ );
1935
+ },
1936
+ error: ({ sourceColorHct }) => {
1937
+ const errorHue = getPiecewiseHue(
1938
+ sourceColorHct,
1939
+ [0, 3, 13, 23, 33, 43, 153, 273, 360],
1940
+ [12, 22, 32, 12, 22, 32, 22, 12]
1941
+ );
1942
+ return materialColorUtilities.TonalPalette.fromHueAndChroma(errorHue, 80);
1943
+ }
1944
+ },
1945
+ customPalettes: ({ colorHct }) => materialColorUtilities.TonalPalette.fromHueAndChroma(
1946
+ getRotatedHue(
1947
+ colorHct,
1948
+ [0, 38, 105, 140, 333, 360],
1949
+ [-14, 10, -14, 10, -14]
1950
+ ),
1951
+ 56
1952
+ )
1953
+ };
1954
+ const Variants = {
1955
+ Expressive: expressiveVariant,
1956
+ Neutral: neutralVariant,
1957
+ TonalSpot: tonalSpotVariant,
1958
+ Vibrant: vibrantVariant
1959
+ };
1960
+ const defaultColors = (colorService) => {
1961
+ const getColor = (key) => {
1962
+ return colorService.getColor(key).getMaterialColor();
1963
+ };
1964
+ const colors = {
1965
+ ////////////////////////////////////////////////////////////////
1966
+ // Surfaces [S] //
1967
+ ////////////////////////////////////////////////////////////////
1968
+ surface: {
1969
+ palette: (s) => s.getPalette("neutral"),
1970
+ tone: (s) => {
1971
+ if (s.isDark) {
1972
+ return 4;
1973
+ } else {
1974
+ if (Hct.isYellow(s.getPalette("neutral").hue)) {
1975
+ return 99;
1976
+ } else if (s.variant === "vibrant") {
1977
+ return 97;
1978
+ } else {
1979
+ return 98;
1980
+ }
1981
+ }
1982
+ },
1983
+ isBackground: true
1984
+ },
1985
+ surfaceDim: {
1986
+ palette: (s) => s.getPalette("neutral"),
1987
+ tone: (s) => {
1988
+ if (s.isDark) {
1989
+ return 4;
1990
+ } else {
1991
+ if (Hct.isYellow(s.getPalette("neutral").hue)) {
1992
+ return 90;
1993
+ } else if (s.variant === "vibrant") {
1994
+ return 85;
1995
+ } else {
1996
+ return 87;
1997
+ }
1998
+ }
1999
+ },
2000
+ isBackground: true,
2001
+ chromaMultiplier: (s) => {
2002
+ if (!s.isDark) {
2003
+ if (s.variant === "neutral") {
2004
+ return 2.5;
2005
+ } else if (s.variant === "tonalSpot") {
2006
+ return 1.7;
2007
+ } else if (s.variant === "expressive") {
2008
+ return Hct.isYellow(s.getPalette("neutral").hue) ? 2.7 : 1.75;
2009
+ } else if (s.variant === "vibrant") {
2010
+ return 1.36;
2011
+ }
2012
+ }
2013
+ return 1;
2014
+ }
2015
+ },
2016
+ surfaceBright: {
2017
+ palette: (s) => s.getPalette("neutral"),
2018
+ tone: (s) => {
2019
+ if (s.isDark) {
2020
+ return 18;
2021
+ } else {
2022
+ if (Hct.isYellow(s.getPalette("neutral").hue)) {
2023
+ return 99;
2024
+ } else if (s.variant === "vibrant") {
2025
+ return 97;
2026
+ } else {
2027
+ return 98;
2028
+ }
2029
+ }
2030
+ },
2031
+ isBackground: true,
2032
+ chromaMultiplier: (s) => {
2033
+ if (s.isDark) {
2034
+ if (s.variant === "neutral") {
2035
+ return 2.5;
2036
+ } else if (s.variant === "tonalSpot") {
2037
+ return 1.7;
2038
+ } else if (s.variant === "expressive") {
2039
+ return Hct.isYellow(s.getPalette("neutral").hue) ? 2.7 : 1.75;
2040
+ } else if (s.variant === "vibrant") {
2041
+ return 1.36;
2042
+ }
2043
+ }
2044
+ return 1;
2045
+ }
2046
+ },
2047
+ surfaceContainerLowest: {
2048
+ palette: (s) => s.getPalette("neutral"),
2049
+ tone: (s) => s.isDark ? 0 : 100,
2050
+ isBackground: true
2051
+ },
2052
+ surfaceContainerLow: {
2053
+ palette: (s) => s.getPalette("neutral"),
2054
+ tone: (s) => {
2055
+ if (s.isDark) {
2056
+ return 6;
2057
+ } else {
2058
+ if (Hct.isYellow(s.getPalette("neutral").hue)) {
2059
+ return 98;
2060
+ } else if (s.variant === "vibrant") {
2061
+ return 95;
2062
+ } else {
2063
+ return 96;
2064
+ }
2065
+ }
2066
+ },
2067
+ isBackground: true,
2068
+ chromaMultiplier: (s) => {
2069
+ if (s.variant === "neutral") {
2070
+ return 1.3;
2071
+ } else if (s.variant === "tonalSpot") {
2072
+ return 1.25;
2073
+ } else if (s.variant === "expressive") {
2074
+ return Hct.isYellow(s.getPalette("neutral").hue) ? 1.3 : 1.15;
2075
+ } else if (s.variant === "vibrant") {
2076
+ return 1.08;
2077
+ }
2078
+ return 1;
2079
+ }
2080
+ },
2081
+ surfaceContainer: {
2082
+ palette: (s) => s.getPalette("neutral"),
2083
+ tone: (s) => {
2084
+ if (s.isDark) {
2085
+ return 9;
2086
+ } else {
2087
+ if (Hct.isYellow(s.getPalette("neutral").hue)) {
2088
+ return 96;
2089
+ } else if (s.variant === "vibrant") {
2090
+ return 92;
2091
+ } else {
2092
+ return 94;
2093
+ }
2094
+ }
2095
+ },
2096
+ isBackground: true,
2097
+ chromaMultiplier: (s) => {
2098
+ if (s.variant === "neutral") {
2099
+ return 1.6;
2100
+ } else if (s.variant === "tonalSpot") {
2101
+ return 1.4;
2102
+ } else if (s.variant === "expressive") {
2103
+ return Hct.isYellow(s.getPalette("neutral").hue) ? 1.6 : 1.3;
2104
+ } else if (s.variant === "vibrant") {
2105
+ return 1.15;
2106
+ }
2107
+ return 1;
2108
+ }
2109
+ },
2110
+ surfaceContainerHigh: {
2111
+ palette: (s) => s.getPalette("neutral"),
2112
+ tone: (s) => {
2113
+ if (s.isDark) {
2114
+ return 12;
2115
+ } else {
2116
+ if (Hct.isYellow(s.getPalette("neutral").hue)) {
2117
+ return 94;
2118
+ } else if (s.variant === "vibrant") {
2119
+ return 90;
2120
+ } else {
2121
+ return 92;
2122
+ }
2123
+ }
2124
+ },
2125
+ isBackground: true,
2126
+ chromaMultiplier: (s) => {
2127
+ if (s.variant === "neutral") {
2128
+ return 1.9;
2129
+ } else if (s.variant === "tonalSpot") {
2130
+ return 1.5;
2131
+ } else if (s.variant === "expressive") {
2132
+ return Hct.isYellow(s.getPalette("neutral").hue) ? 1.95 : 1.45;
2133
+ } else if (s.variant === "vibrant") {
2134
+ return 1.22;
2135
+ }
2136
+ return 1;
2137
+ }
2138
+ },
2139
+ surfaceContainerHighest: {
2140
+ palette: (s) => s.getPalette("neutral"),
2141
+ tone: (s) => {
2142
+ if (s.isDark) {
2143
+ return 15;
2144
+ } else {
2145
+ if (Hct.isYellow(s.getPalette("neutral").hue)) {
2146
+ return 92;
2147
+ } else if (s.variant === "vibrant") {
2148
+ return 88;
2149
+ } else {
2150
+ return 90;
2151
+ }
2152
+ }
2153
+ },
2154
+ isBackground: true,
2155
+ chromaMultiplier: (s) => {
2156
+ if (s.variant === "neutral") {
2157
+ return 2.2;
2158
+ } else if (s.variant === "tonalSpot") {
2159
+ return 1.7;
2160
+ } else if (s.variant === "expressive") {
2161
+ return Hct.isYellow(s.getPalette("neutral").hue) ? 2.3 : 1.6;
2162
+ } else if (s.variant === "vibrant") {
2163
+ return 1.29;
2164
+ } else {
2165
+ return 1;
2166
+ }
2167
+ }
2168
+ },
2169
+ onSurface: {
2170
+ palette: (s) => s.getPalette("neutral"),
2171
+ tone: (s) => {
2172
+ if (s.variant === "vibrant") {
2173
+ return tMaxC(s.getPalette("neutral"), 0, 100, 1.1);
2174
+ } else {
2175
+ return DynamicColor.getInitialToneFromBackground(
2176
+ (s2) => highestSurface(s2, colorService)
2177
+ )(s);
2178
+ }
2179
+ },
2180
+ chromaMultiplier: (s) => {
2181
+ if (s.variant === "neutral") {
2182
+ return 2.2;
2183
+ } else if (s.variant === "tonalSpot") {
2184
+ return 1.7;
2185
+ } else if (s.variant === "expressive") {
2186
+ return Hct.isYellow(s.getPalette("neutral").hue) ? s.isDark ? 3 : 2.3 : 1.6;
2187
+ }
2188
+ return 1;
2189
+ },
2190
+ background: (s) => highestSurface(s, colorService),
2191
+ contrastCurve: (s) => s.isDark ? getCurve(11) : getCurve(9)
2192
+ },
2193
+ onSurfaceVariant: {
2194
+ palette: (s) => s.getPalette("neutralVariant"),
2195
+ chromaMultiplier: (s) => {
2196
+ if (s.variant === "neutral") {
2197
+ return 2.2;
2198
+ } else if (s.variant === "tonalSpot") {
2199
+ return 1.7;
2200
+ } else if (s.variant === "expressive") {
2201
+ return Hct.isYellow(s.getPalette("neutral").hue) ? s.isDark ? 3 : 2.3 : 1.6;
2202
+ }
2203
+ return 1;
2204
+ },
2205
+ background: (s) => highestSurface(s, colorService),
2206
+ contrastCurve: (s) => s.isDark ? getCurve(6) : getCurve(4.5)
2207
+ },
2208
+ outline: {
2209
+ palette: (s) => s.getPalette("neutralVariant"),
2210
+ chromaMultiplier: (s) => {
2211
+ if (s.variant === "neutral") {
2212
+ return 2.2;
2213
+ } else if (s.variant === "tonalSpot") {
2214
+ return 1.7;
2215
+ } else if (s.variant === "expressive") {
2216
+ return Hct.isYellow(s.getPalette("neutral").hue) ? s.isDark ? 3 : 2.3 : 1.6;
2217
+ }
2218
+ return 1;
2219
+ },
2220
+ background: (s) => highestSurface(s, colorService),
2221
+ contrastCurve: (s) => getCurve(3)
2222
+ },
2223
+ outlineVariant: {
2224
+ palette: (s) => s.getPalette("neutralVariant"),
2225
+ chromaMultiplier: (s) => {
2226
+ if (s.variant === "neutral") {
2227
+ return 2.2;
2228
+ } else if (s.variant === "tonalSpot") {
2229
+ return 1.7;
2230
+ } else if (s.variant === "expressive") {
2231
+ return Hct.isYellow(s.getPalette("neutral").hue) ? s.isDark ? 3 : 2.3 : 1.6;
2232
+ }
2233
+ return 1;
2234
+ },
2235
+ background: (s) => highestSurface(s, colorService),
2236
+ contrastCurve: (s) => getCurve(1.5)
2237
+ },
2238
+ inverseSurface: {
2239
+ palette: (s) => s.getPalette("neutral"),
2240
+ tone: (s) => s.isDark ? 98 : 4,
2241
+ isBackground: true
2242
+ },
2243
+ inverseOnSurface: {
2244
+ palette: (s) => s.getPalette("neutral"),
2245
+ tone: (s) => s.isDark ? 20 : 95,
2246
+ background: (s) => colorService.getColor("inverseSurface").getMaterialColor(),
2247
+ contrastCurve: (s) => getCurve(7)
2248
+ },
2249
+ ////////////////////////////////////////////////////////////////
2250
+ // Primaries [P] //
2251
+ ////////////////////////////////////////////////////////////////
2252
+ primary: {
2253
+ palette: (s) => s.getPalette("primary"),
2254
+ tone: (s) => {
2255
+ if (s.variant === "neutral") {
2256
+ return s.isDark ? 80 : 40;
2257
+ } else if (s.variant === "tonalSpot") {
2258
+ if (s.isDark) {
2259
+ return 80;
2260
+ } else {
2261
+ return tMaxC(s.getPalette("primary"));
2262
+ }
2263
+ } else if (s.variant === "expressive") {
2264
+ return tMaxC(
2265
+ s.getPalette("primary"),
2266
+ 0,
2267
+ Hct.isYellow(s.getPalette("primary").hue) ? 25 : Hct.isCyan(s.getPalette("primary").hue) ? 88 : 98
2268
+ );
2269
+ } else {
2270
+ return tMaxC(
2271
+ s.getPalette("primary"),
2272
+ 0,
2273
+ Hct.isCyan(s.getPalette("primary").hue) ? 88 : 98
2274
+ );
2275
+ }
2276
+ },
2277
+ isBackground: true,
2278
+ background: (s) => highestSurface(s, colorService),
2279
+ contrastCurve: (s) => getCurve(4.5),
2280
+ toneDeltaPair: (s) => new ToneDeltaPair(
2281
+ colorService.getColor("primaryContainer").getMaterialColor(),
2282
+ colorService.getColor("primary").getMaterialColor(),
2283
+ 5,
2284
+ "relative_lighter",
2285
+ true,
2286
+ "farther"
2287
+ )
2288
+ },
2289
+ primaryDim: {
2290
+ palette: (s) => s.getPalette("primary"),
2291
+ tone: (s) => {
2292
+ if (s.variant === "neutral") {
2293
+ return 85;
2294
+ } else if (s.variant === "tonalSpot") {
2295
+ return tMaxC(s.getPalette("primary"), 0, 90);
2296
+ } else {
2297
+ return tMaxC(s.getPalette("primary"));
2298
+ }
2299
+ },
2300
+ isBackground: true,
2301
+ background: (s) => getColor("surfaceContainerHigh"),
2302
+ contrastCurve: (s) => getCurve(4.5),
2303
+ toneDeltaPair: (s) => new ToneDeltaPair(
2304
+ colorService.getColor("primaryDim").getMaterialColor(),
2305
+ colorService.getColor("primary").getMaterialColor(),
2306
+ 5,
2307
+ "darker",
2308
+ true,
2309
+ "farther"
2310
+ )
2311
+ },
2312
+ onPrimary: {
2313
+ palette: (s) => s.getPalette("primary"),
2314
+ background: (s) => colorService.getColor("primary").getMaterialColor(),
2315
+ contrastCurve: (s) => getCurve(6)
2316
+ },
2317
+ primaryContainer: {
2318
+ palette: (s) => s.getPalette("primary"),
2319
+ tone: (s) => {
2320
+ if (s.variant === "neutral") {
2321
+ return s.isDark ? 30 : 90;
2322
+ } else if (s.variant === "tonalSpot") {
2323
+ return s.isDark ? tMinC(s.getPalette("primary"), 35, 93) : tMaxC(s.getPalette("primary"), 0, 90);
2324
+ } else if (s.variant === "expressive") {
2325
+ return s.isDark ? tMaxC(s.getPalette("primary"), 30, 93) : tMaxC(
2326
+ s.getPalette("primary"),
2327
+ 78,
2328
+ Hct.isCyan(s.getPalette("primary").hue) ? 88 : 90
2329
+ );
2330
+ } else {
2331
+ return s.isDark ? tMinC(s.getPalette("primary"), 66, 93) : tMaxC(
2332
+ s.getPalette("primary"),
2333
+ 66,
2334
+ Hct.isCyan(s.getPalette("primary").hue) ? 88 : 93
2335
+ );
2336
+ }
2337
+ },
2338
+ isBackground: true,
2339
+ background: (s) => highestSurface(s, colorService),
2340
+ toneDeltaPair: (s) => void 0,
2341
+ contrastCurve: (s) => s.contrastLevel > 0 ? getCurve(1.5) : void 0
2342
+ },
2343
+ onPrimaryContainer: {
2344
+ palette: (s) => s.getPalette("primary"),
2345
+ background: (s) => colorService.getColor("primaryContainer").getMaterialColor(),
2346
+ contrastCurve: (s) => getCurve(6)
2347
+ },
2348
+ primaryFixed: {
2349
+ palette: (s) => s.getPalette("primary"),
2350
+ tone: (s) => {
2351
+ const tempS = new Scheme({
2352
+ ...s.options,
2353
+ isDark: false,
2354
+ contrastLevel: 0
2355
+ });
2356
+ return getColor("primaryContainer").getTone(tempS);
2357
+ },
2358
+ isBackground: true,
2359
+ background: (s) => highestSurface(s, colorService),
2360
+ contrastCurve: (s) => s.contrastLevel > 0 ? getCurve(1.5) : void 0
2361
+ },
2362
+ primaryFixedDim: {
2363
+ palette: (s) => s.getPalette("primary"),
2364
+ tone: (s) => colorService.getColor("primaryFixed").getMaterialColor().getTone(s),
2365
+ isBackground: true,
2366
+ toneDeltaPair: (s) => new ToneDeltaPair(
2367
+ getColor("primaryFixedDim"),
2368
+ getColor("primaryFixed"),
2369
+ 5,
2370
+ "darker",
2371
+ true,
2372
+ "exact"
2373
+ )
2374
+ },
2375
+ onPrimaryFixed: {
2376
+ palette: (s) => s.getPalette("primary"),
2377
+ background: (s) => colorService.getColor("primaryFixedDim").getMaterialColor(),
2378
+ contrastCurve: (s) => getCurve(7)
2379
+ },
2380
+ onPrimaryFixedVariant: {
2381
+ palette: (s) => s.getPalette("primary"),
2382
+ background: (s) => colorService.getColor("primaryFixedDim").getMaterialColor(),
2383
+ contrastCurve: (s) => getCurve(4.5)
2384
+ },
2385
+ inversePrimary: {
2386
+ palette: (s) => s.getPalette("primary"),
2387
+ tone: (s) => tMaxC(s.getPalette("primary")),
2388
+ background: (s) => colorService.getColor("inverseSurface").getMaterialColor(),
2389
+ contrastCurve: (s) => getCurve(6)
2390
+ },
2391
+ ////////////////////////////////////////////////////////////////
2392
+ // Secondaries [Q] //
2393
+ ////////////////////////////////////////////////////////////////
2394
+ secondary: {
2395
+ palette: (s) => s.getPalette("secondary"),
2396
+ tone: (s) => {
2397
+ if (s.variant === "neutral") {
2398
+ return s.isDark ? tMinC(s.getPalette("secondary"), 0, 98) : tMaxC(s.getPalette("secondary"));
2399
+ } else if (s.variant === "vibrant") {
2400
+ return tMaxC(s.getPalette("secondary"), 0, s.isDark ? 90 : 98);
2401
+ } else {
2402
+ return s.isDark ? 80 : tMaxC(s.getPalette("secondary"));
2403
+ }
2404
+ },
2405
+ isBackground: true,
2406
+ background: (s) => highestSurface(s, colorService),
2407
+ contrastCurve: (s) => getCurve(4.5),
2408
+ toneDeltaPair: (s) => new ToneDeltaPair(
2409
+ getColor("secondaryContainer"),
2410
+ getColor("secondary"),
2411
+ 5,
2412
+ "relative_lighter",
2413
+ true,
2414
+ "farther"
2415
+ )
2416
+ },
2417
+ secondaryDim: {
2418
+ palette: (s) => s.getPalette("secondary"),
2419
+ tone: (s) => {
2420
+ if (s.variant === "neutral") {
2421
+ return 85;
2422
+ } else {
2423
+ return tMaxC(s.getPalette("secondary"), 0, 90);
2424
+ }
2425
+ },
2426
+ isBackground: true,
2427
+ background: (s) => getColor("surfaceContainerHigh"),
2428
+ contrastCurve: (s) => getCurve(4.5),
2429
+ toneDeltaPair: (s) => new ToneDeltaPair(
2430
+ getColor("secondaryDim"),
2431
+ getColor("secondary"),
2432
+ 5,
2433
+ "darker",
2434
+ true,
2435
+ "farther"
2436
+ )
2437
+ },
2438
+ onSecondary: {
2439
+ palette: (s) => s.getPalette("secondary"),
2440
+ background: (s) => getColor("secondary"),
2441
+ contrastCurve: (s) => getCurve(6)
2442
+ },
2443
+ secondaryContainer: {
2444
+ palette: (s) => s.getPalette("secondary"),
2445
+ tone: (s) => {
2446
+ if (s.variant === "vibrant") {
2447
+ return s.isDark ? tMinC(s.getPalette("secondary"), 30, 40) : tMaxC(s.getPalette("secondary"), 84, 90);
2448
+ } else if (s.variant === "expressive") {
2449
+ return s.isDark ? 15 : tMaxC(s.getPalette("secondary"), 90, 95);
2450
+ } else {
2451
+ return s.isDark ? 25 : 90;
2452
+ }
2453
+ },
2454
+ isBackground: true,
2455
+ background: (s) => highestSurface(s, colorService),
2456
+ toneDeltaPair: (s) => void 0,
2457
+ contrastCurve: (s) => s.contrastLevel > 0 ? getCurve(1.5) : void 0
2458
+ },
2459
+ onSecondaryContainer: {
2460
+ palette: (s) => s.getPalette("secondary"),
2461
+ background: (s) => getColor("secondaryContainer"),
2462
+ contrastCurve: (s) => getCurve(6)
2463
+ },
2464
+ secondaryFixed: {
2465
+ palette: (s) => s.getPalette("secondary"),
2466
+ tone: (s) => {
2467
+ const tempS = new Scheme({
2468
+ ...s.options,
2469
+ isDark: false,
2470
+ contrastLevel: 0
2471
+ });
2472
+ return getColor("secondaryContainer").getTone(tempS);
2473
+ },
2474
+ isBackground: true,
2475
+ background: (s) => highestSurface(s, colorService),
2476
+ contrastCurve: (s) => s.contrastLevel > 0 ? getCurve(1.5) : void 0
2477
+ },
2478
+ secondaryFixedDim: {
2479
+ palette: (s) => s.getPalette("secondary"),
2480
+ tone: (s) => getColor("secondaryFixed").getTone(s),
2481
+ isBackground: true,
2482
+ toneDeltaPair: (s) => new ToneDeltaPair(
2483
+ getColor("secondaryFixedDim"),
2484
+ getColor("secondaryFixed"),
2485
+ 5,
2486
+ "darker",
2487
+ true,
2488
+ "exact"
2489
+ )
2490
+ },
2491
+ onSecondaryFixed: {
2492
+ palette: (s) => s.getPalette("secondary"),
2493
+ background: (s) => getColor("secondaryFixedDim"),
2494
+ contrastCurve: (s) => getCurve(7)
2495
+ },
2496
+ onSecondaryFixedVariant: {
2497
+ palette: (s) => s.getPalette("secondary"),
2498
+ background: (s) => getColor("secondaryFixedDim"),
2499
+ contrastCurve: (s) => getCurve(4.5)
2500
+ },
2501
+ ////////////////////////////////////////////////////////////////
2502
+ // Tertiaries [T] //
2503
+ ////////////////////////////////////////////////////////////////
2504
+ tertiary: {
2505
+ palette: (s) => s.getPalette("tertiary"),
2506
+ tone: (s) => {
2507
+ if (s.variant === "expressive" || s.variant === "vibrant") {
2508
+ return tMaxC(
2509
+ s.getPalette("tertiary"),
2510
+ 0,
2511
+ Hct.isCyan(s.getPalette("tertiary").hue) ? 88 : s.isDark ? 98 : 100
2512
+ );
2513
+ } else {
2514
+ return s.isDark ? tMaxC(s.getPalette("tertiary"), 0, 98) : tMaxC(s.getPalette("tertiary"));
2515
+ }
2516
+ },
2517
+ isBackground: true,
2518
+ background: (s) => highestSurface(s, colorService),
2519
+ contrastCurve: (s) => getCurve(4.5),
2520
+ toneDeltaPair: (s) => new ToneDeltaPair(
2521
+ getColor("tertiaryContainer"),
2522
+ getColor("tertiary"),
2523
+ 5,
2524
+ "relative_lighter",
2525
+ true,
2526
+ "farther"
2527
+ )
2528
+ },
2529
+ tertiaryDim: {
2530
+ palette: (s) => s.getPalette("tertiary"),
2531
+ tone: (s) => {
2532
+ if (s.variant === "tonalSpot") {
2533
+ return tMaxC(s.getPalette("tertiary"), 0, 90);
2534
+ } else {
2535
+ return tMaxC(s.getPalette("tertiary"));
2536
+ }
2537
+ },
2538
+ isBackground: true,
2539
+ background: (s) => getColor("surfaceContainerHigh"),
2540
+ contrastCurve: (s) => getCurve(4.5),
2541
+ toneDeltaPair: (s) => new ToneDeltaPair(
2542
+ getColor("tertiaryDim"),
2543
+ getColor("tertiary"),
2544
+ 5,
2545
+ "darker",
2546
+ true,
2547
+ "farther"
2548
+ )
2549
+ },
2550
+ onTertiary: {
2551
+ palette: (s) => s.getPalette("tertiary"),
2552
+ background: (s) => getColor("tertiary"),
2553
+ contrastCurve: (s) => getCurve(6)
2554
+ },
2555
+ tertiaryContainer: {
2556
+ palette: (s) => s.getPalette("tertiary"),
2557
+ tone: (s) => {
2558
+ if (s.variant === "neutral") {
2559
+ return s.isDark ? tMaxC(s.getPalette("tertiary"), 0, 93) : tMaxC(s.getPalette("tertiary"), 0, 96);
2560
+ } else if (s.variant === "tonalSpot") {
2561
+ return tMaxC(s.getPalette("tertiary"), 0, s.isDark ? 93 : 100);
2562
+ } else if (s.variant === "expressive") {
2563
+ return tMaxC(
2564
+ s.getPalette("tertiary"),
2565
+ 75,
2566
+ Hct.isCyan(s.getPalette("tertiary").hue) ? 88 : s.isDark ? 93 : 100
2567
+ );
2568
+ } else {
2569
+ return s.isDark ? tMaxC(s.getPalette("tertiary"), 0, 93) : tMaxC(s.getPalette("tertiary"), 72, 100);
2570
+ }
2571
+ },
2572
+ isBackground: true,
2573
+ background: (s) => highestSurface(s, colorService),
2574
+ toneDeltaPair: (s) => void 0,
2575
+ contrastCurve: (s) => s.contrastLevel > 0 ? getCurve(1.5) : void 0
2576
+ },
2577
+ onTertiaryContainer: {
2578
+ palette: (s) => s.getPalette("tertiary"),
2579
+ background: (s) => getColor("tertiaryContainer"),
2580
+ contrastCurve: (s) => getCurve(6)
2581
+ },
2582
+ tertiaryFixed: {
2583
+ palette: (s) => s.getPalette("tertiary"),
2584
+ tone: (s) => {
2585
+ const tempS = new Scheme({
2586
+ ...s.options,
2587
+ isDark: false,
2588
+ contrastLevel: 0
2589
+ });
2590
+ return getColor("tertiaryContainer").getTone(tempS);
2591
+ },
2592
+ isBackground: true,
2593
+ background: (s) => highestSurface(s, colorService),
2594
+ contrastCurve: (s) => s.contrastLevel > 0 ? getCurve(1.5) : void 0
2595
+ },
2596
+ tertiaryFixedDim: {
2597
+ palette: (s) => s.getPalette("tertiary"),
2598
+ tone: (s) => getColor("tertiaryFixed").getTone(s),
2599
+ isBackground: true,
2600
+ toneDeltaPair: (s) => new ToneDeltaPair(
2601
+ getColor("tertiaryFixedDim"),
2602
+ getColor("tertiaryFixed"),
2603
+ 5,
2604
+ "darker",
2605
+ true,
2606
+ "exact"
2607
+ )
2608
+ },
2609
+ onTertiaryFixed: {
2610
+ palette: (s) => s.getPalette("tertiary"),
2611
+ background: (s) => getColor("tertiaryFixedDim"),
2612
+ contrastCurve: (s) => getCurve(7)
2613
+ },
2614
+ onTertiaryFixedVariant: {
2615
+ palette: (s) => s.getPalette("tertiary"),
2616
+ background: (s) => getColor("tertiaryFixedDim"),
2617
+ contrastCurve: (s) => getCurve(4.5)
2618
+ },
2619
+ ////////////////////////////////////////////////////////////////
2620
+ // Errors [E] //
2621
+ ////////////////////////////////////////////////////////////////
2622
+ error: {
2623
+ palette: (s) => s.getPalette("error"),
2624
+ tone: (s) => {
2625
+ return s.isDark ? tMinC(s.getPalette("error"), 0, 98) : tMaxC(s.getPalette("error"));
2626
+ },
2627
+ isBackground: true,
2628
+ background: (s) => highestSurface(s, colorService),
2629
+ contrastCurve: (s) => getCurve(4.5),
2630
+ toneDeltaPair: (s) => new ToneDeltaPair(
2631
+ colorService.getColor("errorContainer").getMaterialColor(),
2632
+ colorService.getColor("error").getMaterialColor(),
2633
+ 5,
2634
+ "relative_lighter",
2635
+ true,
2636
+ "farther"
2637
+ )
2638
+ },
2639
+ errorDim: {
2640
+ palette: (s) => s.getPalette("error"),
2641
+ tone: (s) => tMinC(s.getPalette("error")),
2642
+ isBackground: true,
2643
+ background: (s) => getColor("surfaceContainerHigh"),
2644
+ contrastCurve: (s) => getCurve(4.5),
2645
+ toneDeltaPair: (s) => new ToneDeltaPair(
2646
+ getColor("errorDim"),
2647
+ getColor("error"),
2648
+ 5,
2649
+ "darker",
2650
+ true,
2651
+ "farther"
2652
+ )
2653
+ },
2654
+ onError: {
2655
+ palette: (s) => s.getPalette("error"),
2656
+ background: (s) => colorService.getColor("error").getMaterialColor(),
2657
+ contrastCurve: (s) => getCurve(6)
2658
+ },
2659
+ errorContainer: {
2660
+ palette: (s) => s.getPalette("error"),
2661
+ tone: (s) => {
2662
+ return s.isDark ? tMinC(s.getPalette("error"), 30, 93) : tMaxC(s.getPalette("error"), 0, 90);
2663
+ },
2664
+ isBackground: true,
2665
+ background: (s) => highestSurface(s, colorService),
2666
+ toneDeltaPair: (s) => void 0,
2667
+ contrastCurve: (s) => s.contrastLevel > 0 ? getCurve(1.5) : void 0
2668
+ },
2669
+ onErrorContainer: {
2670
+ palette: (s) => s.getPalette("error"),
2671
+ background: (s) => colorService.getColor("errorContainer").getMaterialColor(),
2672
+ contrastCurve: (s) => getCurve(4.5)
2673
+ },
2674
+ /////////////////////////////////////////////////////////////////
2675
+ // Remapped Colors //
2676
+ /////////////////////////////////////////////////////////////////
2677
+ surfaceVariant: {
2678
+ alias: "surfaceContainerHighest"
2679
+ },
2680
+ surfaceTint: {
2681
+ alias: "primary"
2682
+ },
2683
+ background: {
2684
+ alias: "surface"
2685
+ },
2686
+ onBackground: {
2687
+ alias: "onSurface"
2688
+ }
2689
+ };
2690
+ return {
2691
+ colors
2692
+ };
2693
+ };
2694
+ class API {
2695
+ constructor({
2696
+ colorApi,
2697
+ themeApi,
2698
+ pluginApi
2699
+ }) {
2700
+ this.plugins = pluginApi;
2701
+ this.colors = colorApi;
2702
+ this.themes = themeApi;
2703
+ }
2704
+ }
2705
+ const AppModule = {
2706
+ api: awilix.asClass(API).singleton()
2707
+ };
2708
+ function defineConfig(configObject) {
2709
+ if (!configObject || typeof configObject !== "object") {
2710
+ throw new Error("The configuration is missing or not an object");
2711
+ }
2712
+ if (!("sourceColor" in configObject)) {
2713
+ throw new Error("Invalid configuration");
2714
+ }
2715
+ return configObject;
2716
+ }
2717
+ class ConfigService {
2718
+ constructor({ api }) {
2719
+ this.configPath = "./theme.config";
2720
+ this.api = api;
2721
+ }
2722
+ async loadConfig(config) {
2723
+ const {
2724
+ sourceColor,
2725
+ contrastLevel = 0,
2726
+ isDark = false,
2727
+ variant = tonalSpotVariant,
2728
+ palettes,
2729
+ colors,
2730
+ useDefaultColors = true,
2731
+ plugins
2732
+ } = config ?? await this.getConfig();
2733
+ this.api.themes.create({
2734
+ contrastLevel,
2735
+ isDark,
2736
+ sourceColorHex: sourceColor,
2737
+ variant
2738
+ });
2739
+ if (palettes) {
2740
+ Object.entries(palettes).forEach(
2741
+ ([key, value]) => this.api.themes.addCustomPalette(key, value)
2742
+ );
2743
+ }
2744
+ if (useDefaultColors) {
2745
+ this.api.colors.addColors(defaultColors);
2746
+ }
2747
+ if (colors) {
2748
+ this.api.colors.addColors(colors);
2749
+ }
2750
+ if (plugins) {
2751
+ plugins.forEach((plugin) => {
2752
+ this.api.plugins.addPlugin(plugin);
2753
+ });
2754
+ this.api.plugins.loadPlugins(this.api);
2755
+ }
2756
+ }
2757
+ async getConfig() {
2758
+ if (typeof process !== "undefined" && process.release && process.release.name === "node") {
2759
+ const path = (await import("path")).default;
2760
+ const fs = (await import("fs")).default;
2761
+ const base = path.resolve(this.configPath);
2762
+ const extensions = [".js", ".ts", ".jms", ".jcs"];
2763
+ let configImport = null;
2764
+ for (const ext of extensions) {
2765
+ const path2 = base + ext;
2766
+ if (fs.existsSync(path2)) {
2767
+ configImport = require(path2);
2768
+ break;
2769
+ }
2770
+ }
2771
+ if (!configImport) {
2772
+ throw new Error(
2773
+ `Configuration file not found, looked for: ${base} with extensions: ${extensions.join(", ")}`
2774
+ );
2775
+ }
2776
+ let config;
2777
+ if ("default" in configImport) {
2778
+ config = configImport.default;
2779
+ } else {
2780
+ config = configImport;
2781
+ }
2782
+ return config;
2783
+ } else {
2784
+ throw new Error(
2785
+ "You must provide configuration object when using this library in a browser."
2786
+ );
2787
+ }
2788
+ }
2789
+ }
2790
+ const ConfigModule = {
2791
+ configService: awilix.asClass(ConfigService).singleton()
2792
+ };
2793
+ class PluginAbstract {
2794
+ constructor(options) {
2795
+ this.options = options;
2796
+ }
2797
+ init(api) {
2798
+ this.pluginInstance = new this.pluginClass(api, this.options);
2799
+ this.pluginInstance.onInit();
2800
+ return this;
2801
+ }
2802
+ getInstance() {
2803
+ if (!this.pluginInstance) {
2804
+ throw new Error(`Plugin ${this.name} is not initialized`);
2805
+ }
2806
+ return this.pluginInstance;
2807
+ }
2808
+ }
2809
+ class PluginImplAbstract {
2810
+ constructor(api, options) {
2811
+ this.api = api;
2812
+ this.options = options;
2813
+ this.onInit();
2814
+ }
2815
+ }
2816
+ class PluginApi {
2817
+ constructor() {
2818
+ this.plugins = /* @__PURE__ */ new Map();
2819
+ }
2820
+ addPlugin(plugin) {
2821
+ this.plugins.set(plugin.name, plugin);
2822
+ }
2823
+ loadPlugins(api) {
2824
+ const plugins = new Map(this.plugins);
2825
+ let size = 0;
2826
+ do {
2827
+ size = plugins.size;
2828
+ plugins.forEach((plugin, key) => {
2829
+ const deps = plugin.dependencies.filter(
2830
+ (dep) => !this.plugins.has(new dep().name)
2831
+ );
2832
+ if (deps.length === 0) {
2833
+ this.plugins.set(plugin.name, plugin.init(api));
2834
+ plugins.delete(key);
2835
+ }
2836
+ });
2837
+ } while (plugins.size != 0 && plugins.size < size);
2838
+ if (plugins.size > 0)
2839
+ throw new Error(
2840
+ "Some plugins couldn't be loaded due to missing dependencies: " + Array.from(plugins.keys())
2841
+ );
2842
+ }
2843
+ getPlugin(plugin) {
2844
+ const pluginInstance = this.plugins.get(new plugin().name);
2845
+ if (!pluginInstance) throw new Error(`Plugin ${plugin.name} not found`);
2846
+ return pluginInstance;
2847
+ }
2848
+ }
2849
+ const PluginModule = {
2850
+ pluginApi: awilix.asClass(PluginApi).singleton()
2851
+ };
2852
+ function importContainer(container, services) {
2853
+ services.forEach((service) => {
2854
+ Object.entries(service).forEach(([name, serviceClass]) => {
2855
+ container.register(name, serviceClass);
2856
+ });
2857
+ });
2858
+ return container;
2859
+ }
2860
+ const AppContainer = awilix.createContainer({
2861
+ injectionMode: awilix.InjectionMode.PROXY
2862
+ });
2863
+ importContainer(AppContainer, [
2864
+ ConfigModule,
2865
+ AppModule,
2866
+ PluginModule,
2867
+ ColorModule,
2868
+ ThemeModule
2869
+ ]);
2870
+ function bootstrap() {
2871
+ return AppContainer.resolve("api");
2872
+ }
2873
+ async function bootstrapFromConfig(args) {
2874
+ const configService = AppContainer.resolve("configService");
2875
+ if (args == null ? void 0 : args.path) configService.configPath = args.path;
2876
+ await configService.loadConfig(args == null ? void 0 : args.config);
2877
+ return AppContainer.resolve("api");
2878
+ }
2879
+ var FontFamily = /* @__PURE__ */ ((FontFamily2) => {
2880
+ FontFamily2["Expressive"] = "expressive";
2881
+ FontFamily2["Neutral"] = "neutral";
2882
+ return FontFamily2;
2883
+ })(FontFamily || {});
2884
+ class FontPlugin extends PluginAbstract {
2885
+ constructor() {
2886
+ super(...arguments);
2887
+ this.dependencies = [];
2888
+ this.name = "font";
2889
+ this.pluginClass = FontPluginImpl;
2890
+ }
2891
+ }
2892
+ class FontPluginImpl extends PluginImplAbstract {
2893
+ get fontFamily() {
2894
+ if (!this._fontFamily) throw new Error("Font family not initialized");
2895
+ return this._fontFamily;
2896
+ }
2897
+ set fontFamily(value) {
2898
+ this._fontFamily = value;
2899
+ }
2900
+ get fontStyles() {
2901
+ if (!this._fontStyles) throw new Error("Font styles not initialized");
2902
+ return this._fontStyles;
2903
+ }
2904
+ set fontStyles(value) {
2905
+ this._fontStyles = value;
2906
+ }
2907
+ getFonts() {
2908
+ return {
2909
+ fontStyles: this.fontStyles,
2910
+ fontFamily: this.fontFamily
2911
+ };
2912
+ }
2913
+ onInit() {
2914
+ var _a, _b, _c, _d;
2915
+ this.fontFamily = {
2916
+ expressive: ((_b = (_a = this.options) == null ? void 0 : _a.fontFamily) == null ? void 0 : _b.expressive) ?? [
2917
+ "Roboto",
2918
+ "sans-serif"
2919
+ ],
2920
+ neutral: ((_d = (_c = this.options) == null ? void 0 : _c.fontFamily) == null ? void 0 : _d.neutral) ?? ["Roboto", "sans-serif"]
2921
+ };
2922
+ this.fontStyles = {
2923
+ display: {
2924
+ large: {
2925
+ fontWeight: 400,
2926
+ fontSize: 3.5625,
2927
+ lineHeight: 4,
2928
+ letterSpacing: -0.015625,
2929
+ fontFamily: "expressive"
2930
+ /* Expressive */
2931
+ },
2932
+ medium: {
2933
+ fontWeight: 400,
2934
+ fontSize: 2.8125,
2935
+ lineHeight: 3.25,
2936
+ fontFamily: "expressive"
2937
+ /* Expressive */
2938
+ },
2939
+ small: {
2940
+ fontWeight: 400,
2941
+ fontSize: 2.25,
2942
+ lineHeight: 2.75,
2943
+ fontFamily: "expressive"
2944
+ /* Expressive */
2945
+ }
2946
+ },
2947
+ headline: {
2948
+ large: {
2949
+ fontWeight: 400,
2950
+ fontSize: 2,
2951
+ lineHeight: 2.5,
2952
+ fontFamily: "expressive"
2953
+ /* Expressive */
2954
+ },
2955
+ medium: {
2956
+ fontWeight: 400,
2957
+ fontSize: 1.75,
2958
+ lineHeight: 2.25,
2959
+ fontFamily: "expressive"
2960
+ /* Expressive */
2961
+ },
2962
+ small: {
2963
+ fontWeight: 400,
2964
+ fontSize: 1.5,
2965
+ lineHeight: 2,
2966
+ fontFamily: "expressive"
2967
+ /* Expressive */
2968
+ }
2969
+ },
2970
+ title: {
2971
+ large: {
2972
+ fontWeight: 400,
2973
+ fontSize: 1.375,
2974
+ lineHeight: 1.75,
2975
+ fontFamily: "neutral"
2976
+ /* Neutral */
2977
+ },
2978
+ medium: {
2979
+ fontWeight: 500,
2980
+ fontSize: 1,
2981
+ lineHeight: 1.5,
2982
+ fontFamily: "neutral",
2983
+ letterSpacing: 9375e-6
2984
+ },
2985
+ small: {
2986
+ fontWeight: 500,
2987
+ fontSize: 0.875,
2988
+ lineHeight: 1.25,
2989
+ fontFamily: "neutral",
2990
+ letterSpacing: 625e-5
2991
+ }
2992
+ },
2993
+ label: {
2994
+ large: {
2995
+ fontWeight: 500,
2996
+ fontSize: 0.875,
2997
+ lineHeight: 1.25,
2998
+ fontFamily: "neutral",
2999
+ letterSpacing: 625e-5
3000
+ },
3001
+ medium: {
3002
+ fontWeight: 500,
3003
+ fontSize: 0.75,
3004
+ lineHeight: 1,
3005
+ fontFamily: "neutral",
3006
+ letterSpacing: 0.03125
3007
+ },
3008
+ small: {
3009
+ fontWeight: 500,
3010
+ fontSize: 0.6875,
3011
+ lineHeight: 1,
3012
+ fontFamily: "neutral",
3013
+ letterSpacing: 0.03125
3014
+ }
3015
+ },
3016
+ body: {
3017
+ large: {
3018
+ fontWeight: 400,
3019
+ fontSize: 1,
3020
+ lineHeight: 1.5625,
3021
+ fontFamily: "neutral",
3022
+ letterSpacing: 0.03125
3023
+ },
3024
+ medium: {
3025
+ fontWeight: 400,
3026
+ fontSize: 0.875,
3027
+ lineHeight: 1.25,
3028
+ fontFamily: "neutral",
3029
+ letterSpacing: 0.015625
3030
+ },
3031
+ small: {
3032
+ fontWeight: 400,
3033
+ fontSize: 0.75,
3034
+ lineHeight: 1,
3035
+ fontFamily: "neutral",
3036
+ letterSpacing: 0.025
3037
+ }
3038
+ }
3039
+ };
3040
+ if (this.options && this.options.fontStyles)
3041
+ Object.entries(this.options.fontStyles).forEach(([key, fontParam]) => {
3042
+ const fontRole = key;
3043
+ Object.entries(fontParam).forEach(([size, fontStyle]) => {
3044
+ const fontSize = size;
3045
+ if (fontStyle) {
3046
+ this.fontStyles[fontRole][fontSize] = {
3047
+ ...this.fontStyles[fontRole][fontSize],
3048
+ ...fontStyle
3049
+ };
3050
+ }
3051
+ });
3052
+ });
3053
+ }
3054
+ }
3055
+ exports.API = API;
3056
+ exports.AppContainer = AppContainer;
3057
+ exports.AppModule = AppModule;
3058
+ exports.ColorApi = ColorApi;
3059
+ exports.ColorManager = ColorManager;
3060
+ exports.ColorModule = ColorModule;
3061
+ exports.ConfigModule = ConfigModule;
3062
+ exports.ConfigService = ConfigService;
3063
+ exports.ConfigurableColor = ConfigurableColor;
3064
+ exports.ContrastCurve = ContrastCurve;
3065
+ exports.DynamicColor = DynamicColor;
3066
+ exports.FontFamily = FontFamily;
3067
+ exports.FontPlugin = FontPlugin;
3068
+ exports.PluginAbstract = PluginAbstract;
3069
+ exports.PluginApi = PluginApi;
3070
+ exports.PluginImplAbstract = PluginImplAbstract;
3071
+ exports.PluginModule = PluginModule;
3072
+ exports.Scheme = Scheme;
3073
+ exports.SchemeManager = SchemeManager;
3074
+ exports.ThemeApi = ThemeApi;
3075
+ exports.ThemeModule = ThemeModule;
3076
+ exports.ToneDeltaPair = ToneDeltaPair;
3077
+ exports.Variant = Variant;
3078
+ exports.VariantManager = VariantManager;
3079
+ exports.Variants = Variants;
3080
+ exports.bootstrap = bootstrap;
3081
+ exports.bootstrapFromConfig = bootstrapFromConfig;
3082
+ exports.defaultColors = defaultColors;
3083
+ exports.defineConfig = defineConfig;
3084
+ exports.expressiveVariant = expressiveVariant;
3085
+ exports.extendSpecVersion = extendSpecVersion;
3086
+ exports.getPiecewiseHue = getPiecewiseHue;
3087
+ exports.getRotatedHue = getRotatedHue;
3088
+ exports.highestSurface = highestSurface;
3089
+ exports.importContainer = importContainer;
3090
+ exports.neutralVariant = neutralVariant;
3091
+ exports.tonalSpotVariant = tonalSpotVariant;
3092
+ exports.vibrantVariant = vibrantVariant;