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