@udixio/theme 0.4.1 → 0.5.0

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