@udixio/theme 0.4.2 → 0.5.1

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