@udixio/theme 1.3.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/CHANGELOG.md +23 -2
  2. package/dist/API.d.ts +7 -4
  3. package/dist/API.d.ts.map +1 -1
  4. package/dist/app.container.d.ts +1 -2
  5. package/dist/app.container.d.ts.map +1 -1
  6. package/dist/bin.cjs +1 -1
  7. package/dist/bin.js +1 -1
  8. package/dist/browser.cjs +23 -18
  9. package/dist/browser.js +34 -29
  10. package/dist/color/color.api.d.ts +16 -31
  11. package/dist/color/color.api.d.ts.map +1 -1
  12. package/dist/color/color.d.ts +100 -0
  13. package/dist/color/color.d.ts.map +1 -0
  14. package/dist/color/color.manager.d.ts +9 -18
  15. package/dist/color/color.manager.d.ts.map +1 -1
  16. package/dist/color/color.utils.d.ts +14 -3
  17. package/dist/color/color.utils.d.ts.map +1 -1
  18. package/dist/color/default-color.d.ts +5 -1
  19. package/dist/color/default-color.d.ts.map +1 -1
  20. package/dist/color/index.d.ts +1 -1
  21. package/dist/color/index.d.ts.map +1 -1
  22. package/dist/config/config.interface.d.ts +4 -4
  23. package/dist/config/config.interface.d.ts.map +1 -1
  24. package/dist/context/context.d.ts +41 -0
  25. package/dist/context/context.d.ts.map +1 -0
  26. package/dist/context/context.module.d.ts +3 -0
  27. package/dist/context/context.module.d.ts.map +1 -0
  28. package/dist/context/index.d.ts +3 -0
  29. package/dist/context/index.d.ts.map +1 -0
  30. package/dist/font.plugin-5Xpo-ntw.js +228 -0
  31. package/dist/font.plugin-FPU_gL1Y.cjs +227 -0
  32. package/dist/index.d.ts +6 -4
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/{load-from-path-Bo1kCfh9.js → load-from-path-CBnO8ESw.js} +1 -1
  35. package/dist/{load-from-path-DoZnR1-p.cjs → load-from-path-kuofMGN3.cjs} +2 -2
  36. package/dist/loader/loader.d.ts +1 -1
  37. package/dist/loader/loader.d.ts.map +1 -1
  38. package/dist/loader-BzsrGBu-.cjs +3905 -0
  39. package/dist/loader-CoayTlSl.js +3906 -0
  40. package/dist/material-color-utilities/dynamic_color.d.ts +0 -22
  41. package/dist/material-color-utilities/dynamic_color.d.ts.map +1 -1
  42. package/dist/material-color-utilities/toneDeltaPair.d.ts +8 -8
  43. package/dist/material-color-utilities/toneDeltaPair.d.ts.map +1 -1
  44. package/dist/node.cjs +24 -19
  45. package/dist/node.js +36 -31
  46. package/dist/palette/index.d.ts +4 -0
  47. package/dist/palette/index.d.ts.map +1 -0
  48. package/dist/palette/palette.api.d.ts +13 -0
  49. package/dist/palette/palette.api.d.ts.map +1 -0
  50. package/dist/palette/palette.d.ts +33 -0
  51. package/dist/palette/palette.d.ts.map +1 -0
  52. package/dist/palette/palette.manager.d.ts +20 -0
  53. package/dist/palette/palette.manager.d.ts.map +1 -0
  54. package/dist/palette/palette.module.d.ts +3 -0
  55. package/dist/palette/palette.module.d.ts.map +1 -0
  56. package/dist/plugins/font/font.plugin.d.ts +1 -1
  57. package/dist/plugins/font/font.plugin.d.ts.map +1 -1
  58. package/dist/variant/index.d.ts +3 -0
  59. package/dist/variant/index.d.ts.map +1 -0
  60. package/dist/variant/variant.d.ts +31 -0
  61. package/dist/variant/variant.d.ts.map +1 -0
  62. package/dist/variant/variants/expressive.variant.d.ts +2 -0
  63. package/dist/variant/variants/expressive.variant.d.ts.map +1 -0
  64. package/dist/{theme → variant}/variants/index.d.ts +1 -1
  65. package/dist/variant/variants/index.d.ts.map +1 -0
  66. package/dist/variant/variants/neutral.variant.d.ts.map +1 -0
  67. package/dist/variant/variants/tonal-spot.variant.d.ts.map +1 -0
  68. package/dist/variant/variants/udixio.variant.d.ts +3 -0
  69. package/dist/variant/variants/udixio.variant.d.ts.map +1 -0
  70. package/dist/variant/variants/vibrant.variant.d.ts.map +1 -0
  71. package/package.json +1 -1
  72. package/src/API.ts +12 -5
  73. package/src/app.container.ts +22 -11
  74. package/src/bootstrap.ts +1 -1
  75. package/src/color/color.api.ts +189 -47
  76. package/src/color/color.manager.ts +34 -189
  77. package/src/color/color.ts +295 -0
  78. package/src/color/color.utils.ts +48 -3
  79. package/src/color/default-color.ts +390 -425
  80. package/src/color/index.ts +1 -1
  81. package/src/config/config.interface.ts +5 -4
  82. package/src/context/context.module.ts +7 -0
  83. package/src/context/context.ts +169 -0
  84. package/src/context/index.ts +2 -0
  85. package/src/index.ts +6 -4
  86. package/src/loader/loader.ts +11 -24
  87. package/src/material-color-utilities/dynamic_color.ts +25 -34
  88. package/src/material-color-utilities/toneDeltaPair.ts +44 -41
  89. package/src/palette/index.ts +3 -0
  90. package/src/palette/palette.api.ts +43 -0
  91. package/src/palette/palette.manager.ts +74 -0
  92. package/src/palette/palette.module.ts +9 -0
  93. package/src/palette/palette.ts +206 -0
  94. package/src/plugins/font/font.plugin.ts +1 -1
  95. package/src/variant/index.ts +2 -0
  96. package/src/variant/variant.ts +84 -0
  97. package/src/{theme → variant}/variants/expressive.variant.ts +33 -29
  98. package/src/{theme → variant}/variants/index.ts +2 -2
  99. package/src/variant/variants/neutral.variant.ts +47 -0
  100. package/src/variant/variants/tonal-spot.variant.ts +37 -0
  101. package/src/variant/variants/udixio.variant.ts +846 -0
  102. package/src/{theme → variant}/variants/vibrant.variant.ts +23 -22
  103. package/dist/color/configurable-color.d.ts +0 -31
  104. package/dist/color/configurable-color.d.ts.map +0 -1
  105. package/dist/define-config-BasMdCqD.js +0 -430
  106. package/dist/define-config-CKSsLMnc.cjs +0 -429
  107. package/dist/loader-C8_TyOuS.js +0 -2698
  108. package/dist/loader-R7hccp8_.cjs +0 -2697
  109. package/dist/theme/index.d.ts +0 -8
  110. package/dist/theme/index.d.ts.map +0 -1
  111. package/dist/theme/scheme.d.ts +0 -20
  112. package/dist/theme/scheme.d.ts.map +0 -1
  113. package/dist/theme/scheme.manager.d.ts +0 -31
  114. package/dist/theme/scheme.manager.d.ts.map +0 -1
  115. package/dist/theme/theme.api.d.ts +0 -24
  116. package/dist/theme/theme.api.d.ts.map +0 -1
  117. package/dist/theme/theme.module.d.ts +0 -3
  118. package/dist/theme/theme.module.d.ts.map +0 -1
  119. package/dist/theme/variant.d.ts +0 -36
  120. package/dist/theme/variant.d.ts.map +0 -1
  121. package/dist/theme/variant.manager.d.ts +0 -14
  122. package/dist/theme/variant.manager.d.ts.map +0 -1
  123. package/dist/theme/variants/expressive.variant.d.ts +0 -3
  124. package/dist/theme/variants/expressive.variant.d.ts.map +0 -1
  125. package/dist/theme/variants/fidelity.variant.d.ts +0 -3
  126. package/dist/theme/variants/fidelity.variant.d.ts.map +0 -1
  127. package/dist/theme/variants/index.d.ts.map +0 -1
  128. package/dist/theme/variants/neutral.variant.d.ts.map +0 -1
  129. package/dist/theme/variants/tonal-spot.variant.d.ts.map +0 -1
  130. package/dist/theme/variants/vibrant.variant.d.ts.map +0 -1
  131. package/src/color/configurable-color.ts +0 -67
  132. package/src/theme/index.ts +0 -7
  133. package/src/theme/scheme.manager.ts +0 -100
  134. package/src/theme/scheme.ts +0 -66
  135. package/src/theme/theme.api.ts +0 -82
  136. package/src/theme/theme.module.ts +0 -11
  137. package/src/theme/variant.manager.ts +0 -58
  138. package/src/theme/variant.ts +0 -53
  139. package/src/theme/variants/fidelity.variant.ts +0 -38
  140. package/src/theme/variants/neutral.variant.ts +0 -45
  141. package/src/theme/variants/tonal-spot.variant.ts +0 -35
  142. /package/dist/{theme → variant}/variants/neutral.variant.d.ts +0 -0
  143. /package/dist/{theme → variant}/variants/tonal-spot.variant.d.ts +0 -0
  144. /package/dist/{theme → variant}/variants/vibrant.variant.d.ts +0 -0
@@ -0,0 +1,3906 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ import { asClass, createContainer, InjectionMode } from "awilix";
5
+ import { argbFromLstar, sanitizeDegreesDouble, yFromLstar, argbFromLinrgb, Cam16, signum, matrixMultiply, ViewingConditions, lstarFromArgb, lstarFromY, lerp, clampDouble, Contrast, DynamicColor as DynamicColor$1, argbFromHex, hexFromArgb, TonalPalette } from "@material/material-color-utilities";
6
+ class API {
7
+ constructor({
8
+ colorApi,
9
+ pluginApi,
10
+ context,
11
+ paletteApi
12
+ }) {
13
+ __publicField(this, "colors");
14
+ __publicField(this, "plugins");
15
+ __publicField(this, "context");
16
+ __publicField(this, "palettes");
17
+ colorApi.api = this;
18
+ this.context = context;
19
+ this.plugins = pluginApi;
20
+ this.colors = colorApi;
21
+ this.palettes = paletteApi;
22
+ }
23
+ async load() {
24
+ return this.plugins.loadPlugins();
25
+ }
26
+ }
27
+ /**
28
+ * @license
29
+ * Copyright 2021 Google LLC
30
+ *
31
+ * Licensed under the Apache License, Version 2.0 (the "License");
32
+ * you may not use this file except in compliance with the License.
33
+ * You may obtain a copy of the License at
34
+ *
35
+ * http://www.apache.org/licenses/LICENSE-2.0
36
+ *
37
+ * Unless required by applicable law or agreed to in writing, software
38
+ * distributed under the License is distributed on an "AS IS" BASIS,
39
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
40
+ * See the License for the specific language governing permissions and
41
+ * limitations under the License.
42
+ */
43
+ const _HctSolver = class _HctSolver {
44
+ /**
45
+ * Finds an sRGB color with the given hue, chroma, and L*, if
46
+ * possible.
47
+ *
48
+ * @param hueDegrees The desired hue, in degrees.
49
+ * @param chroma The desired chroma.
50
+ * @param lstar The desired L*.
51
+ * @return A hexadecimal representing the sRGB color. The color
52
+ * has sufficiently close hue, chroma, and L* to the desired
53
+ * values, if possible; otherwise, the hue and L* will be
54
+ * sufficiently close, and chroma will be maximized.
55
+ */
56
+ static solveToInt(hueDegrees, chroma, lstar) {
57
+ if (chroma < 1e-4 || lstar < 1e-4 || lstar > 99.9999) {
58
+ return argbFromLstar(lstar);
59
+ }
60
+ hueDegrees = sanitizeDegreesDouble(hueDegrees);
61
+ const hueRadians = hueDegrees / 180 * Math.PI;
62
+ const y = yFromLstar(lstar);
63
+ const exactAnswer = _HctSolver.findResultByJ(hueRadians, chroma, y);
64
+ if (exactAnswer !== 0) {
65
+ return exactAnswer;
66
+ }
67
+ const linrgb = _HctSolver.bisectToLimit(y, hueRadians);
68
+ return argbFromLinrgb(linrgb);
69
+ }
70
+ /**
71
+ * Finds an sRGB color with the given hue, chroma, and L*, if
72
+ * possible.
73
+ *
74
+ * @param hueDegrees The desired hue, in degrees.
75
+ * @param chroma The desired chroma.
76
+ * @param lstar The desired L*.
77
+ * @return An CAM16 object representing the sRGB color. The color
78
+ * has sufficiently close hue, chroma, and L* to the desired
79
+ * values, if possible; otherwise, the hue and L* will be
80
+ * sufficiently close, and chroma will be maximized.
81
+ */
82
+ static solveToCam(hueDegrees, chroma, lstar) {
83
+ return Cam16.fromInt(_HctSolver.solveToInt(hueDegrees, chroma, lstar));
84
+ }
85
+ /**
86
+ * Sanitizes a small enough angle in radians.
87
+ *
88
+ * @param angle An angle in radians; must not deviate too much
89
+ * from 0.
90
+ * @return A coterminal angle between 0 and 2pi.
91
+ */
92
+ static sanitizeRadians(angle) {
93
+ return (angle + Math.PI * 8) % (Math.PI * 2);
94
+ }
95
+ /**
96
+ * Delinearizes an RGB component, returning a floating-point
97
+ * number.
98
+ *
99
+ * @param rgbComponent 0.0 <= rgb_component <= 100.0, represents
100
+ * linear R/G/B channel
101
+ * @return 0.0 <= output <= 255.0, color channel converted to
102
+ * regular RGB space
103
+ */
104
+ static trueDelinearized(rgbComponent) {
105
+ const normalized = rgbComponent / 100;
106
+ let delinearized = 0;
107
+ if (normalized <= 31308e-7) {
108
+ delinearized = normalized * 12.92;
109
+ } else {
110
+ delinearized = 1.055 * Math.pow(normalized, 1 / 2.4) - 0.055;
111
+ }
112
+ return delinearized * 255;
113
+ }
114
+ static chromaticAdaptation(component) {
115
+ const af = Math.pow(Math.abs(component), 0.42);
116
+ return signum(component) * 400 * af / (af + 27.13);
117
+ }
118
+ /**
119
+ * Returns the hue of a linear RGB color in CAM16.
120
+ *
121
+ * @param linrgb The linear RGB coordinates of a color.
122
+ * @return The hue of the color in CAM16, in radians.
123
+ */
124
+ static hueOf(linrgb) {
125
+ const scaledDiscount = matrixMultiply(
126
+ linrgb,
127
+ _HctSolver.SCALED_DISCOUNT_FROM_LINRGB
128
+ );
129
+ const rA = _HctSolver.chromaticAdaptation(scaledDiscount[0]);
130
+ const gA = _HctSolver.chromaticAdaptation(scaledDiscount[1]);
131
+ const bA = _HctSolver.chromaticAdaptation(scaledDiscount[2]);
132
+ const a = (11 * rA + -12 * gA + bA) / 11;
133
+ const b = (rA + gA - 2 * bA) / 9;
134
+ return Math.atan2(b, a);
135
+ }
136
+ static areInCyclicOrder(a, b, c) {
137
+ const deltaAB = _HctSolver.sanitizeRadians(b - a);
138
+ const deltaAC = _HctSolver.sanitizeRadians(c - a);
139
+ return deltaAB < deltaAC;
140
+ }
141
+ /**
142
+ * Solves the lerp equation.
143
+ *
144
+ * @param source The starting number.
145
+ * @param mid The number in the middle.
146
+ * @param target The ending number.
147
+ * @return A number t such that lerp(source, target, t) = mid.
148
+ */
149
+ static intercept(source, mid, target) {
150
+ return (mid - source) / (target - source);
151
+ }
152
+ static lerpPoint(source, t, target) {
153
+ return [
154
+ source[0] + (target[0] - source[0]) * t,
155
+ source[1] + (target[1] - source[1]) * t,
156
+ source[2] + (target[2] - source[2]) * t
157
+ ];
158
+ }
159
+ /**
160
+ * Intersects a segment with a plane.
161
+ *
162
+ * @param source The coordinates of point A.
163
+ * @param coordinate The R-, G-, or B-coordinate of the plane.
164
+ * @param target The coordinates of point B.
165
+ * @param axis The axis the plane is perpendicular with. (0: R, 1:
166
+ * G, 2: B)
167
+ * @return The intersection point of the segment AB with the plane
168
+ * R=coordinate, G=coordinate, or B=coordinate
169
+ */
170
+ static setCoordinate(source, coordinate, target, axis) {
171
+ const t = _HctSolver.intercept(source[axis], coordinate, target[axis]);
172
+ return _HctSolver.lerpPoint(source, t, target);
173
+ }
174
+ static isBounded(x) {
175
+ return 0 <= x && x <= 100;
176
+ }
177
+ /**
178
+ * Returns the nth possible vertex of the polygonal intersection.
179
+ *
180
+ * @param y The Y value of the plane.
181
+ * @param n The zero-based index of the point. 0 <= n <= 11.
182
+ * @return The nth possible vertex of the polygonal intersection
183
+ * of the y plane and the RGB cube, in linear RGB coordinates, if
184
+ * it exists. If this possible vertex lies outside of the cube,
185
+ * [-1.0, -1.0, -1.0] is returned.
186
+ */
187
+ static nthVertex(y, n) {
188
+ const kR = _HctSolver.Y_FROM_LINRGB[0];
189
+ const kG = _HctSolver.Y_FROM_LINRGB[1];
190
+ const kB = _HctSolver.Y_FROM_LINRGB[2];
191
+ const coordA = n % 4 <= 1 ? 0 : 100;
192
+ const coordB = n % 2 === 0 ? 0 : 100;
193
+ if (n < 4) {
194
+ const g = coordA;
195
+ const b = coordB;
196
+ const r = (y - g * kG - b * kB) / kR;
197
+ if (_HctSolver.isBounded(r)) {
198
+ return [r, g, b];
199
+ } else {
200
+ return [-1, -1, -1];
201
+ }
202
+ } else if (n < 8) {
203
+ const b = coordA;
204
+ const r = coordB;
205
+ const g = (y - r * kR - b * kB) / kG;
206
+ if (_HctSolver.isBounded(g)) {
207
+ return [r, g, b];
208
+ } else {
209
+ return [-1, -1, -1];
210
+ }
211
+ } else {
212
+ const r = coordA;
213
+ const g = coordB;
214
+ const b = (y - r * kR - g * kG) / kB;
215
+ if (_HctSolver.isBounded(b)) {
216
+ return [r, g, b];
217
+ } else {
218
+ return [-1, -1, -1];
219
+ }
220
+ }
221
+ }
222
+ /**
223
+ * Finds the segment containing the desired color.
224
+ *
225
+ * @param y The Y value of the color.
226
+ * @param targetHue The hue of the color.
227
+ * @return A list of two sets of linear RGB coordinates, each
228
+ * corresponding to an endpoint of the segment containing the
229
+ * desired color.
230
+ */
231
+ static bisectToSegment(y, targetHue) {
232
+ let left = [-1, -1, -1];
233
+ let right = left;
234
+ let leftHue = 0;
235
+ let rightHue = 0;
236
+ let initialized = false;
237
+ let uncut = true;
238
+ for (let n = 0; n < 12; n++) {
239
+ const mid = _HctSolver.nthVertex(y, n);
240
+ if (mid[0] < 0) {
241
+ continue;
242
+ }
243
+ const midHue = _HctSolver.hueOf(mid);
244
+ if (!initialized) {
245
+ left = mid;
246
+ right = mid;
247
+ leftHue = midHue;
248
+ rightHue = midHue;
249
+ initialized = true;
250
+ continue;
251
+ }
252
+ if (uncut || _HctSolver.areInCyclicOrder(leftHue, midHue, rightHue)) {
253
+ uncut = false;
254
+ if (_HctSolver.areInCyclicOrder(leftHue, targetHue, midHue)) {
255
+ right = mid;
256
+ rightHue = midHue;
257
+ } else {
258
+ left = mid;
259
+ leftHue = midHue;
260
+ }
261
+ }
262
+ }
263
+ return [left, right];
264
+ }
265
+ static midpoint(a, b) {
266
+ return [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2, (a[2] + b[2]) / 2];
267
+ }
268
+ static criticalPlaneBelow(x) {
269
+ return Math.floor(x - 0.5);
270
+ }
271
+ static criticalPlaneAbove(x) {
272
+ return Math.ceil(x - 0.5);
273
+ }
274
+ /**
275
+ * Finds a color with the given Y and hue on the boundary of the
276
+ * cube.
277
+ *
278
+ * @param y The Y value of the color.
279
+ * @param targetHue The hue of the color.
280
+ * @return The desired color, in linear RGB coordinates.
281
+ */
282
+ static bisectToLimit(y, targetHue) {
283
+ const segment = _HctSolver.bisectToSegment(y, targetHue);
284
+ let left = segment[0];
285
+ let leftHue = _HctSolver.hueOf(left);
286
+ let right = segment[1];
287
+ for (let axis = 0; axis < 3; axis++) {
288
+ if (left[axis] !== right[axis]) {
289
+ let lPlane = -1;
290
+ let rPlane = 255;
291
+ if (left[axis] < right[axis]) {
292
+ lPlane = _HctSolver.criticalPlaneBelow(
293
+ _HctSolver.trueDelinearized(left[axis])
294
+ );
295
+ rPlane = _HctSolver.criticalPlaneAbove(
296
+ _HctSolver.trueDelinearized(right[axis])
297
+ );
298
+ } else {
299
+ lPlane = _HctSolver.criticalPlaneAbove(
300
+ _HctSolver.trueDelinearized(left[axis])
301
+ );
302
+ rPlane = _HctSolver.criticalPlaneBelow(
303
+ _HctSolver.trueDelinearized(right[axis])
304
+ );
305
+ }
306
+ for (let i = 0; i < 8; i++) {
307
+ if (Math.abs(rPlane - lPlane) <= 1) {
308
+ break;
309
+ } else {
310
+ const mPlane = Math.floor((lPlane + rPlane) / 2);
311
+ const midPlaneCoordinate = _HctSolver.CRITICAL_PLANES[mPlane];
312
+ const mid = _HctSolver.setCoordinate(
313
+ left,
314
+ midPlaneCoordinate,
315
+ right,
316
+ axis
317
+ );
318
+ const midHue = _HctSolver.hueOf(mid);
319
+ if (_HctSolver.areInCyclicOrder(leftHue, targetHue, midHue)) {
320
+ right = mid;
321
+ rPlane = mPlane;
322
+ } else {
323
+ left = mid;
324
+ leftHue = midHue;
325
+ lPlane = mPlane;
326
+ }
327
+ }
328
+ }
329
+ }
330
+ }
331
+ return _HctSolver.midpoint(left, right);
332
+ }
333
+ static inverseChromaticAdaptation(adapted) {
334
+ const adaptedAbs = Math.abs(adapted);
335
+ const base = Math.max(0, 27.13 * adaptedAbs / (400 - adaptedAbs));
336
+ return signum(adapted) * Math.pow(base, 1 / 0.42);
337
+ }
338
+ /**
339
+ * Finds a color with the given hue, chroma, and Y.
340
+ *
341
+ * @param hueRadians The desired hue in radians.
342
+ * @param chroma The desired chroma.
343
+ * @param y The desired Y.
344
+ * @return The desired color as a hexadecimal integer, if found; 0
345
+ * otherwise.
346
+ */
347
+ static findResultByJ(hueRadians, chroma, y) {
348
+ let j = Math.sqrt(y) * 11;
349
+ const viewingConditions = ViewingConditions.DEFAULT;
350
+ const tInnerCoeff = 1 / Math.pow(1.64 - Math.pow(0.29, viewingConditions.n), 0.73);
351
+ const eHue = 0.25 * (Math.cos(hueRadians + 2) + 3.8);
352
+ const p1 = eHue * (5e4 / 13) * viewingConditions.nc * viewingConditions.ncb;
353
+ const hSin = Math.sin(hueRadians);
354
+ const hCos = Math.cos(hueRadians);
355
+ for (let iterationRound = 0; iterationRound < 5; iterationRound++) {
356
+ const jNormalized = j / 100;
357
+ const alpha = chroma === 0 || j === 0 ? 0 : chroma / Math.sqrt(jNormalized);
358
+ const t = Math.pow(alpha * tInnerCoeff, 1 / 0.9);
359
+ const ac = viewingConditions.aw * Math.pow(jNormalized, 1 / viewingConditions.c / viewingConditions.z);
360
+ const p2 = ac / viewingConditions.nbb;
361
+ const gamma = 23 * (p2 + 0.305) * t / (23 * p1 + 11 * t * hCos + 108 * t * hSin);
362
+ const a = gamma * hCos;
363
+ const b = gamma * hSin;
364
+ const rA = (460 * p2 + 451 * a + 288 * b) / 1403;
365
+ const gA = (460 * p2 - 891 * a - 261 * b) / 1403;
366
+ const bA = (460 * p2 - 220 * a - 6300 * b) / 1403;
367
+ const rCScaled = _HctSolver.inverseChromaticAdaptation(rA);
368
+ const gCScaled = _HctSolver.inverseChromaticAdaptation(gA);
369
+ const bCScaled = _HctSolver.inverseChromaticAdaptation(bA);
370
+ const linrgb = matrixMultiply(
371
+ [rCScaled, gCScaled, bCScaled],
372
+ _HctSolver.LINRGB_FROM_SCALED_DISCOUNT
373
+ );
374
+ if (linrgb[0] < 0 || linrgb[1] < 0 || linrgb[2] < 0) {
375
+ return 0;
376
+ }
377
+ const kR = _HctSolver.Y_FROM_LINRGB[0];
378
+ const kG = _HctSolver.Y_FROM_LINRGB[1];
379
+ const kB = _HctSolver.Y_FROM_LINRGB[2];
380
+ const fnj = kR * linrgb[0] + kG * linrgb[1] + kB * linrgb[2];
381
+ if (fnj <= 0) {
382
+ return 0;
383
+ }
384
+ if (iterationRound === 4 || Math.abs(fnj - y) < 2e-3) {
385
+ if (linrgb[0] > 100.01 || linrgb[1] > 100.01 || linrgb[2] > 100.01) {
386
+ return 0;
387
+ }
388
+ return argbFromLinrgb(linrgb);
389
+ }
390
+ j = j - (fnj - y) * j / (2 * fnj);
391
+ }
392
+ return 0;
393
+ }
394
+ };
395
+ __publicField(_HctSolver, "SCALED_DISCOUNT_FROM_LINRGB", [
396
+ [0.001200833568784504, 0.002389694492170889, 2795742885861124e-19],
397
+ [5891086651375999e-19, 0.0029785502573438758, 3270666104008398e-19],
398
+ [10146692491640572e-20, 5364214359186694e-19, 0.0032979401770712076]
399
+ ]);
400
+ __publicField(_HctSolver, "LINRGB_FROM_SCALED_DISCOUNT", [
401
+ [1373.2198709594231, -1100.4251190754821, -7.278681089101213],
402
+ [-271.815969077903, 559.6580465940733, -32.46047482791194],
403
+ [1.9622899599665666, -57.173814538844006, 308.7233197812385]
404
+ ]);
405
+ __publicField(_HctSolver, "Y_FROM_LINRGB", [0.2126, 0.7152, 0.0722]);
406
+ __publicField(_HctSolver, "CRITICAL_PLANES", [
407
+ 0.015176349177441876,
408
+ 0.045529047532325624,
409
+ 0.07588174588720938,
410
+ 0.10623444424209313,
411
+ 0.13658714259697685,
412
+ 0.16693984095186062,
413
+ 0.19729253930674434,
414
+ 0.2276452376616281,
415
+ 0.2579979360165119,
416
+ 0.28835063437139563,
417
+ 0.3188300904430532,
418
+ 0.350925934958123,
419
+ 0.3848314933096426,
420
+ 0.42057480301049466,
421
+ 0.458183274052838,
422
+ 0.4976837250274023,
423
+ 0.5391024159806381,
424
+ 0.5824650784040898,
425
+ 0.6277969426914107,
426
+ 0.6751227633498623,
427
+ 0.7244668422128921,
428
+ 0.775853049866786,
429
+ 0.829304845476233,
430
+ 0.8848452951698498,
431
+ 0.942497089126609,
432
+ 1.0022825574869039,
433
+ 1.0642236851973577,
434
+ 1.1283421258858297,
435
+ 1.1946592148522128,
436
+ 1.2631959812511864,
437
+ 1.3339731595349034,
438
+ 1.407011200216447,
439
+ 1.4823302800086415,
440
+ 1.5599503113873272,
441
+ 1.6398909516233677,
442
+ 1.7221716113234105,
443
+ 1.8068114625156377,
444
+ 1.8938294463134073,
445
+ 1.9832442801866852,
446
+ 2.075074464868551,
447
+ 2.1693382909216234,
448
+ 2.2660538449872063,
449
+ 2.36523901573795,
450
+ 2.4669114995532007,
451
+ 2.5710888059345764,
452
+ 2.6777882626779785,
453
+ 2.7870270208169257,
454
+ 2.898822059350997,
455
+ 3.0131901897720907,
456
+ 3.1301480604002863,
457
+ 3.2497121605402226,
458
+ 3.3718988244681087,
459
+ 3.4967242352587946,
460
+ 3.624204428461639,
461
+ 3.754355295633311,
462
+ 3.887192587735158,
463
+ 4.022731918402185,
464
+ 4.160988767090289,
465
+ 4.301978482107941,
466
+ 4.445716283538092,
467
+ 4.592217266055746,
468
+ 4.741496401646282,
469
+ 4.893568542229298,
470
+ 5.048448422192488,
471
+ 5.20615066083972,
472
+ 5.3666897647573375,
473
+ 5.5300801301023865,
474
+ 5.696336044816294,
475
+ 5.865471690767354,
476
+ 6.037501145825082,
477
+ 6.212438385869475,
478
+ 6.390297286737924,
479
+ 6.571091626112461,
480
+ 6.7548350853498045,
481
+ 6.941541251256611,
482
+ 7.131223617812143,
483
+ 7.323895587840543,
484
+ 7.5195704746346665,
485
+ 7.7182615035334345,
486
+ 7.919981813454504,
487
+ 8.124744458384042,
488
+ 8.332562408825165,
489
+ 8.543448553206703,
490
+ 8.757415699253682,
491
+ 8.974476575321063,
492
+ 9.194643831691977,
493
+ 9.417930041841839,
494
+ 9.644347703669503,
495
+ 9.873909240696694,
496
+ 10.106627003236781,
497
+ 10.342513269534024,
498
+ 10.58158024687427,
499
+ 10.8238400726681,
500
+ 11.069304815507364,
501
+ 11.317986476196008,
502
+ 11.569896988756009,
503
+ 11.825048221409341,
504
+ 12.083451977536606,
505
+ 12.345119996613247,
506
+ 12.610063955123938,
507
+ 12.878295467455942,
508
+ 13.149826086772048,
509
+ 13.42466730586372,
510
+ 13.702830557985108,
511
+ 13.984327217668513,
512
+ 14.269168601521828,
513
+ 14.55736596900856,
514
+ 14.848930523210871,
515
+ 15.143873411576273,
516
+ 15.44220572664832,
517
+ 15.743938506781891,
518
+ 16.04908273684337,
519
+ 16.35764934889634,
520
+ 16.66964922287304,
521
+ 16.985093187232053,
522
+ 17.30399201960269,
523
+ 17.62635644741625,
524
+ 17.95219714852476,
525
+ 18.281524751807332,
526
+ 18.614349837764564,
527
+ 18.95068293910138,
528
+ 19.290534541298456,
529
+ 19.633915083172692,
530
+ 19.98083495742689,
531
+ 20.331304511189067,
532
+ 20.685334046541502,
533
+ 21.042933821039977,
534
+ 21.404114048223256,
535
+ 21.76888489811322,
536
+ 22.137256497705877,
537
+ 22.50923893145328,
538
+ 22.884842241736916,
539
+ 23.264076429332462,
540
+ 23.6469514538663,
541
+ 24.033477234264016,
542
+ 24.42366364919083,
543
+ 24.817520537484558,
544
+ 25.21505769858089,
545
+ 25.61628489293138,
546
+ 26.021211842414342,
547
+ 26.429848230738664,
548
+ 26.842203703840827,
549
+ 27.258287870275353,
550
+ 27.678110301598522,
551
+ 28.10168053274597,
552
+ 28.529008062403893,
553
+ 28.96010235337422,
554
+ 29.39497283293396,
555
+ 29.83362889318845,
556
+ 30.276079891419332,
557
+ 30.722335150426627,
558
+ 31.172403958865512,
559
+ 31.62629557157785,
560
+ 32.08401920991837,
561
+ 32.54558406207592,
562
+ 33.010999283389665,
563
+ 33.4802739966603,
564
+ 33.953417292456834,
565
+ 34.430438229418264,
566
+ 34.911345834551085,
567
+ 35.39614910352207,
568
+ 35.88485700094671,
569
+ 36.37747846067349,
570
+ 36.87402238606382,
571
+ 37.37449765026789,
572
+ 37.87891309649659,
573
+ 38.38727753828926,
574
+ 38.89959975977785,
575
+ 39.41588851594697,
576
+ 39.93615253289054,
577
+ 40.460400508064545,
578
+ 40.98864111053629,
579
+ 41.520882981230194,
580
+ 42.05713473317016,
581
+ 42.597404951718396,
582
+ 43.141702194811224,
583
+ 43.6900349931913,
584
+ 44.24241185063697,
585
+ 44.798841244188324,
586
+ 45.35933162437017,
587
+ 45.92389141541209,
588
+ 46.49252901546552,
589
+ 47.065252796817916,
590
+ 47.64207110610409,
591
+ 48.22299226451468,
592
+ 48.808024568002054,
593
+ 49.3971762874833,
594
+ 49.9904556690408,
595
+ 50.587870934119984,
596
+ 51.189430279724725,
597
+ 51.79514187861014,
598
+ 52.40501387947288,
599
+ 53.0190544071392,
600
+ 53.637271562750364,
601
+ 54.259673423945976,
602
+ 54.88626804504493,
603
+ 55.517063457223934,
604
+ 56.15206766869424,
605
+ 56.79128866487574,
606
+ 57.43473440856916,
607
+ 58.08241284012621,
608
+ 58.734331877617365,
609
+ 59.39049941699807,
610
+ 60.05092333227251,
611
+ 60.715611475655585,
612
+ 61.38457167773311,
613
+ 62.057811747619894,
614
+ 62.7353394731159,
615
+ 63.417162620860914,
616
+ 64.10328893648692,
617
+ 64.79372614476921,
618
+ 65.48848194977529,
619
+ 66.18756403501224,
620
+ 66.89098006357258,
621
+ 67.59873767827808,
622
+ 68.31084450182222,
623
+ 69.02730813691093,
624
+ 69.74813616640164,
625
+ 70.47333615344107,
626
+ 71.20291564160104,
627
+ 71.93688215501312,
628
+ 72.67524319850172,
629
+ 73.41800625771542,
630
+ 74.16517879925733,
631
+ 74.9167682708136,
632
+ 75.67278210128072,
633
+ 76.43322770089146,
634
+ 77.1981124613393,
635
+ 77.96744375590167,
636
+ 78.74122893956174,
637
+ 79.51947534912904,
638
+ 80.30219030335869,
639
+ 81.08938110306934,
640
+ 81.88105503125999,
641
+ 82.67721935322541,
642
+ 83.4778813166706,
643
+ 84.28304815182372,
644
+ 85.09272707154808,
645
+ 85.90692527145302,
646
+ 86.72564993000343,
647
+ 87.54890820862819,
648
+ 88.3767072518277,
649
+ 89.2090541872801,
650
+ 90.04595612594655,
651
+ 90.88742016217518,
652
+ 91.73345337380438,
653
+ 92.58406282226491,
654
+ 93.43925555268066,
655
+ 94.29903859396902,
656
+ 95.16341895893969,
657
+ 96.03240364439274,
658
+ 96.9059996312159,
659
+ 97.78421388448044,
660
+ 98.6670533535366,
661
+ 99.55452497210776
662
+ ]);
663
+ let HctSolver = _HctSolver;
664
+ /**
665
+ * @license
666
+ * Copyright 2021 Google LLC
667
+ *
668
+ * Licensed under the Apache License, Version 2.0 (the "License");
669
+ * you may not use this file except in compliance with the License.
670
+ * You may obtain a copy of the License at
671
+ *
672
+ * http://www.apache.org/licenses/LICENSE-2.0
673
+ *
674
+ * Unless required by applicable law or agreed to in writing, software
675
+ * distributed under the License is distributed on an "AS IS" BASIS,
676
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
677
+ * See the License for the specific language governing permissions and
678
+ * limitations under the License.
679
+ */
680
+ class Hct {
681
+ constructor(argb) {
682
+ /**
683
+ * @param hue 0 <= hue < 360; invalid values are corrected.
684
+ * @param chroma 0 <= chroma < ?; Informally, colorfulness. The color
685
+ * returned may be lower than the requested chroma. Chroma has a different
686
+ * maximum for any given hue and tone.
687
+ * @param tone 0 <= tone <= 100; invalid values are corrected.
688
+ * @return HCT representation of a color in default viewing conditions.
689
+ */
690
+ __publicField(this, "internalHue");
691
+ __publicField(this, "internalChroma");
692
+ __publicField(this, "internalTone");
693
+ this.argb = argb;
694
+ const cam = Cam16.fromInt(argb);
695
+ this.internalHue = cam.hue;
696
+ this.internalChroma = cam.chroma;
697
+ this.internalTone = lstarFromArgb(argb);
698
+ this.argb = argb;
699
+ }
700
+ /**
701
+ * A number, in degrees, representing ex. red, orange, yellow, etc.
702
+ * Ranges from 0 <= hue < 360.
703
+ */
704
+ get hue() {
705
+ return this.internalHue;
706
+ }
707
+ /**
708
+ * @param newHue 0 <= newHue < 360; invalid values are corrected.
709
+ * Chroma may decrease because chroma has a different maximum for any given
710
+ * hue and tone.
711
+ */
712
+ set hue(newHue) {
713
+ this.setInternalState(
714
+ HctSolver.solveToInt(newHue, this.internalChroma, this.internalTone)
715
+ );
716
+ }
717
+ get chroma() {
718
+ return this.internalChroma;
719
+ }
720
+ /**
721
+ * @param newChroma 0 <= newChroma < ?
722
+ * Chroma may decrease because chroma has a different maximum for any given
723
+ * hue and tone.
724
+ */
725
+ set chroma(newChroma) {
726
+ this.setInternalState(
727
+ HctSolver.solveToInt(this.internalHue, newChroma, this.internalTone)
728
+ );
729
+ }
730
+ /** Lightness. Ranges from 0 to 100. */
731
+ get tone() {
732
+ return this.internalTone;
733
+ }
734
+ /**
735
+ * @param newTone 0 <= newTone <= 100; invalid valids are corrected.
736
+ * Chroma may decrease because chroma has a different maximum for any given
737
+ * hue and tone.
738
+ */
739
+ set tone(newTone) {
740
+ this.setInternalState(
741
+ HctSolver.solveToInt(this.internalHue, this.internalChroma, newTone)
742
+ );
743
+ }
744
+ static from(hue, chroma, tone) {
745
+ return new Hct(HctSolver.solveToInt(hue, chroma, tone));
746
+ }
747
+ /**
748
+ * @param argb ARGB representation of a color.
749
+ * @return HCT representation of a color in default viewing conditions
750
+ */
751
+ static fromInt(argb) {
752
+ return new Hct(argb);
753
+ }
754
+ static isBlue(hue) {
755
+ return hue >= 250 && hue < 270;
756
+ }
757
+ static isYellow(hue) {
758
+ return hue >= 105 && hue < 125;
759
+ }
760
+ static isCyan(hue) {
761
+ return hue >= 170 && hue < 207;
762
+ }
763
+ toInt() {
764
+ return this.argb;
765
+ }
766
+ /** Sets a property of the Hct object. */
767
+ setValue(propertyName, value) {
768
+ this[propertyName] = value;
769
+ }
770
+ toString() {
771
+ return `HCT(${this.hue.toFixed(0)}, ${this.chroma.toFixed(0)}, ${this.tone.toFixed(
772
+ 0
773
+ )})`;
774
+ }
775
+ /**
776
+ * Translates a color into different [ViewingConditions].
777
+ *
778
+ * Colors change appearance. They look different with lights on versus off,
779
+ * the same color, as in hex code, on white looks different when on black.
780
+ * This is called color relativity, most famously explicated by Josef Albers
781
+ * in Interaction of Color.
782
+ *
783
+ * In color science, color appearance models can account for this and
784
+ * calculate the appearance of a color in different settings. HCT is based on
785
+ * CAM16, a color appearance model, and uses it to make these calculations.
786
+ *
787
+ * See [ViewingConditions.make] for parameters affecting color appearance.
788
+ */
789
+ inViewingConditions(vc) {
790
+ const cam = Cam16.fromInt(this.toInt());
791
+ const viewedInVc = cam.xyzInViewingConditions(vc);
792
+ const recastInVc = Cam16.fromXyzInViewingConditions(
793
+ viewedInVc[0],
794
+ viewedInVc[1],
795
+ viewedInVc[2],
796
+ ViewingConditions.make()
797
+ );
798
+ const recastHct = Hct.from(
799
+ recastInVc.hue,
800
+ recastInVc.chroma,
801
+ lstarFromY(viewedInVc[1])
802
+ );
803
+ return recastHct;
804
+ }
805
+ setInternalState(argb) {
806
+ const cam = Cam16.fromInt(argb);
807
+ this.internalHue = cam.hue;
808
+ this.internalChroma = cam.chroma;
809
+ this.internalTone = lstarFromArgb(argb);
810
+ this.argb = argb;
811
+ }
812
+ }
813
+ /**
814
+ * @license
815
+ * Copyright 2023 Google LLC
816
+ *
817
+ * Licensed under the Apache License, Version 2.0 (the "License");
818
+ * you may not use this file except in compliance with the License.
819
+ * You may obtain a copy of the License at
820
+ *
821
+ * http://www.apache.org/licenses/LICENSE-2.0
822
+ *
823
+ * Unless required by applicable law or agreed to in writing, software
824
+ * distributed under the License is distributed on an "AS IS" BASIS,
825
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
826
+ * See the License for the specific language governing permissions and
827
+ * limitations under the License.
828
+ */
829
+ class ContrastCurve {
830
+ /**
831
+ * Creates a `ContrastCurve` object.
832
+ *
833
+ * @param low Value for contrast level -1.0
834
+ * @param normal Value for contrast level 0.0
835
+ * @param medium Value for contrast level 0.5
836
+ * @param high Value for contrast level 1.0
837
+ */
838
+ constructor(low, normal, medium, high) {
839
+ this.low = low;
840
+ this.normal = normal;
841
+ this.medium = medium;
842
+ this.high = high;
843
+ }
844
+ /**
845
+ * Returns the value at a given contrast level.
846
+ *
847
+ * @param contrastLevel The contrast level. 0.0 is the default (normal); -1.0
848
+ * is the lowest; 1.0 is the highest.
849
+ * @return The value. For contrast ratios, a number between 1.0 and 21.0.
850
+ */
851
+ get(contrastLevel) {
852
+ if (contrastLevel <= -1) {
853
+ return this.low;
854
+ } else if (contrastLevel < 0) {
855
+ return lerp(this.low, this.normal, (contrastLevel - -1) / 1);
856
+ } else if (contrastLevel < 0.5) {
857
+ return lerp(this.normal, this.medium, (contrastLevel - 0) / 0.5);
858
+ } else if (contrastLevel < 1) {
859
+ return lerp(this.medium, this.high, (contrastLevel - 0.5) / 0.5);
860
+ } else {
861
+ return this.high;
862
+ }
863
+ }
864
+ }
865
+ function getCurve(defaultContrast) {
866
+ if (defaultContrast === 1.5) {
867
+ return new ContrastCurve(1.5, 1.5, 3, 4.5);
868
+ } else if (defaultContrast === 3) {
869
+ return new ContrastCurve(3, 3, 4.5, 7);
870
+ } else if (defaultContrast === 4.5) {
871
+ return new ContrastCurve(4.5, 4.5, 7, 11);
872
+ } else if (defaultContrast === 6) {
873
+ return new ContrastCurve(6, 6, 7, 11);
874
+ } else if (defaultContrast === 7) {
875
+ return new ContrastCurve(7, 7, 11, 21);
876
+ } else if (defaultContrast === 9) {
877
+ return new ContrastCurve(9, 9, 11, 21);
878
+ } else if (defaultContrast === 11) {
879
+ return new ContrastCurve(11, 11, 21, 21);
880
+ } else if (defaultContrast === 21) {
881
+ return new ContrastCurve(21, 21, 21, 21);
882
+ } else {
883
+ return new ContrastCurve(defaultContrast, defaultContrast, 7, 21);
884
+ }
885
+ }
886
+ function tMaxC(palette, lowerBound = 0, upperBound = 100, chromaMultiplier = 1) {
887
+ const answer = findBestToneForChroma(
888
+ palette.hue,
889
+ palette.chroma * chromaMultiplier,
890
+ 100,
891
+ true
892
+ );
893
+ return clampDouble(lowerBound, upperBound, answer);
894
+ }
895
+ function tMinC(palette, lowerBound = 0, upperBound = 100) {
896
+ const answer = findBestToneForChroma(palette.hue, palette.chroma, 0, false);
897
+ return clampDouble(lowerBound, upperBound, answer);
898
+ }
899
+ function findBestToneForChroma(hue, chroma, tone, byDecreasingTone) {
900
+ let answer = tone;
901
+ let bestCandidate = Hct.from(hue, chroma, answer);
902
+ while (bestCandidate.chroma < chroma) {
903
+ if (tone < 0 || tone > 100) {
904
+ break;
905
+ }
906
+ tone += byDecreasingTone ? -1 : 1;
907
+ const newCandidate = Hct.from(hue, chroma, tone);
908
+ if (bestCandidate.chroma < newCandidate.chroma) {
909
+ bestCandidate = newCandidate;
910
+ answer = tone;
911
+ }
912
+ }
913
+ return answer;
914
+ }
915
+ function calculateToneAdjustmentPercentage(toneA, toneB, desiredRatio) {
916
+ const currentRatio = Contrast.ratioOfTones(toneA, toneB);
917
+ if (currentRatio >= desiredRatio) {
918
+ return 0;
919
+ }
920
+ const lighterTone = Contrast.lighter(toneA, desiredRatio);
921
+ const darkerTone = Contrast.darker(toneA, desiredRatio);
922
+ if (lighterTone !== -1 && toneB < lighterTone) {
923
+ const percentageToAdjust = (toneB - lighterTone) / (toneA - lighterTone);
924
+ return clampDouble(0, 1, percentageToAdjust);
925
+ }
926
+ if (darkerTone !== -1 && toneB > darkerTone) {
927
+ const percentageToAdjust = (toneB - darkerTone) / (toneA - darkerTone);
928
+ return clampDouble(0, 1, percentageToAdjust);
929
+ }
930
+ return 0;
931
+ }
932
+ /**
933
+ * @license
934
+ * Copyright 2022 Google LLC
935
+ *
936
+ * Licensed under the Apache License, Version 2.0 (the "License");
937
+ * you may not use this file except in compliance with the License.
938
+ * You may obtain a copy of the License at
939
+ *
940
+ * http://www.apache.org/licenses/LICENSE-2.0
941
+ *
942
+ * Unless required by applicable law or agreed to in writing, software
943
+ * distributed under the License is distributed on an "AS IS" BASIS,
944
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
945
+ * See the License for the specific language governing permissions and
946
+ * limitations under the License.
947
+ */
948
+ class DynamicColor {
949
+ /**
950
+ * The base constructor for DynamicColor.
951
+ *
952
+ * _Strongly_ prefer using one of the convenience constructors. This class is
953
+ * arguably too flexible to ensure it can support any scenario. Functional
954
+ * arguments allow overriding without risks that come with subclasses.
955
+ *
956
+ * For example, the default behavior of adjust tone at max contrast
957
+ * to be at a 7.0 ratio with its background is principled and
958
+ * matches accessibility guidance. That does not mean it's the desired
959
+ * approach for _every_ design system, and every color pairing,
960
+ * always, in every case.
961
+ *
962
+ * @param name The name of the dynamic color. Defaults to empty.
963
+ * @param palette Function that provides a TonalPalette given DynamicScheme. A
964
+ * TonalPalette is defined by a hue and chroma, so this replaces the need
965
+ * to specify hue/chroma. By providing a tonal palette, when contrast
966
+ * adjustments are made, intended chroma can be preserved.
967
+ * @param tone Function that provides a tone, given a DynamicScheme.
968
+ * @param isBackground Whether this dynamic color is a background, with some
969
+ * other color as the foreground. Defaults to false.
970
+ * @param chromaMultiplier A factor that multiplies the chroma for this color.
971
+ * @param background The background of the dynamic color (as a function of a
972
+ * `DynamicScheme`), if it exists.
973
+ * @param secondBackground A second background of the dynamic color (as a
974
+ * function of a `DynamicScheme`), if it exists.
975
+ * @param contrastCurve A `ContrastCurve` object specifying how its contrast
976
+ * against its background should behave in various contrast levels
977
+ * options.
978
+ * @param adjustTone A `AdjustTone` object specifying a tone delta
979
+ * constraint between two colors. One of them must be the color being
980
+ * constructed.
981
+ */
982
+ constructor(name, palette, tone, isBackground, chromaMultiplier, background, secondBackground, contrastCurve, adjustTone) {
983
+ this.name = name;
984
+ this.palette = palette;
985
+ this.tone = tone;
986
+ this.isBackground = isBackground;
987
+ this.chromaMultiplier = chromaMultiplier;
988
+ this.background = background;
989
+ this.secondBackground = secondBackground;
990
+ this.contrastCurve = contrastCurve;
991
+ this.adjustTone = adjustTone;
992
+ if (!background && secondBackground) {
993
+ throw new Error(
994
+ `Color ${name} has secondBackgrounddefined, but background is not defined.`
995
+ );
996
+ }
997
+ if (!background && contrastCurve) {
998
+ throw new Error(
999
+ `Color ${name} has contrastCurvedefined, but background is not defined.`
1000
+ );
1001
+ }
1002
+ if (background && !contrastCurve) {
1003
+ throw new Error(
1004
+ `Color ${name} has backgrounddefined, but contrastCurve is not defined.`
1005
+ );
1006
+ }
1007
+ }
1008
+ /**
1009
+ * Create a DynamicColor defined by a TonalPalette and HCT tone.
1010
+ *
1011
+ * @param args Functions with DynamicScheme as input. Must provide a palette
1012
+ * and tone. May provide a background DynamicColor and ToneDeltaPair.
1013
+ */
1014
+ static fromPalette(args) {
1015
+ return new DynamicColor(
1016
+ args.name ?? "",
1017
+ args.palette,
1018
+ args.tone ?? (() => DynamicColor.getInitialToneFromBackground(args.background)),
1019
+ args.isBackground ?? false,
1020
+ args.chromaMultiplier,
1021
+ args.background,
1022
+ args.secondBackground,
1023
+ args.contrastCurve,
1024
+ args.adjustTone
1025
+ );
1026
+ }
1027
+ // static getInitialToneFromBackground(
1028
+ // background?: () => Color | undefined,
1029
+ // ): number {
1030
+ // if (background === undefined) {
1031
+ // return 50;
1032
+ // }
1033
+ // return (background() ? background()!.getTone() : 50);
1034
+ // }
1035
+ /**
1036
+ * Given a background tone, finds a foreground tone, while ensuring they reach
1037
+ * a contrast ratio that is as close to [ratio] as possible.
1038
+ *
1039
+ * @param bgTone Tone in HCT. Range is 0 to 100, undefined behavior when it
1040
+ * falls outside that range.
1041
+ * @param ratio The contrast ratio desired between bgTone and the return
1042
+ * value.
1043
+ */
1044
+ static foregroundTone(bgTone, ratio) {
1045
+ const lighterTone = Contrast.lighterUnsafe(bgTone, ratio);
1046
+ const darkerTone = Contrast.darkerUnsafe(bgTone, ratio);
1047
+ const lighterRatio = Contrast.ratioOfTones(lighterTone, bgTone);
1048
+ const darkerRatio = Contrast.ratioOfTones(darkerTone, bgTone);
1049
+ const preferLighter = DynamicColor.tonePrefersLightForeground(bgTone);
1050
+ if (preferLighter) {
1051
+ const negligibleDifference = Math.abs(lighterRatio - darkerRatio) < 0.1 && lighterRatio < ratio && darkerRatio < ratio;
1052
+ return lighterRatio >= ratio || lighterRatio >= darkerRatio || negligibleDifference ? lighterTone : darkerTone;
1053
+ } else {
1054
+ return darkerRatio >= ratio || darkerRatio >= lighterRatio ? darkerTone : lighterTone;
1055
+ }
1056
+ }
1057
+ /**
1058
+ * Returns whether [tone] prefers a light foreground.
1059
+ *
1060
+ * People prefer white foregrounds on ~T60-70. Observed over time, and also
1061
+ * by Andrew Somers during research for APCA.
1062
+ *
1063
+ * T60 used as to create the smallest discontinuity possible when skipping
1064
+ * down to T49 in order to ensure light foregrounds.
1065
+ * Since `tertiaryContainer` in dark monochrome scheme requires a tone of
1066
+ * 60, it should not be adjusted. Therefore, 60 is excluded here.
1067
+ */
1068
+ static tonePrefersLightForeground(tone) {
1069
+ return Math.round(tone) < 60;
1070
+ }
1071
+ /**
1072
+ * Returns whether [tone] can reach a contrast ratio of 4.5 with a lighter
1073
+ * color.
1074
+ */
1075
+ static toneAllowsLightForeground(tone) {
1076
+ return Math.round(tone) <= 49;
1077
+ }
1078
+ /**
1079
+ * Adjusts a tone such that white has 4.5 contrast, if the tone is
1080
+ * reasonably close to supporting it.
1081
+ */
1082
+ static enableLightForeground(tone) {
1083
+ if (DynamicColor.tonePrefersLightForeground(tone) && !DynamicColor.toneAllowsLightForeground(tone)) {
1084
+ return 49;
1085
+ }
1086
+ return tone;
1087
+ }
1088
+ /**
1089
+ * Returns a deep copy of this DynamicColor.
1090
+ */
1091
+ clone() {
1092
+ return DynamicColor.fromPalette({
1093
+ name: this.name,
1094
+ palette: this.palette,
1095
+ tone: this.tone,
1096
+ isBackground: this.isBackground,
1097
+ chromaMultiplier: this.chromaMultiplier,
1098
+ background: this.background,
1099
+ secondBackground: this.secondBackground,
1100
+ contrastCurve: this.contrastCurve,
1101
+ adjustTone: this.adjustTone
1102
+ });
1103
+ }
1104
+ /**
1105
+ * Returns a ARGB integer (i.e. a hex code).
1106
+ *
1107
+ * @param scheme Defines the conditions of the user interface, for example,
1108
+ * whether or not it is dark mode or light mode, and what the desired
1109
+ * contrast level is.
1110
+ */
1111
+ getArgb(scheme) {
1112
+ return this.getHct(scheme).toInt();
1113
+ }
1114
+ /**
1115
+ * Returns a color, expressed in the HCT color space, that this
1116
+ * DynamicColor is under the conditions in scheme.
1117
+ *
1118
+ * @param scheme Defines the conditions of the user interface, for example,
1119
+ * whether or not it is dark mode or light mode, and what the desired
1120
+ * contrast level is.
1121
+ */
1122
+ getHct(scheme) {
1123
+ const palette = this.palette(scheme);
1124
+ const tone = this.getTone(scheme);
1125
+ const hue = palette.hue;
1126
+ const chroma = palette.chroma * (this.chromaMultiplier ? this.chromaMultiplier(scheme) : 1);
1127
+ return Hct.from(hue, chroma, tone);
1128
+ }
1129
+ /**
1130
+ * Returns a tone, T in the HCT color space, that this DynamicColor is under
1131
+ * the conditions in scheme.
1132
+ *
1133
+ * @param scheme Defines the conditions of the user interface, for example,
1134
+ * whether or not it is dark mode or light mode, and what the desired
1135
+ * contrast level is.
1136
+ */
1137
+ getTone(scheme) {
1138
+ const adjustTone = this.adjustTone ? this.adjustTone(scheme) : void 0;
1139
+ if (adjustTone) {
1140
+ return adjustTone({ scheme, dynamicColor: this });
1141
+ } else {
1142
+ let answer = this.tone(scheme);
1143
+ if (this.background == void 0 || this.background(scheme) === void 0 || this.contrastCurve == void 0 || this.contrastCurve(scheme) === void 0) {
1144
+ return answer;
1145
+ }
1146
+ const bgTone = this.background(scheme).getTone(scheme);
1147
+ const desiredRatio = this.contrastCurve(scheme).get(
1148
+ scheme.contrastLevel
1149
+ );
1150
+ answer = Contrast.ratioOfTones(bgTone, answer) >= desiredRatio && scheme.contrastLevel >= 0 ? answer : DynamicColor.foregroundTone(bgTone, desiredRatio);
1151
+ if (this.isBackground && !this.name.endsWith("_fixed_dim")) {
1152
+ if (answer >= 57) {
1153
+ answer = clampDouble(65, 100, answer);
1154
+ } else {
1155
+ answer = clampDouble(0, 49, answer);
1156
+ }
1157
+ }
1158
+ if (this.secondBackground == void 0 || this.secondBackground(scheme) === void 0) {
1159
+ return answer;
1160
+ }
1161
+ const [bg1, bg2] = [this.background, this.secondBackground];
1162
+ const [bgTone1, bgTone2] = [
1163
+ bg1(scheme).getTone(scheme),
1164
+ bg2(scheme).getTone(scheme)
1165
+ ];
1166
+ const [upper, lower] = [
1167
+ Math.max(bgTone1, bgTone2),
1168
+ Math.min(bgTone1, bgTone2)
1169
+ ];
1170
+ if (Contrast.ratioOfTones(upper, answer) >= desiredRatio && Contrast.ratioOfTones(lower, answer) >= desiredRatio) {
1171
+ return answer;
1172
+ }
1173
+ const lightOption = Contrast.lighter(upper, desiredRatio);
1174
+ const darkOption = Contrast.darker(lower, desiredRatio);
1175
+ const availables = [];
1176
+ if (lightOption !== -1) availables.push(lightOption);
1177
+ if (darkOption !== -1) availables.push(darkOption);
1178
+ const prefersLight = DynamicColor.tonePrefersLightForeground(bgTone1) || DynamicColor.tonePrefersLightForeground(bgTone2);
1179
+ if (prefersLight) {
1180
+ return lightOption < 0 ? 100 : lightOption;
1181
+ }
1182
+ if (availables.length === 1) {
1183
+ return availables[0];
1184
+ }
1185
+ return darkOption < 0 ? 0 : darkOption;
1186
+ }
1187
+ }
1188
+ }
1189
+ /**
1190
+ * @license
1191
+ * Copyright 2023 Google LLC
1192
+ *
1193
+ * Licensed under the Apache License, Version 2.0 (the "License");
1194
+ * you may not use this file except in compliance with the License.
1195
+ * You may obtain a copy of the License at
1196
+ *
1197
+ * http://www.apache.org/licenses/LICENSE-2.0
1198
+ *
1199
+ * Unless required by applicable law or agreed to in writing, software
1200
+ * distributed under the License is distributed on an "AS IS" BASIS,
1201
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1202
+ * See the License for the specific language governing permissions and
1203
+ * limitations under the License.
1204
+ */
1205
+ class ToneDeltaPair {
1206
+ /**
1207
+ * Documents a constraint in tone distance between two DynamicColors.
1208
+ *
1209
+ * The polarity is an adjective that describes "A", compared to "B".
1210
+ *
1211
+ * For instance, ToneDeltaPair(A, B, 15, 'darker', 'exact') states that
1212
+ * A's tone should be exactly 15 darker than B's.
1213
+ *
1214
+ * 'relative_darker' and 'relative_lighter' describes the tone adjustment
1215
+ * relative to the surface color trend (white in light mode; black in dark
1216
+ * mode). For instance, ToneDeltaPair(A, B, 10, 'relative_lighter',
1217
+ * 'farther') states that A should be at least 10 lighter than B in light
1218
+ * mode, and at least 10 darker than B in dark mode.
1219
+ *
1220
+ * @param roleA The first role in a pair.
1221
+ * @param roleB The second role in a pair.
1222
+ * @param delta Required difference between tones. Absolute value, negative
1223
+ * values have undefined behavior.
1224
+ * @param polarity The relative relation between tones of roleA and roleB,
1225
+ * as described above.
1226
+ * @param constraint How to fulfill the tone delta pair constraint.
1227
+ * @param stayTogether Whether these two roles should stay on the same side
1228
+ * of the "awkward zone" (T50-59). This is necessary for certain cases where
1229
+ * one role has two backgrounds.
1230
+ */
1231
+ constructor(roleA, roleB, delta, polarity, stayTogether, constraint) {
1232
+ this.roleA = roleA;
1233
+ this.roleB = roleB;
1234
+ this.delta = delta;
1235
+ this.polarity = polarity;
1236
+ this.stayTogether = stayTogether;
1237
+ this.constraint = constraint;
1238
+ this.constraint = constraint ?? "exact";
1239
+ }
1240
+ adjustedTone({ context: ctx, color }) {
1241
+ const roleA = this.roleA;
1242
+ const roleB = this.roleB;
1243
+ const polarity = this.polarity;
1244
+ const constraint = this.constraint;
1245
+ const absoluteDelta = polarity === "darker" || polarity === "relative_lighter" && ctx.isDark || polarity === "relative_darker" && !ctx.isDark ? -this.delta : this.delta;
1246
+ const amRoleA = color.name === roleA.name;
1247
+ const selfRole = amRoleA ? roleA : roleB;
1248
+ const refRole = amRoleA ? roleB : roleA;
1249
+ if (!(selfRole instanceof ColorFromPalette)) {
1250
+ throw new Error("selfRole is not a ColorFromPalette");
1251
+ }
1252
+ let selfTone = selfRole.options.tone;
1253
+ const refTone = refRole.getTone();
1254
+ const relativeDelta = absoluteDelta * (amRoleA ? 1 : -1);
1255
+ if (constraint === "exact") {
1256
+ selfTone = clampDouble(0, 100, refTone + relativeDelta);
1257
+ } else if (constraint === "nearer") {
1258
+ if (relativeDelta > 0) {
1259
+ selfTone = clampDouble(
1260
+ 0,
1261
+ 100,
1262
+ clampDouble(refTone, refTone + relativeDelta, selfTone)
1263
+ );
1264
+ } else {
1265
+ selfTone = clampDouble(
1266
+ 0,
1267
+ 100,
1268
+ clampDouble(refTone + relativeDelta, refTone, selfTone)
1269
+ );
1270
+ }
1271
+ } else if (constraint === "farther") {
1272
+ if (relativeDelta > 0) {
1273
+ selfTone = clampDouble(refTone + relativeDelta, 100, selfTone);
1274
+ } else {
1275
+ selfTone = clampDouble(0, refTone + relativeDelta, selfTone);
1276
+ }
1277
+ }
1278
+ if (color instanceof ColorFromPalette) {
1279
+ if (color.options.background && color.options.contrastCurve) {
1280
+ const background = color.options.background;
1281
+ const contrastCurve = color.options.contrastCurve;
1282
+ if (background && contrastCurve) {
1283
+ const bgTone = background.getTone();
1284
+ const selfContrast = contrastCurve.get(ctx.contrastLevel);
1285
+ selfTone = Contrast.ratioOfTones(bgTone, selfTone) >= selfContrast && ctx.contrastLevel >= 0 ? selfTone : DynamicColor$1.foregroundTone(bgTone, selfContrast);
1286
+ }
1287
+ }
1288
+ if (color.options.isBackground && !color.name.endsWith("_fixed_dim")) {
1289
+ if (selfTone >= 57) {
1290
+ selfTone = clampDouble(65, 100, selfTone);
1291
+ } else {
1292
+ selfTone = clampDouble(0, 49, selfTone);
1293
+ }
1294
+ }
1295
+ }
1296
+ return selfTone;
1297
+ }
1298
+ }
1299
+ const toneDeltaPair = (...params) => {
1300
+ return (args) => new ToneDeltaPair(...params).adjustedTone(args);
1301
+ };
1302
+ function argbToRgb(argb) {
1303
+ return {
1304
+ r: argb >> 16 & 255,
1305
+ g: argb >> 8 & 255,
1306
+ b: argb & 255
1307
+ };
1308
+ }
1309
+ function getInitialToneFromBackground(background) {
1310
+ if (background === void 0) {
1311
+ return 50;
1312
+ }
1313
+ return background.getTone();
1314
+ }
1315
+ class Color {
1316
+ constructor(name) {
1317
+ this.name = name;
1318
+ }
1319
+ static maxChroma(hue, tone = 50) {
1320
+ return Hct.from(hue, 200, tone).chroma;
1321
+ }
1322
+ getHex() {
1323
+ return hexFromArgb(this.getArgb());
1324
+ }
1325
+ getArgb() {
1326
+ return this.getHct().toInt();
1327
+ }
1328
+ getRgb() {
1329
+ return argbToRgb(this.getArgb());
1330
+ }
1331
+ getTone() {
1332
+ return this.getHct().tone;
1333
+ }
1334
+ }
1335
+ class ColorAlias extends Color {
1336
+ constructor(name, as, colorService) {
1337
+ super(name);
1338
+ this.as = as;
1339
+ this.colorService = colorService;
1340
+ }
1341
+ getHct() {
1342
+ return this.colorService.get(this.as).getHct();
1343
+ }
1344
+ color() {
1345
+ return this.colorService.get(this.as);
1346
+ }
1347
+ }
1348
+ class ColorFromHex extends Color {
1349
+ constructor(name, _hex) {
1350
+ super(name);
1351
+ this._hex = _hex;
1352
+ this._hex = _hex;
1353
+ }
1354
+ getHct() {
1355
+ return Hct.fromInt(argbFromHex(this.getHex()));
1356
+ }
1357
+ getHex() {
1358
+ return this._hex;
1359
+ }
1360
+ setHex(hex) {
1361
+ this._hex = hex;
1362
+ }
1363
+ }
1364
+ class ColorFromPalette extends Color {
1365
+ constructor(name, _options, context) {
1366
+ super(name);
1367
+ this._options = _options;
1368
+ this.context = context;
1369
+ this.validateOption();
1370
+ }
1371
+ get options() {
1372
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1373
+ const options = {
1374
+ ...this._options,
1375
+ palette: this._options.palette(),
1376
+ tone: (_b = (_a = this._options).tone) == null ? void 0 : _b.call(_a),
1377
+ chromaMultiplier: (_d = (_c = this._options).chromaMultiplier) == null ? void 0 : _d.call(_c),
1378
+ background: (_f = (_e = this._options).background) == null ? void 0 : _f.call(_e),
1379
+ secondBackground: (_h = (_g = this._options).secondBackground) == null ? void 0 : _h.call(_g),
1380
+ contrastCurve: (_j = (_i = this._options).contrastCurve) == null ? void 0 : _j.call(_i),
1381
+ adjustTone: (_l = (_k = this._options).adjustTone) == null ? void 0 : _l.call(_k)
1382
+ };
1383
+ return {
1384
+ ...options,
1385
+ chromaMultiplier: options.chromaMultiplier ?? 1,
1386
+ tone: options.tone ?? getInitialToneFromBackground(options.background)
1387
+ };
1388
+ }
1389
+ update(args) {
1390
+ this._options = { ...this._options, ...args };
1391
+ this.validateOption();
1392
+ }
1393
+ validateOption() {
1394
+ const option = this._options;
1395
+ if ("palette" in option) {
1396
+ if (!option.background && option.secondBackground) {
1397
+ throw new Error(
1398
+ `Color ${this.name} has secondBackground defined, but background is not defined.`
1399
+ );
1400
+ }
1401
+ if (!option.background && option.contrastCurve) {
1402
+ throw new Error(
1403
+ `Color ${this.name} has contrastCurve defined, but background is not defined.`
1404
+ );
1405
+ }
1406
+ if (option.background && !option.contrastCurve) {
1407
+ throw new Error(
1408
+ `Color ${this.name} has background defined, but contrastCurve is not defined.`
1409
+ );
1410
+ }
1411
+ }
1412
+ }
1413
+ getHct() {
1414
+ const option = this.options;
1415
+ const palette = option.palette;
1416
+ const tone = this.getTone();
1417
+ const hue = palette.hue;
1418
+ const chroma = palette.chroma * option.chromaMultiplier;
1419
+ return Hct.from(hue, chroma, tone);
1420
+ }
1421
+ getTone() {
1422
+ const context = this.context;
1423
+ const options = this.options;
1424
+ const adjustTone = options.adjustTone;
1425
+ if (adjustTone) {
1426
+ return adjustTone({ context, color: this });
1427
+ } else {
1428
+ let answer = options.tone;
1429
+ if (!options.background || !options.contrastCurve) {
1430
+ return answer;
1431
+ }
1432
+ const bgTone = options.background.getTone();
1433
+ const desiredRatio = options.contrastCurve.get(context.contrastLevel);
1434
+ answer = Contrast.ratioOfTones(bgTone, answer) >= desiredRatio && context.contrastLevel >= 0 ? answer : DynamicColor.foregroundTone(bgTone, desiredRatio);
1435
+ if (options.isBackground && !this.name.endsWith("_fixed_dim")) {
1436
+ if (answer >= 57) {
1437
+ answer = clampDouble(65, 100, answer);
1438
+ } else {
1439
+ answer = clampDouble(0, 49, answer);
1440
+ }
1441
+ }
1442
+ if (!options.secondBackground) {
1443
+ return answer;
1444
+ }
1445
+ const [bg1, bg2] = [options.background, options.secondBackground];
1446
+ const [bgTone1, bgTone2] = [bg1.getTone(), bg2.getTone()];
1447
+ const [upper, lower] = [
1448
+ Math.max(bgTone1, bgTone2),
1449
+ Math.min(bgTone1, bgTone2)
1450
+ ];
1451
+ if (Contrast.ratioOfTones(upper, answer) >= desiredRatio && Contrast.ratioOfTones(lower, answer) >= desiredRatio) {
1452
+ return answer;
1453
+ }
1454
+ const lightOption = Contrast.lighter(upper, desiredRatio);
1455
+ const darkOption = Contrast.darker(lower, desiredRatio);
1456
+ const availables = [];
1457
+ if (lightOption !== -1) availables.push(lightOption);
1458
+ if (darkOption !== -1) availables.push(darkOption);
1459
+ const prefersLight = DynamicColor.tonePrefersLightForeground(bgTone1) || DynamicColor.tonePrefersLightForeground(bgTone2);
1460
+ if (prefersLight) {
1461
+ return lightOption < 0 ? 100 : lightOption;
1462
+ }
1463
+ if (availables.length === 1) {
1464
+ return availables[0];
1465
+ }
1466
+ return darkOption < 0 ? 0 : darkOption;
1467
+ }
1468
+ }
1469
+ }
1470
+ const highestSurface$1 = (context, colorService) => {
1471
+ if (colorService instanceof ColorApi) {
1472
+ return context.isDark ? colorService.get("surfaceBright") : colorService.get("surfaceDim");
1473
+ } else {
1474
+ return context.isDark ? colorService.get("surfaceBright") : colorService.get("surfaceDim");
1475
+ }
1476
+ };
1477
+ const defaultColors = ({
1478
+ colors,
1479
+ context: c,
1480
+ palettes
1481
+ }) => {
1482
+ const getColor = (key) => {
1483
+ return colors.get(key);
1484
+ };
1485
+ return {
1486
+ ////////////////////////////////////////////////////////////////
1487
+ // Surfaces [S] //
1488
+ ////////////////////////////////////////////////////////////////
1489
+ surface: {
1490
+ palette: () => palettes.get("neutral"),
1491
+ tone: () => {
1492
+ if (c.isDark) {
1493
+ return 4;
1494
+ } else {
1495
+ if (Hct.isYellow(palettes.get("neutral").hue)) {
1496
+ return 99;
1497
+ } else if (c.variant.name === "vibrant") {
1498
+ return 97;
1499
+ } else {
1500
+ return 98;
1501
+ }
1502
+ }
1503
+ },
1504
+ isBackground: true
1505
+ },
1506
+ surfaceDim: {
1507
+ palette: () => palettes.get("neutral"),
1508
+ tone: () => {
1509
+ if (c.isDark) {
1510
+ return 4;
1511
+ } else {
1512
+ if (Hct.isYellow(palettes.get("neutral").hue)) {
1513
+ return 90;
1514
+ } else if (c.variant.name === "vibrant") {
1515
+ return 85;
1516
+ } else {
1517
+ return 87;
1518
+ }
1519
+ }
1520
+ },
1521
+ isBackground: true,
1522
+ chromaMultiplier: () => {
1523
+ if (!c.isDark) {
1524
+ if (c.variant.name === "neutral") {
1525
+ return 2.5;
1526
+ } else if (c.variant.name === "tonalSpot") {
1527
+ return 1.7;
1528
+ } else if (c.variant.name === "expressive") {
1529
+ return Hct.isYellow(palettes.get("neutral").hue) ? 2.7 : 1.75;
1530
+ } else if (c.variant.name === "vibrant") {
1531
+ return 1.36;
1532
+ }
1533
+ }
1534
+ return 1;
1535
+ }
1536
+ },
1537
+ surfaceBright: {
1538
+ palette: () => palettes.get("neutral"),
1539
+ tone: () => {
1540
+ if (c.isDark) {
1541
+ return 18;
1542
+ } else {
1543
+ if (Hct.isYellow(palettes.get("neutral").hue)) {
1544
+ return 99;
1545
+ } else if (c.variant.name === "vibrant") {
1546
+ return 97;
1547
+ } else {
1548
+ return 98;
1549
+ }
1550
+ }
1551
+ },
1552
+ isBackground: true,
1553
+ chromaMultiplier: () => {
1554
+ if (c.isDark) {
1555
+ if (c.variant.name === "neutral") {
1556
+ return 2.5;
1557
+ } else if (c.variant.name === "tonalSpot") {
1558
+ return 1.7;
1559
+ } else if (c.variant.name === "expressive") {
1560
+ return Hct.isYellow(palettes.get("neutral").hue) ? 2.7 : 1.75;
1561
+ } else if (c.variant.name === "vibrant") {
1562
+ return 1.36;
1563
+ }
1564
+ }
1565
+ return 1;
1566
+ }
1567
+ },
1568
+ surfaceContainerLowest: {
1569
+ palette: () => palettes.get("neutral"),
1570
+ tone: () => c.isDark ? 0 : 100,
1571
+ isBackground: true
1572
+ },
1573
+ surfaceContainerLow: {
1574
+ palette: () => palettes.get("neutral"),
1575
+ tone: () => {
1576
+ if (c.isDark) {
1577
+ return 6;
1578
+ } else {
1579
+ if (Hct.isYellow(palettes.get("neutral").hue)) {
1580
+ return 98;
1581
+ } else if (c.variant.name === "vibrant") {
1582
+ return 95;
1583
+ } else {
1584
+ return 96;
1585
+ }
1586
+ }
1587
+ },
1588
+ isBackground: true,
1589
+ chromaMultiplier: () => {
1590
+ if (c.variant.name === "neutral") {
1591
+ return 1.3;
1592
+ } else if (c.variant.name === "tonalSpot") {
1593
+ return 1.25;
1594
+ } else if (c.variant.name === "expressive") {
1595
+ return Hct.isYellow(palettes.get("neutral").hue) ? 1.3 : 1.15;
1596
+ } else if (c.variant.name === "vibrant") {
1597
+ return 1.08;
1598
+ }
1599
+ return 1;
1600
+ }
1601
+ },
1602
+ surfaceContainer: {
1603
+ palette: () => palettes.get("neutral"),
1604
+ tone: () => {
1605
+ if (c.isDark) {
1606
+ return 9;
1607
+ } else {
1608
+ if (Hct.isYellow(palettes.get("neutral").hue)) {
1609
+ return 96;
1610
+ } else if (c.variant.name === "vibrant") {
1611
+ return 92;
1612
+ } else {
1613
+ return 94;
1614
+ }
1615
+ }
1616
+ },
1617
+ isBackground: true,
1618
+ chromaMultiplier: () => {
1619
+ if (c.variant.name === "neutral") {
1620
+ return 1.6;
1621
+ } else if (c.variant.name === "tonalSpot") {
1622
+ return 1.4;
1623
+ } else if (c.variant.name === "expressive") {
1624
+ return Hct.isYellow(palettes.get("neutral").hue) ? 1.6 : 1.3;
1625
+ } else if (c.variant.name === "vibrant") {
1626
+ return 1.15;
1627
+ }
1628
+ return 1;
1629
+ }
1630
+ },
1631
+ surfaceContainerHigh: {
1632
+ palette: () => palettes.get("neutral"),
1633
+ tone: () => {
1634
+ if (c.isDark) {
1635
+ return 12;
1636
+ } else {
1637
+ if (Hct.isYellow(palettes.get("neutral").hue)) {
1638
+ return 94;
1639
+ } else if (c.variant.name === "vibrant") {
1640
+ return 90;
1641
+ } else {
1642
+ return 92;
1643
+ }
1644
+ }
1645
+ },
1646
+ isBackground: true,
1647
+ chromaMultiplier: () => {
1648
+ if (c.variant.name === "neutral") {
1649
+ return 1.9;
1650
+ } else if (c.variant.name === "tonalSpot") {
1651
+ return 1.5;
1652
+ } else if (c.variant.name === "expressive") {
1653
+ return Hct.isYellow(palettes.get("neutral").hue) ? 1.95 : 1.45;
1654
+ } else if (c.variant.name === "vibrant") {
1655
+ return 1.22;
1656
+ }
1657
+ return 1;
1658
+ }
1659
+ },
1660
+ surfaceContainerHighest: {
1661
+ palette: () => palettes.get("neutral"),
1662
+ tone: () => {
1663
+ if (c.isDark) {
1664
+ return 15;
1665
+ } else {
1666
+ if (Hct.isYellow(palettes.get("neutral").hue)) {
1667
+ return 92;
1668
+ } else if (c.variant.name === "vibrant") {
1669
+ return 88;
1670
+ } else {
1671
+ return 90;
1672
+ }
1673
+ }
1674
+ },
1675
+ isBackground: true,
1676
+ chromaMultiplier: () => {
1677
+ if (c.variant.name === "neutral") {
1678
+ return 2.2;
1679
+ } else if (c.variant.name === "tonalSpot") {
1680
+ return 1.7;
1681
+ } else if (c.variant.name === "expressive") {
1682
+ return Hct.isYellow(palettes.get("neutral").hue) ? 2.3 : 1.6;
1683
+ } else if (c.variant.name === "vibrant") {
1684
+ return 1.29;
1685
+ } else {
1686
+ return 1;
1687
+ }
1688
+ }
1689
+ },
1690
+ onSurface: {
1691
+ palette: () => palettes.get("neutral"),
1692
+ tone: () => {
1693
+ if (c.variant.name === "vibrant") {
1694
+ return tMaxC(palettes.get("neutral"), 0, 100, 1.1);
1695
+ } else {
1696
+ return getInitialToneFromBackground(highestSurface$1(c, colors));
1697
+ }
1698
+ },
1699
+ chromaMultiplier: () => {
1700
+ if (c.variant.name === "neutral") {
1701
+ return 2.2;
1702
+ } else if (c.variant.name === "tonalSpot") {
1703
+ return 1.7;
1704
+ } else if (c.variant.name === "expressive") {
1705
+ return Hct.isYellow(palettes.get("neutral").hue) ? c.isDark ? 3 : 2.3 : 1.6;
1706
+ }
1707
+ return 1;
1708
+ },
1709
+ background: () => highestSurface$1(c, colors),
1710
+ contrastCurve: () => c.isDark ? getCurve(11) : getCurve(9)
1711
+ },
1712
+ onSurfaceVariant: {
1713
+ palette: () => palettes.get("neutralVariant"),
1714
+ chromaMultiplier: () => {
1715
+ if (c.variant.name === "neutral") {
1716
+ return 2.2;
1717
+ } else if (c.variant.name === "tonalSpot") {
1718
+ return 1.7;
1719
+ } else if (c.variant.name === "expressive") {
1720
+ return Hct.isYellow(palettes.get("neutral").hue) ? c.isDark ? 3 : 2.3 : 1.6;
1721
+ }
1722
+ return 1;
1723
+ },
1724
+ background: () => highestSurface$1(c, colors),
1725
+ contrastCurve: () => c.isDark ? getCurve(6) : getCurve(4.5)
1726
+ },
1727
+ outline: {
1728
+ palette: () => palettes.get("neutralVariant"),
1729
+ chromaMultiplier: () => {
1730
+ if (c.variant.name === "neutral") {
1731
+ return 2.2;
1732
+ } else if (c.variant.name === "tonalSpot") {
1733
+ return 1.7;
1734
+ } else if (c.variant.name === "expressive") {
1735
+ return Hct.isYellow(palettes.get("neutral").hue) ? c.isDark ? 3 : 2.3 : 1.6;
1736
+ }
1737
+ return 1;
1738
+ },
1739
+ background: () => highestSurface$1(c, colors),
1740
+ contrastCurve: () => getCurve(3)
1741
+ },
1742
+ outlineVariant: {
1743
+ palette: () => palettes.get("neutralVariant"),
1744
+ chromaMultiplier: () => {
1745
+ if (c.variant.name === "neutral") {
1746
+ return 2.2;
1747
+ } else if (c.variant.name === "tonalSpot") {
1748
+ return 1.7;
1749
+ } else if (c.variant.name === "expressive") {
1750
+ return Hct.isYellow(palettes.get("neutral").hue) ? c.isDark ? 3 : 2.3 : 1.6;
1751
+ }
1752
+ return 1;
1753
+ },
1754
+ background: () => highestSurface$1(c, colors),
1755
+ contrastCurve: () => getCurve(1.5)
1756
+ },
1757
+ inverseSurface: {
1758
+ palette: () => palettes.get("neutral"),
1759
+ tone: () => c.isDark ? 98 : 4,
1760
+ isBackground: true
1761
+ },
1762
+ inverseOnSurface: {
1763
+ palette: () => palettes.get("neutral"),
1764
+ tone: () => c.isDark ? 20 : 95,
1765
+ background: () => colors.get("inverseSurface"),
1766
+ contrastCurve: () => getCurve(7)
1767
+ },
1768
+ ////////////////////////////////////////////////////////////////
1769
+ // Primaries [P] //
1770
+ ////////////////////////////////////////////////////////////////
1771
+ primary: {
1772
+ palette: () => palettes.get("primary"),
1773
+ tone: () => {
1774
+ if (c.variant.name === "neutral") {
1775
+ return c.isDark ? 80 : 40;
1776
+ } else if (c.variant.name === "tonalSpot") {
1777
+ if (c.isDark) {
1778
+ return 80;
1779
+ } else {
1780
+ return tMaxC(palettes.get("primary"));
1781
+ }
1782
+ } else if (c.variant.name === "expressive") {
1783
+ return tMaxC(
1784
+ palettes.get("primary"),
1785
+ 0,
1786
+ Hct.isYellow(palettes.get("primary").hue) ? 25 : Hct.isCyan(palettes.get("primary").hue) ? 88 : 98
1787
+ );
1788
+ } else {
1789
+ return tMaxC(
1790
+ palettes.get("primary"),
1791
+ 0,
1792
+ Hct.isCyan(palettes.get("primary").hue) ? 88 : 98
1793
+ );
1794
+ }
1795
+ },
1796
+ isBackground: true,
1797
+ background: () => highestSurface$1(c, colors),
1798
+ contrastCurve: () => getCurve(4.5),
1799
+ adjustTone: () => toneDeltaPair(
1800
+ colors.get("primaryContainer"),
1801
+ colors.get("primary"),
1802
+ 5,
1803
+ "relative_lighter",
1804
+ true,
1805
+ "farther"
1806
+ )
1807
+ },
1808
+ primaryDim: {
1809
+ palette: () => palettes.get("primary"),
1810
+ tone: () => {
1811
+ if (c.variant.name === "neutral") {
1812
+ return 85;
1813
+ } else if (c.variant.name === "tonalSpot") {
1814
+ return tMaxC(palettes.get("primary"), 0, 90);
1815
+ } else {
1816
+ return tMaxC(palettes.get("primary"));
1817
+ }
1818
+ },
1819
+ isBackground: true,
1820
+ background: () => getColor("surfaceContainerHigh"),
1821
+ contrastCurve: () => getCurve(4.5),
1822
+ adjustTone: () => toneDeltaPair(
1823
+ colors.get("primaryDim"),
1824
+ colors.get("primary"),
1825
+ 5,
1826
+ "darker",
1827
+ true,
1828
+ "farther"
1829
+ )
1830
+ },
1831
+ onPrimary: {
1832
+ palette: () => palettes.get("primary"),
1833
+ background: () => colors.get("primary"),
1834
+ contrastCurve: () => getCurve(6)
1835
+ },
1836
+ primaryContainer: {
1837
+ palette: () => palettes.get("primary"),
1838
+ tone: () => {
1839
+ if (c.variant.name === "neutral") {
1840
+ return c.isDark ? 30 : 90;
1841
+ } else if (c.variant.name === "tonalSpot") {
1842
+ return c.isDark ? tMinC(palettes.get("primary"), 35, 93) : tMaxC(palettes.get("primary"), 0, 90);
1843
+ } else if (c.variant.name === "expressive") {
1844
+ return c.isDark ? tMaxC(palettes.get("primary"), 30, 93) : tMaxC(
1845
+ palettes.get("primary"),
1846
+ 78,
1847
+ Hct.isCyan(palettes.get("primary").hue) ? 88 : 90
1848
+ );
1849
+ }
1850
+ return c.isDark ? tMinC(palettes.get("primary"), 66, 93) : tMaxC(
1851
+ palettes.get("primary"),
1852
+ 66,
1853
+ Hct.isCyan(palettes.get("primary").hue) ? 88 : 93
1854
+ );
1855
+ },
1856
+ isBackground: true,
1857
+ background: () => highestSurface$1(c, colors),
1858
+ contrastCurve: () => c.contrastLevel > 0 ? getCurve(1.5) : void 0
1859
+ },
1860
+ onPrimaryContainer: {
1861
+ palette: () => palettes.get("primary"),
1862
+ background: () => colors.get("primaryContainer"),
1863
+ contrastCurve: () => getCurve(6)
1864
+ },
1865
+ primaryFixed: {
1866
+ palette: () => palettes.get("primary"),
1867
+ tone: () => {
1868
+ return c.temp(
1869
+ {
1870
+ isDark: false,
1871
+ contrastLevel: 0
1872
+ },
1873
+ () => {
1874
+ const color = getColor("primaryContainer");
1875
+ return color.getTone();
1876
+ }
1877
+ );
1878
+ },
1879
+ isBackground: true,
1880
+ background: () => highestSurface$1(c, colors),
1881
+ contrastCurve: () => c.contrastLevel > 0 ? getCurve(1.5) : void 0
1882
+ },
1883
+ primaryFixedDim: {
1884
+ palette: () => palettes.get("primary"),
1885
+ tone: () => colors.get("primaryFixed").getTone(),
1886
+ isBackground: true,
1887
+ adjustTone: () => toneDeltaPair(
1888
+ getColor("primaryFixedDim"),
1889
+ getColor("primaryFixed"),
1890
+ 5,
1891
+ "darker",
1892
+ true,
1893
+ "exact"
1894
+ )
1895
+ },
1896
+ onPrimaryFixed: {
1897
+ palette: () => palettes.get("primary"),
1898
+ background: () => colors.get("primaryFixedDim"),
1899
+ contrastCurve: () => getCurve(7)
1900
+ },
1901
+ onPrimaryFixedVariant: {
1902
+ palette: () => palettes.get("primary"),
1903
+ background: () => colors.get("primaryFixedDim"),
1904
+ contrastCurve: () => getCurve(4.5)
1905
+ },
1906
+ inversePrimary: {
1907
+ palette: () => palettes.get("primary"),
1908
+ tone: () => tMaxC(palettes.get("primary")),
1909
+ background: () => colors.get("inverseSurface"),
1910
+ contrastCurve: () => getCurve(6)
1911
+ },
1912
+ ////////////////////////////////////////////////////////////////
1913
+ // Secondaries [Q] //
1914
+ ////////////////////////////////////////////////////////////////
1915
+ secondary: {
1916
+ palette: () => palettes.get("secondary"),
1917
+ tone: () => {
1918
+ if (c.variant.name === "neutral") {
1919
+ return c.isDark ? tMinC(palettes.get("secondary"), 0, 98) : tMaxC(palettes.get("secondary"));
1920
+ } else if (c.variant.name === "vibrant") {
1921
+ return tMaxC(palettes.get("secondary"), 0, c.isDark ? 90 : 98);
1922
+ } else {
1923
+ return c.isDark ? 80 : tMaxC(palettes.get("secondary"));
1924
+ }
1925
+ },
1926
+ isBackground: true,
1927
+ background: () => highestSurface$1(c, colors),
1928
+ contrastCurve: () => getCurve(4.5),
1929
+ adjustTone: () => toneDeltaPair(
1930
+ getColor("secondaryContainer"),
1931
+ getColor("secondary"),
1932
+ 5,
1933
+ "relative_lighter",
1934
+ true,
1935
+ "farther"
1936
+ )
1937
+ },
1938
+ secondaryDim: {
1939
+ palette: () => palettes.get("secondary"),
1940
+ tone: () => {
1941
+ if (c.variant.name === "neutral") {
1942
+ return 85;
1943
+ } else {
1944
+ return tMaxC(palettes.get("secondary"), 0, 90);
1945
+ }
1946
+ },
1947
+ isBackground: true,
1948
+ background: () => getColor("surfaceContainerHigh"),
1949
+ contrastCurve: () => getCurve(4.5),
1950
+ adjustTone: () => toneDeltaPair(
1951
+ getColor("secondaryDim"),
1952
+ getColor("secondary"),
1953
+ 5,
1954
+ "darker",
1955
+ true,
1956
+ "farther"
1957
+ )
1958
+ },
1959
+ onSecondary: {
1960
+ palette: () => palettes.get("secondary"),
1961
+ background: () => getColor("secondary"),
1962
+ contrastCurve: () => getCurve(6)
1963
+ },
1964
+ secondaryContainer: {
1965
+ palette: () => palettes.get("secondary"),
1966
+ tone: () => {
1967
+ if (c.variant.name === "vibrant") {
1968
+ return c.isDark ? tMinC(palettes.get("secondary"), 30, 40) : tMaxC(palettes.get("secondary"), 84, 90);
1969
+ } else if (c.variant.name === "expressive") {
1970
+ return c.isDark ? 15 : tMaxC(palettes.get("secondary"), 90, 95);
1971
+ } else {
1972
+ return c.isDark ? 25 : 90;
1973
+ }
1974
+ },
1975
+ isBackground: true,
1976
+ background: () => highestSurface$1(c, colors),
1977
+ adjustTone: () => void 0,
1978
+ contrastCurve: () => c.contrastLevel > 0 ? getCurve(1.5) : void 0
1979
+ },
1980
+ onSecondaryContainer: {
1981
+ palette: () => palettes.get("secondary"),
1982
+ background: () => getColor("secondaryContainer"),
1983
+ contrastCurve: () => getCurve(6)
1984
+ },
1985
+ secondaryFixed: {
1986
+ palette: () => palettes.get("secondary"),
1987
+ tone: () => {
1988
+ return c.temp(
1989
+ {
1990
+ isDark: false,
1991
+ contrastLevel: 0
1992
+ },
1993
+ () => {
1994
+ const color = getColor("secondaryContainer");
1995
+ return color.getTone();
1996
+ }
1997
+ );
1998
+ },
1999
+ isBackground: true,
2000
+ background: () => highestSurface$1(c, colors),
2001
+ contrastCurve: () => c.contrastLevel > 0 ? getCurve(1.5) : void 0
2002
+ },
2003
+ secondaryFixedDim: {
2004
+ palette: () => palettes.get("secondary"),
2005
+ tone: () => getColor("secondaryFixed").getTone(),
2006
+ isBackground: true,
2007
+ adjustTone: () => toneDeltaPair(
2008
+ getColor("secondaryFixedDim"),
2009
+ getColor("secondaryFixed"),
2010
+ 5,
2011
+ "darker",
2012
+ true,
2013
+ "exact"
2014
+ )
2015
+ },
2016
+ onSecondaryFixed: {
2017
+ palette: () => palettes.get("secondary"),
2018
+ background: () => getColor("secondaryFixedDim"),
2019
+ contrastCurve: () => getCurve(7)
2020
+ },
2021
+ onSecondaryFixedVariant: {
2022
+ palette: () => palettes.get("secondary"),
2023
+ background: () => getColor("secondaryFixedDim"),
2024
+ contrastCurve: () => getCurve(4.5)
2025
+ },
2026
+ ////////////////////////////////////////////////////////////////
2027
+ // Tertiaries [T] //
2028
+ ////////////////////////////////////////////////////////////////
2029
+ tertiary: {
2030
+ palette: () => palettes.get("tertiary"),
2031
+ tone: () => {
2032
+ if (c.variant.name === "expressive" || c.variant.name === "vibrant") {
2033
+ return tMaxC(
2034
+ palettes.get("tertiary"),
2035
+ 0,
2036
+ Hct.isCyan(palettes.get("tertiary").hue) ? 88 : c.isDark ? 98 : 100
2037
+ );
2038
+ } else {
2039
+ return c.isDark ? tMaxC(palettes.get("tertiary"), 0, 98) : tMaxC(palettes.get("tertiary"));
2040
+ }
2041
+ },
2042
+ isBackground: true,
2043
+ background: () => highestSurface$1(c, colors),
2044
+ contrastCurve: () => getCurve(4.5),
2045
+ adjustTone: () => toneDeltaPair(
2046
+ getColor("tertiaryContainer"),
2047
+ getColor("tertiary"),
2048
+ 5,
2049
+ "relative_lighter",
2050
+ true,
2051
+ "farther"
2052
+ )
2053
+ },
2054
+ tertiaryDim: {
2055
+ palette: () => palettes.get("tertiary"),
2056
+ tone: () => {
2057
+ if (c.variant.name === "tonalSpot") {
2058
+ return tMaxC(palettes.get("tertiary"), 0, 90);
2059
+ } else {
2060
+ return tMaxC(palettes.get("tertiary"));
2061
+ }
2062
+ },
2063
+ isBackground: true,
2064
+ background: () => getColor("surfaceContainerHigh"),
2065
+ contrastCurve: () => getCurve(4.5),
2066
+ adjustTone: () => toneDeltaPair(
2067
+ getColor("tertiaryDim"),
2068
+ getColor("tertiary"),
2069
+ 5,
2070
+ "darker",
2071
+ true,
2072
+ "farther"
2073
+ )
2074
+ },
2075
+ onTertiary: {
2076
+ palette: () => palettes.get("tertiary"),
2077
+ background: () => getColor("tertiary"),
2078
+ contrastCurve: () => getCurve(6)
2079
+ },
2080
+ tertiaryContainer: {
2081
+ palette: () => palettes.get("tertiary"),
2082
+ tone: () => {
2083
+ if (c.variant.name === "neutral") {
2084
+ return c.isDark ? tMaxC(palettes.get("tertiary"), 0, 93) : tMaxC(palettes.get("tertiary"), 0, 96);
2085
+ } else if (c.variant.name === "tonalSpot") {
2086
+ return tMaxC(palettes.get("tertiary"), 0, c.isDark ? 93 : 100);
2087
+ } else if (c.variant.name === "expressive") {
2088
+ return tMaxC(
2089
+ palettes.get("tertiary"),
2090
+ 75,
2091
+ Hct.isCyan(palettes.get("tertiary").hue) ? 88 : c.isDark ? 93 : 100
2092
+ );
2093
+ } else {
2094
+ return c.isDark ? tMaxC(palettes.get("tertiary"), 0, 93) : tMaxC(palettes.get("tertiary"), 72, 100);
2095
+ }
2096
+ },
2097
+ isBackground: true,
2098
+ background: () => highestSurface$1(c, colors),
2099
+ adjustTone: () => void 0,
2100
+ contrastCurve: () => c.contrastLevel > 0 ? getCurve(1.5) : void 0
2101
+ },
2102
+ onTertiaryContainer: {
2103
+ palette: () => palettes.get("tertiary"),
2104
+ background: () => getColor("tertiaryContainer"),
2105
+ contrastCurve: () => getCurve(6)
2106
+ },
2107
+ tertiaryFixed: {
2108
+ palette: () => palettes.get("tertiary"),
2109
+ tone: () => {
2110
+ return c.temp(
2111
+ {
2112
+ isDark: false,
2113
+ contrastLevel: 0
2114
+ },
2115
+ () => {
2116
+ const color = getColor("tertiaryContainer");
2117
+ return color.getTone();
2118
+ }
2119
+ );
2120
+ },
2121
+ isBackground: true,
2122
+ background: () => highestSurface$1(c, colors),
2123
+ contrastCurve: () => c.contrastLevel > 0 ? getCurve(1.5) : void 0
2124
+ },
2125
+ tertiaryFixedDim: {
2126
+ palette: () => palettes.get("tertiary"),
2127
+ tone: () => getColor("tertiaryFixed").getTone(),
2128
+ isBackground: true,
2129
+ adjustTone: () => toneDeltaPair(
2130
+ getColor("tertiaryFixedDim"),
2131
+ getColor("tertiaryFixed"),
2132
+ 5,
2133
+ "darker",
2134
+ true,
2135
+ "exact"
2136
+ )
2137
+ },
2138
+ onTertiaryFixed: {
2139
+ palette: () => palettes.get("tertiary"),
2140
+ background: () => getColor("tertiaryFixedDim"),
2141
+ contrastCurve: () => getCurve(7)
2142
+ },
2143
+ onTertiaryFixedVariant: {
2144
+ palette: () => palettes.get("tertiary"),
2145
+ background: () => getColor("tertiaryFixedDim"),
2146
+ contrastCurve: () => getCurve(4.5)
2147
+ },
2148
+ ////////////////////////////////////////////////////////////////
2149
+ // Errors [E] //
2150
+ ////////////////////////////////////////////////////////////////
2151
+ error: {
2152
+ palette: () => palettes.get("error"),
2153
+ tone: () => {
2154
+ return c.isDark ? tMinC(palettes.get("error"), 0, 98) : tMaxC(palettes.get("error"));
2155
+ },
2156
+ isBackground: true,
2157
+ background: () => highestSurface$1(c, colors),
2158
+ contrastCurve: () => getCurve(4.5),
2159
+ adjustTone: () => toneDeltaPair(
2160
+ colors.get("errorContainer"),
2161
+ colors.get("error"),
2162
+ 5,
2163
+ "relative_lighter",
2164
+ true,
2165
+ "farther"
2166
+ )
2167
+ },
2168
+ errorDim: {
2169
+ palette: () => palettes.get("error"),
2170
+ tone: () => tMinC(palettes.get("error")),
2171
+ isBackground: true,
2172
+ background: () => getColor("surfaceContainerHigh"),
2173
+ contrastCurve: () => getCurve(4.5),
2174
+ adjustTone: () => toneDeltaPair(
2175
+ getColor("errorDim"),
2176
+ getColor("error"),
2177
+ 5,
2178
+ "darker",
2179
+ true,
2180
+ "farther"
2181
+ )
2182
+ },
2183
+ onError: {
2184
+ palette: () => palettes.get("error"),
2185
+ background: () => colors.get("error"),
2186
+ contrastCurve: () => getCurve(6)
2187
+ },
2188
+ errorContainer: {
2189
+ palette: () => palettes.get("error"),
2190
+ tone: () => {
2191
+ return c.isDark ? tMinC(palettes.get("error"), 30, 93) : tMaxC(palettes.get("error"), 0, 90);
2192
+ },
2193
+ isBackground: true,
2194
+ background: () => highestSurface$1(c, colors),
2195
+ adjustTone: () => void 0,
2196
+ contrastCurve: () => c.contrastLevel > 0 ? getCurve(1.5) : void 0
2197
+ },
2198
+ onErrorContainer: {
2199
+ palette: () => palettes.get("error"),
2200
+ background: () => colors.get("errorContainer"),
2201
+ contrastCurve: () => getCurve(4.5)
2202
+ },
2203
+ /////////////////////////////////////////////////////////////////
2204
+ // Remapped Colors //
2205
+ /////////////////////////////////////////////////////////////////
2206
+ surfaceVariant: {
2207
+ alias: "surfaceContainerHighest"
2208
+ },
2209
+ surfaceTint: {
2210
+ alias: "primary"
2211
+ },
2212
+ background: {
2213
+ alias: "surface"
2214
+ },
2215
+ onBackground: {
2216
+ alias: "onSurface"
2217
+ }
2218
+ };
2219
+ };
2220
+ function capitalizeFirstLetter(string) {
2221
+ return string.charAt(0).toUpperCase() + string.slice(1);
2222
+ }
2223
+ class ColorApi {
2224
+ constructor({
2225
+ colorManager,
2226
+ context
2227
+ }) {
2228
+ __publicField(this, "colorManager");
2229
+ __publicField(this, "context");
2230
+ __publicField(this, "api");
2231
+ this.context = context;
2232
+ this.colorManager = colorManager;
2233
+ this.context.onUpdate((changed) => {
2234
+ if (changed.includes("variant")) {
2235
+ this.colorManager.clear();
2236
+ this.addColors(this.context.variant.colors);
2237
+ }
2238
+ });
2239
+ }
2240
+ getAll() {
2241
+ return this.colorManager.getAll();
2242
+ }
2243
+ addColor(key, color) {
2244
+ return this.colorManager.createOrUpdate(key, color);
2245
+ }
2246
+ addColors(args) {
2247
+ if (!this.api)
2248
+ throw new Error(
2249
+ "The API is not initialized. Please call bootstrap() before calling addColors()."
2250
+ );
2251
+ if (typeof args === "function") {
2252
+ args = args(this.api);
2253
+ }
2254
+ if (args) {
2255
+ Object.entries(args).forEach(([name, colorOption]) => {
2256
+ this.addColor(name, colorOption);
2257
+ });
2258
+ }
2259
+ }
2260
+ get(key) {
2261
+ return this.colorManager.get(key);
2262
+ }
2263
+ remove(key) {
2264
+ return this.colorManager.remove(key);
2265
+ }
2266
+ update(key, newColor) {
2267
+ return this.colorManager.createOrUpdate(key, newColor);
2268
+ }
2269
+ addFromCustomPalette(key) {
2270
+ if (this.context.variant.colorsFromCustomPalette) {
2271
+ return this.addColors(this.context.variant.colorsFromCustomPalette(key));
2272
+ }
2273
+ const colorKey = key;
2274
+ const colorDimKey = colorKey + "Dim";
2275
+ const ColorKey = capitalizeFirstLetter(key);
2276
+ const onColorKey = "on" + ColorKey;
2277
+ const colorContainerKey = colorKey + "Container";
2278
+ const onColorContainerKey = "on" + ColorKey + "Container";
2279
+ const colorFixedKey = colorKey + "Fixed";
2280
+ const colorFixedDimKey = colorKey + "FixedDim";
2281
+ const onColorFixedKey = "on" + ColorKey + "Fixed";
2282
+ const onColorFixedVariantKey = "on" + ColorKey + "FixedVariant";
2283
+ const colors = ({ palettes, colors: colors2, context: ctx }) => ({
2284
+ [colorKey]: {
2285
+ palette: () => palettes.get(colorKey),
2286
+ tone: () => {
2287
+ if (ctx.variant.name === "neutral") {
2288
+ return ctx.isDark ? tMinC(palettes.get(colorKey), 0, 98) : tMaxC(palettes.get(colorKey));
2289
+ } else if (ctx.variant.name === "vibrant") {
2290
+ return tMaxC(palettes.get(colorKey), 0, ctx.isDark ? 90 : 98);
2291
+ } else {
2292
+ return ctx.isDark ? 80 : tMaxC(palettes.get(colorKey));
2293
+ }
2294
+ },
2295
+ isBackground: true,
2296
+ background: () => highestSurface$1(ctx, this),
2297
+ contrastCurve: () => getCurve(4.5),
2298
+ adjustTone: () => toneDeltaPair(
2299
+ colors2.get(colorContainerKey),
2300
+ colors2.get(colorKey),
2301
+ 5,
2302
+ "relative_lighter",
2303
+ true,
2304
+ "farther"
2305
+ )
2306
+ },
2307
+ [colorDimKey]: {
2308
+ palette: () => palettes.get(colorKey),
2309
+ tone: () => {
2310
+ if (ctx.variant.name === "neutral") {
2311
+ return 85;
2312
+ } else {
2313
+ return tMaxC(palettes.get(colorKey), 0, 90);
2314
+ }
2315
+ },
2316
+ isBackground: true,
2317
+ background: () => this.get("surfaceContainerHigh"),
2318
+ contrastCurve: () => getCurve(4.5),
2319
+ adjustTone: () => toneDeltaPair(
2320
+ this.get(colorDimKey),
2321
+ this.get(colorKey),
2322
+ 5,
2323
+ "darker",
2324
+ true,
2325
+ "farther"
2326
+ )
2327
+ },
2328
+ [onColorKey]: {
2329
+ palette: () => palettes.get(colorKey),
2330
+ background: () => this.get(colorKey),
2331
+ contrastCurve: () => getCurve(6)
2332
+ },
2333
+ [colorContainerKey]: {
2334
+ palette: () => palettes.get(colorKey),
2335
+ tone: () => {
2336
+ if (ctx.variant.name === "vibrant") {
2337
+ return ctx.isDark ? tMinC(palettes.get(colorKey), 30, 40) : tMaxC(palettes.get(colorKey), 84, 90);
2338
+ } else if (ctx.variant.name === "expressive") {
2339
+ return ctx.isDark ? 15 : tMaxC(palettes.get(colorKey), 90, 95);
2340
+ } else {
2341
+ return ctx.isDark ? 25 : 90;
2342
+ }
2343
+ },
2344
+ isBackground: true,
2345
+ background: () => highestSurface$1(ctx, this),
2346
+ adjustTone: () => void 0,
2347
+ contrastCurve: () => ctx.contrastLevel > 0 ? getCurve(1.5) : void 0
2348
+ },
2349
+ [onColorContainerKey]: {
2350
+ palette: () => palettes.get(colorKey),
2351
+ background: () => this.get(colorContainerKey),
2352
+ contrastCurve: () => getCurve(6)
2353
+ },
2354
+ [colorFixedKey]: {
2355
+ palette: () => palettes.get(colorKey),
2356
+ tone: () => {
2357
+ return ctx.temp({ isDark: false, contrastLevel: 0 }, () => {
2358
+ const color = this.get(colorContainerKey);
2359
+ return color.getTone();
2360
+ });
2361
+ },
2362
+ isBackground: true,
2363
+ background: () => highestSurface$1(ctx, this),
2364
+ contrastCurve: () => ctx.contrastLevel > 0 ? getCurve(1.5) : void 0
2365
+ },
2366
+ [colorFixedDimKey]: {
2367
+ palette: () => palettes.get(colorKey),
2368
+ tone: () => this.get(colorFixedKey).getTone(),
2369
+ isBackground: true,
2370
+ adjustTone: () => toneDeltaPair(
2371
+ this.get(colorFixedDimKey),
2372
+ this.get(colorFixedKey),
2373
+ 5,
2374
+ "darker",
2375
+ true,
2376
+ "exact"
2377
+ )
2378
+ },
2379
+ [onColorFixedKey]: {
2380
+ palette: () => palettes.get(colorKey),
2381
+ background: () => this.get(colorFixedDimKey),
2382
+ contrastCurve: () => getCurve(7)
2383
+ },
2384
+ [onColorFixedVariantKey]: {
2385
+ palette: () => palettes.get(colorKey),
2386
+ background: () => this.get(colorFixedDimKey),
2387
+ contrastCurve: () => getCurve(4.5)
2388
+ }
2389
+ });
2390
+ this.addColors(colors);
2391
+ }
2392
+ }
2393
+ class ColorManager {
2394
+ constructor(args) {
2395
+ __publicField(this, "colorMap", /* @__PURE__ */ new Map());
2396
+ __publicField(this, "context");
2397
+ this.context = args.context;
2398
+ }
2399
+ createOrUpdate(key, args) {
2400
+ let colorEntity = this.colorMap.get(key);
2401
+ if ("alias" in args) {
2402
+ colorEntity = new ColorAlias(key, args.alias, this);
2403
+ } else if ("hex" in args) {
2404
+ colorEntity = new ColorFromHex(key, args.hex);
2405
+ } else {
2406
+ try {
2407
+ if (colorEntity instanceof ColorFromPalette) {
2408
+ colorEntity.update(args);
2409
+ } else {
2410
+ colorEntity = new ColorFromPalette(key, args, this.context);
2411
+ }
2412
+ } catch (e) {
2413
+ console.error(e);
2414
+ throw new Error(`Invalid color options provided for ${key}`);
2415
+ }
2416
+ }
2417
+ this.colorMap.set(key, colorEntity);
2418
+ return colorEntity;
2419
+ }
2420
+ remove(key) {
2421
+ return this.colorMap.delete(key);
2422
+ }
2423
+ clear() {
2424
+ this.colorMap.clear();
2425
+ }
2426
+ get(key) {
2427
+ const colorEntity = this.colorMap.get(key);
2428
+ if (colorEntity) {
2429
+ return colorEntity;
2430
+ } else {
2431
+ throw new Error(`Color ${key} does not exist`);
2432
+ }
2433
+ }
2434
+ getAll() {
2435
+ return this.colorMap;
2436
+ }
2437
+ }
2438
+ const ColorModule = {
2439
+ colorManager: asClass(ColorManager).singleton(),
2440
+ colorApi: asClass(ColorApi).singleton()
2441
+ };
2442
+ const AppModule = {
2443
+ api: asClass(API).singleton()
2444
+ };
2445
+ class PluginApi {
2446
+ constructor() {
2447
+ __publicField(this, "plugins", /* @__PURE__ */ new Map());
2448
+ }
2449
+ addPlugin(plugin) {
2450
+ this.plugins.set(plugin.name, plugin);
2451
+ }
2452
+ initPlugins(api) {
2453
+ const plugins = new Map(this.plugins);
2454
+ let size = 0;
2455
+ this.plugins = /* @__PURE__ */ new Map();
2456
+ do {
2457
+ size = plugins.size;
2458
+ plugins.forEach((plugin, key) => {
2459
+ const deps = plugin.dependencies.filter(
2460
+ (dep) => !this.plugins.has(new dep().name)
2461
+ );
2462
+ if (deps.length === 0) {
2463
+ this.plugins.set(plugin.name, plugin.init(api));
2464
+ plugins.delete(key);
2465
+ }
2466
+ });
2467
+ } while (plugins.size != 0 && plugins.size < size);
2468
+ if (plugins.size > 0)
2469
+ throw new Error(
2470
+ "Some plugins couldn't be loaded due to missing dependencies: " + Array.from(plugins.keys())
2471
+ );
2472
+ }
2473
+ async loadPlugins() {
2474
+ var _a, _b;
2475
+ for (const plugin of this.plugins.values()) {
2476
+ await ((_b = (_a = plugin.getInstance()).onLoad) == null ? void 0 : _b.call(_a));
2477
+ }
2478
+ }
2479
+ getPlugin(plugin) {
2480
+ const pluginInstance = this.plugins.get(new plugin().name);
2481
+ if (!pluginInstance) throw new Error(`Plugin ${plugin.name} not found`);
2482
+ return pluginInstance;
2483
+ }
2484
+ }
2485
+ const PluginModule = {
2486
+ pluginApi: asClass(PluginApi).singleton()
2487
+ };
2488
+ class Context {
2489
+ constructor() {
2490
+ __publicField(this, "_options");
2491
+ __publicField(this, "_temOptions", null);
2492
+ __publicField(this, "updateCallbacks", []);
2493
+ this.onUpdate((changed) => {
2494
+ if (changed.includes("variant")) {
2495
+ this.variant.init(this);
2496
+ }
2497
+ });
2498
+ }
2499
+ /**
2500
+ * Runs the provided callback with a proxied Context and records which Context
2501
+ * properties (getters) were accessed during its execution.
2502
+ *
2503
+ * This helps determine dependencies of the callback on the Context.
2504
+ *
2505
+ * Example usage:
2506
+ * const { result, dependencies } = Context.trackDependencies(ctx, (c) => cb(c));
2507
+ */
2508
+ static trackDependencies(context, callback) {
2509
+ const dependencies = /* @__PURE__ */ new Set();
2510
+ const isGetterOnContext = (prop) => {
2511
+ if (typeof prop !== "string") return false;
2512
+ const desc = Object.getOwnPropertyDescriptor(Context.prototype, prop);
2513
+ return !!desc && typeof desc.get === "function";
2514
+ };
2515
+ const proxy = new Proxy(context, {
2516
+ get(target, prop, receiver) {
2517
+ if (isGetterOnContext(prop)) {
2518
+ dependencies.add(prop);
2519
+ }
2520
+ return Reflect.get(target, prop, receiver);
2521
+ }
2522
+ });
2523
+ const result = callback(proxy);
2524
+ return { result, dependencies: Array.from(dependencies) };
2525
+ }
2526
+ set(options) {
2527
+ if (this._options) {
2528
+ console.error(this._options);
2529
+ throw new Error("Options already set");
2530
+ }
2531
+ if (typeof options.sourceColor === "string") {
2532
+ options.sourceColor = Hct.fromInt(argbFromHex(options.sourceColor));
2533
+ }
2534
+ const changed = [];
2535
+ for (const key of Object.keys(options)) {
2536
+ changed.push(key);
2537
+ }
2538
+ this._options = options;
2539
+ if (changed.length > 0) {
2540
+ this.updateCallbacks.forEach((callback) => callback(changed));
2541
+ }
2542
+ }
2543
+ update(args) {
2544
+ const options = this._options;
2545
+ if (!options) {
2546
+ throw new Error("Options not found");
2547
+ }
2548
+ if (typeof args.sourceColor === "string") {
2549
+ args.sourceColor = Hct.fromInt(argbFromHex(args.sourceColor));
2550
+ }
2551
+ const changed = [];
2552
+ for (const key of Object.keys(args)) {
2553
+ if (args[key] !== options[key]) {
2554
+ changed.push(key);
2555
+ }
2556
+ }
2557
+ this._options = {
2558
+ ...options,
2559
+ ...args
2560
+ };
2561
+ if (changed.length > 0) {
2562
+ this.updateCallbacks.forEach((callback) => callback(changed));
2563
+ }
2564
+ }
2565
+ getOptions() {
2566
+ let options;
2567
+ if (this._temOptions) {
2568
+ options = this._temOptions;
2569
+ } else {
2570
+ options = this._options;
2571
+ }
2572
+ if (!options) {
2573
+ throw new Error("Options not found");
2574
+ }
2575
+ return options;
2576
+ }
2577
+ set darkMode(isDark) {
2578
+ this.update({ isDark });
2579
+ }
2580
+ get isDark() {
2581
+ return this.getOptions().isDark;
2582
+ }
2583
+ set contrastLevel(contrastLevel) {
2584
+ this.update({ contrastLevel });
2585
+ }
2586
+ get contrastLevel() {
2587
+ return this.getOptions().contrastLevel;
2588
+ }
2589
+ set sourceColor(sourceColor) {
2590
+ this.update({ sourceColor });
2591
+ }
2592
+ get sourceColor() {
2593
+ let sourceColor = this.getOptions().sourceColor;
2594
+ if (typeof sourceColor === "string") {
2595
+ sourceColor = Hct.fromInt(argbFromHex(sourceColor));
2596
+ }
2597
+ return sourceColor;
2598
+ }
2599
+ set variant(variant2) {
2600
+ this.update({ variant: variant2 });
2601
+ }
2602
+ get variant() {
2603
+ return this.getOptions().variant;
2604
+ }
2605
+ temp(args, callback) {
2606
+ const previousOptions = this.getOptions();
2607
+ this._temOptions = {
2608
+ ...previousOptions,
2609
+ ...args
2610
+ };
2611
+ const result = callback();
2612
+ this._temOptions = null;
2613
+ return result;
2614
+ }
2615
+ onUpdate(callback) {
2616
+ this.updateCallbacks.push(callback);
2617
+ }
2618
+ }
2619
+ const ContextModule = {
2620
+ context: asClass(Context).singleton()
2621
+ };
2622
+ class Palette {
2623
+ constructor(name, callback, context) {
2624
+ __publicField(this, "cache", /* @__PURE__ */ new Map());
2625
+ __publicField(this, "hueCache", null);
2626
+ __publicField(this, "chromaCache", null);
2627
+ __publicField(this, "dependencies", null);
2628
+ this.name = name;
2629
+ this.callback = callback;
2630
+ this.context = context;
2631
+ this.update([]);
2632
+ }
2633
+ static fromVariant(name, color, ctx) {
2634
+ const callback = (context) => {
2635
+ return context.variant.customPalettes(context, color);
2636
+ };
2637
+ return new Palette(name, callback, ctx);
2638
+ }
2639
+ update(change) {
2640
+ let result = null;
2641
+ if (this.dependencies == null) {
2642
+ const trackDependencies = Context.trackDependencies(
2643
+ this.context,
2644
+ (ctx) => this.callback(ctx)
2645
+ );
2646
+ this.dependencies = trackDependencies.dependencies;
2647
+ result = trackDependencies.result;
2648
+ } else if (change.length > 0 && change.some((c) => {
2649
+ var _a;
2650
+ return (_a = this.dependencies) == null ? void 0 : _a.includes(c);
2651
+ })) {
2652
+ result = this.callback(this.context);
2653
+ }
2654
+ if (result && (this.hueCache !== result.hue || this.chromaCache !== result.chroma)) {
2655
+ this.clearCache();
2656
+ this.hueCache = result.hue;
2657
+ this.chromaCache = result.chroma;
2658
+ }
2659
+ }
2660
+ clearCache() {
2661
+ this.cache.clear();
2662
+ this.hueCache = null;
2663
+ this.chromaCache = null;
2664
+ }
2665
+ /**
2666
+ * @param tone HCT tone, measured from 0 to 100.
2667
+ * @return ARGB representation of a color with that tone.
2668
+ */
2669
+ tone(tone) {
2670
+ const hue = this.hueCache;
2671
+ const chroma = this.chromaCache;
2672
+ if (hue == null || chroma == null)
2673
+ throw new Error("Palette must be updated before using tone");
2674
+ let argb = this.cache.get(tone);
2675
+ if (argb === void 0) {
2676
+ if (tone == 99 && Hct.isYellow(hue)) {
2677
+ argb = this.averageArgb(this.tone(98), this.tone(100));
2678
+ } else {
2679
+ argb = Hct.from(hue, chroma, tone).toInt();
2680
+ }
2681
+ this.cache.set(tone, argb);
2682
+ }
2683
+ return argb;
2684
+ }
2685
+ /**
2686
+ * @param tone HCT tone.
2687
+ * @return HCT representation of a color with that tone.
2688
+ */
2689
+ getHct(tone) {
2690
+ return Hct.fromInt(this.tone(tone));
2691
+ }
2692
+ get hue() {
2693
+ const hue = this.hueCache;
2694
+ if (hue == null) {
2695
+ throw new Error(`Palette ${this.name} must be updated before using hue`);
2696
+ }
2697
+ return hue;
2698
+ }
2699
+ get chroma() {
2700
+ const chroma = this.chromaCache;
2701
+ if (chroma == null) {
2702
+ throw new Error(`Palette ${this.name} must be updated before using hue`);
2703
+ }
2704
+ return chroma;
2705
+ }
2706
+ averageArgb(argb1, argb2) {
2707
+ const red1 = argb1 >>> 16 & 255;
2708
+ const green1 = argb1 >>> 8 & 255;
2709
+ const blue1 = argb1 & 255;
2710
+ const red2 = argb2 >>> 16 & 255;
2711
+ const green2 = argb2 >>> 8 & 255;
2712
+ const blue2 = argb2 & 255;
2713
+ const red = Math.round((red1 + red2) / 2);
2714
+ const green = Math.round((green1 + green2) / 2);
2715
+ const blue = Math.round((blue1 + blue2) / 2);
2716
+ return (255 << 24 | (red & 255) << 16 | (green & 255) << 8 | blue & 255) >>> 0;
2717
+ }
2718
+ }
2719
+ class PaletteApi {
2720
+ constructor({ paletteManager }) {
2721
+ __publicField(this, "paletteManager");
2722
+ this.paletteManager = paletteManager;
2723
+ }
2724
+ add(args) {
2725
+ Object.entries(args).forEach(([key, callback]) => {
2726
+ if (typeof callback === "string") {
2727
+ this.paletteManager.addCustomPalette(
2728
+ key,
2729
+ Hct.fromInt(argbFromHex(callback))
2730
+ );
2731
+ } else {
2732
+ this.paletteManager.add(key, callback);
2733
+ }
2734
+ });
2735
+ }
2736
+ get(key) {
2737
+ return this.paletteManager.get(key);
2738
+ }
2739
+ getAll() {
2740
+ return this.paletteManager.palettes;
2741
+ }
2742
+ }
2743
+ class PaletteManager {
2744
+ constructor(args) {
2745
+ __publicField(this, "_palettes", {});
2746
+ __publicField(this, "context");
2747
+ __publicField(this, "colorApi");
2748
+ this.colorApi = args.colorApi;
2749
+ this.context = args.context;
2750
+ this.context.onUpdate(
2751
+ (changed) => Object.entries(this.palettes).forEach(([key, value]) => {
2752
+ value.update(changed);
2753
+ })
2754
+ );
2755
+ }
2756
+ get palettes() {
2757
+ return {
2758
+ ...this.context.variant.palettes,
2759
+ ...this._palettes
2760
+ };
2761
+ }
2762
+ addCustomPalette(key, color) {
2763
+ const palette = Palette.fromVariant(key, color, this.context);
2764
+ this.add(key, palette);
2765
+ this.colorApi.addFromCustomPalette(key);
2766
+ }
2767
+ add(key, palette) {
2768
+ if (this._palettes["key"]) {
2769
+ throw new Error(`Palette with key ${key} already exists`);
2770
+ }
2771
+ if (!(palette instanceof Palette))
2772
+ palette = new Palette(key, palette, this.context);
2773
+ this.set(key, palette);
2774
+ }
2775
+ get(key) {
2776
+ const palette = this.palettes[key];
2777
+ if (!palette) {
2778
+ throw new Error(`Palette ${key} not found`);
2779
+ }
2780
+ return palette;
2781
+ }
2782
+ set(key, palette) {
2783
+ this._palettes[key] = palette;
2784
+ }
2785
+ update(key, args) {
2786
+ if (!this.palettes["key"]) {
2787
+ throw new Error(`Palette with key ${key} not found`);
2788
+ }
2789
+ if (!(args instanceof Palette)) {
2790
+ args = new Palette(key, args, this.context);
2791
+ }
2792
+ this.set(key, args);
2793
+ }
2794
+ }
2795
+ const PaletteModule = {
2796
+ paletteApi: asClass(PaletteApi).singleton(),
2797
+ paletteManager: asClass(PaletteManager).singleton()
2798
+ };
2799
+ const AppContainer = () => {
2800
+ function registerModule(...modules) {
2801
+ modules.forEach((module) => {
2802
+ Object.entries(module).forEach(([name, moduleClass]) => {
2803
+ container.register(name, moduleClass);
2804
+ });
2805
+ });
2806
+ return AppContainer;
2807
+ }
2808
+ const container = createContainer({
2809
+ injectionMode: InjectionMode.PROXY
2810
+ });
2811
+ registerModule(
2812
+ AppModule,
2813
+ PluginModule,
2814
+ ColorModule,
2815
+ PaletteModule,
2816
+ ContextModule
2817
+ );
2818
+ return container;
2819
+ };
2820
+ function bootstrap() {
2821
+ return AppContainer().resolve("api");
2822
+ }
2823
+ const getPiecewiseHue = (sourceColor, hueBreakpoints, hues) => {
2824
+ const size = Math.min(hueBreakpoints.length - 1, hues.length);
2825
+ const sourceHue = sourceColor.hue;
2826
+ for (let i = 0; i < size; i++) {
2827
+ if (sourceHue >= hueBreakpoints[i] && sourceHue < hueBreakpoints[i + 1]) {
2828
+ return sanitizeDegreesDouble(hues[i]);
2829
+ }
2830
+ }
2831
+ return sourceHue;
2832
+ };
2833
+ const getRotatedHue = (sourceColor, hueBreakpoints, rotations) => {
2834
+ let rotation = getPiecewiseHue(sourceColor, hueBreakpoints, rotations);
2835
+ if (Math.min(hueBreakpoints.length - 1, rotations.length) <= 0) {
2836
+ rotation = 0;
2837
+ }
2838
+ return sanitizeDegreesDouble(sourceColor.hue + rotation);
2839
+ };
2840
+ class Variant {
2841
+ constructor(options) {
2842
+ __publicField(this, "_palettes");
2843
+ __publicField(this, "customPalettes");
2844
+ __publicField(this, "colorsFromCustomPalette");
2845
+ __publicField(this, "colors");
2846
+ __publicField(this, "name");
2847
+ __publicField(this, "context");
2848
+ this.options = options;
2849
+ this.customPalettes = options.customPalettes;
2850
+ this.colors = options.colors || {};
2851
+ this.name = options.name;
2852
+ this.colorsFromCustomPalette = options.colorsFromCustomPalette;
2853
+ }
2854
+ get palettes() {
2855
+ if (!this._palettes) {
2856
+ throw new Error("Variant not initialized");
2857
+ }
2858
+ return this._palettes;
2859
+ }
2860
+ init(context) {
2861
+ if (this.context) return;
2862
+ this.context = context;
2863
+ this._palettes = Object.entries(this.options.palettes).reduce(
2864
+ (acc, [key, callback]) => ({
2865
+ ...acc,
2866
+ [key]: new Palette(key, callback, context)
2867
+ }),
2868
+ {}
2869
+ );
2870
+ }
2871
+ }
2872
+ const variant = (args) => new Variant(args);
2873
+ const getExpressiveNeutralHue = (sourceColor) => {
2874
+ const hue = getRotatedHue(
2875
+ sourceColor,
2876
+ [0, 71, 124, 253, 278, 300, 360],
2877
+ [10, 0, 10, 0, 10, 0]
2878
+ );
2879
+ return hue;
2880
+ };
2881
+ const getExpressiveNeutralChroma = (sourceColor, isDark) => {
2882
+ const neutralHue = getExpressiveNeutralHue(sourceColor);
2883
+ return isDark ? Hct.isYellow(neutralHue) ? 6 : 14 : 18;
2884
+ };
2885
+ const expressiveVariant = variant({
2886
+ name: "expressive",
2887
+ palettes: {
2888
+ primary: ({ sourceColor, isDark }) => ({
2889
+ hue: sourceColor.hue,
2890
+ chroma: isDark ? 36 : 48
2891
+ }),
2892
+ secondary: ({ sourceColor, isDark }) => ({
2893
+ hue: getRotatedHue(
2894
+ sourceColor,
2895
+ [0, 105, 140, 204, 253, 278, 300, 333, 360],
2896
+ [-160, 155, -100, 96, -96, -156, -165, -160]
2897
+ ),
2898
+ chroma: isDark ? 16 : 24
2899
+ }),
2900
+ tertiary: ({ sourceColor }) => TonalPalette.fromHueAndChroma(
2901
+ getRotatedHue(
2902
+ sourceColor,
2903
+ [0, 105, 140, 204, 253, 278, 300, 333, 360],
2904
+ [-165, 160, -105, 101, -101, -160, -170, -165]
2905
+ ),
2906
+ 48
2907
+ ),
2908
+ neutral: ({ sourceColor, isDark }) => TonalPalette.fromHueAndChroma(
2909
+ getExpressiveNeutralHue(sourceColor),
2910
+ getExpressiveNeutralChroma(sourceColor, isDark)
2911
+ ),
2912
+ neutralVariant: ({ sourceColor, isDark }) => {
2913
+ const expressiveNeutralHue = getExpressiveNeutralHue(sourceColor);
2914
+ const expressiveNeutralChroma = getExpressiveNeutralChroma(
2915
+ sourceColor,
2916
+ isDark
2917
+ );
2918
+ return TonalPalette.fromHueAndChroma(
2919
+ expressiveNeutralHue,
2920
+ expressiveNeutralChroma * (expressiveNeutralHue >= 105 && expressiveNeutralHue < 125 ? 1.6 : 2.3)
2921
+ );
2922
+ },
2923
+ error: ({ sourceColor }) => {
2924
+ const errorHue = getPiecewiseHue(
2925
+ sourceColor,
2926
+ [0, 3, 13, 23, 33, 43, 153, 273, 360],
2927
+ [12, 22, 32, 12, 22, 32, 22, 12]
2928
+ );
2929
+ return TonalPalette.fromHueAndChroma(errorHue, 64);
2930
+ }
2931
+ },
2932
+ customPalettes: ({ isDark }, color) => TonalPalette.fromHueAndChroma(
2933
+ getRotatedHue(
2934
+ color,
2935
+ [0, 105, 140, 204, 253, 278, 300, 333, 360],
2936
+ [-160, 155, -100, 96, -96, -156, -165, -160]
2937
+ ),
2938
+ isDark ? 16 : 24
2939
+ ),
2940
+ colors: defaultColors
2941
+ });
2942
+ const neutralVariant = variant({
2943
+ name: "neutral",
2944
+ palettes: {
2945
+ primary: ({ sourceColor }) => TonalPalette.fromHueAndChroma(
2946
+ sourceColor.hue,
2947
+ Hct.isBlue(sourceColor.hue) ? 12 : 8
2948
+ ),
2949
+ secondary: ({ sourceColor }) => TonalPalette.fromHueAndChroma(
2950
+ sourceColor.hue,
2951
+ Hct.isBlue(sourceColor.hue) ? 6 : 4
2952
+ ),
2953
+ tertiary: ({ sourceColor }) => TonalPalette.fromHueAndChroma(
2954
+ getRotatedHue(
2955
+ sourceColor,
2956
+ [0, 38, 105, 161, 204, 278, 333, 360],
2957
+ [-32, 26, 10, -39, 24, -15, -32]
2958
+ ),
2959
+ 20
2960
+ ),
2961
+ neutral: ({ sourceColor }) => TonalPalette.fromHueAndChroma(sourceColor.hue, 1.4),
2962
+ neutralVariant: ({ sourceColor }) => TonalPalette.fromHueAndChroma(sourceColor.hue, 1.4 * 2.2),
2963
+ error: ({ sourceColor }) => {
2964
+ const errorHue = getPiecewiseHue(
2965
+ sourceColor,
2966
+ [0, 3, 13, 23, 33, 43, 153, 273, 360],
2967
+ [12, 22, 32, 12, 22, 32, 22, 12]
2968
+ );
2969
+ return TonalPalette.fromHueAndChroma(errorHue, 50);
2970
+ }
2971
+ },
2972
+ customPalettes: (_, colorHct) => TonalPalette.fromHueAndChroma(
2973
+ colorHct.hue,
2974
+ Hct.isBlue(colorHct.hue) ? 6 : 4
2975
+ ),
2976
+ colors: defaultColors
2977
+ });
2978
+ const tonalSpotVariant = variant({
2979
+ name: "tonalSpot",
2980
+ palettes: {
2981
+ primary: ({ sourceColor, isDark }) => TonalPalette.fromHueAndChroma(sourceColor.hue, isDark ? 26 : 32),
2982
+ secondary: ({ sourceColor }) => TonalPalette.fromHueAndChroma(sourceColor.hue, 16),
2983
+ tertiary: ({ sourceColor }) => TonalPalette.fromHueAndChroma(
2984
+ getRotatedHue(
2985
+ sourceColor,
2986
+ [0, 20, 71, 161, 333, 360],
2987
+ [-40, 48, -32, 40, -32]
2988
+ ),
2989
+ 28
2990
+ ),
2991
+ neutral: ({ sourceColor }) => TonalPalette.fromHueAndChroma(sourceColor.hue, 5),
2992
+ neutralVariant: ({ sourceColor }) => TonalPalette.fromHueAndChroma(sourceColor.hue, 5 * 1.7),
2993
+ error: ({ sourceColor }) => {
2994
+ const errorHue = getPiecewiseHue(
2995
+ sourceColor,
2996
+ [0, 3, 13, 23, 33, 43, 153, 273, 360],
2997
+ [12, 22, 32, 12, 22, 32, 22, 12]
2998
+ );
2999
+ return TonalPalette.fromHueAndChroma(errorHue, 60);
3000
+ }
3001
+ },
3002
+ customPalettes: (_, colorHct) => TonalPalette.fromHueAndChroma(colorHct.hue, 16),
3003
+ colors: defaultColors
3004
+ });
3005
+ const getVibrantNeutralHue = (sourceColor) => {
3006
+ return getRotatedHue(
3007
+ sourceColor,
3008
+ [0, 38, 105, 140, 333, 360],
3009
+ [-14, 10, -14, 10, -14]
3010
+ );
3011
+ };
3012
+ const getVibrantNeutralChroma = (sourceColor) => {
3013
+ return 28;
3014
+ };
3015
+ const vibrantVariant = variant({
3016
+ name: "vibrant",
3017
+ palettes: {
3018
+ primary: ({ sourceColor }) => TonalPalette.fromHueAndChroma(sourceColor.hue, 74),
3019
+ secondary: ({ sourceColor }) => TonalPalette.fromHueAndChroma(
3020
+ getRotatedHue(
3021
+ sourceColor,
3022
+ [0, 38, 105, 140, 333, 360],
3023
+ [-14, 10, -14, 10, -14]
3024
+ ),
3025
+ 56
3026
+ ),
3027
+ tertiary: ({ sourceColor }) => TonalPalette.fromHueAndChroma(
3028
+ getRotatedHue(
3029
+ sourceColor,
3030
+ [0, 38, 71, 105, 140, 161, 253, 333, 360],
3031
+ [-72, 35, 24, -24, 62, 50, 62, -72]
3032
+ ),
3033
+ 56
3034
+ ),
3035
+ neutral: ({ sourceColor }) => TonalPalette.fromHueAndChroma(
3036
+ getVibrantNeutralHue(sourceColor),
3037
+ getVibrantNeutralChroma()
3038
+ ),
3039
+ neutralVariant: ({ sourceColor }) => {
3040
+ const vibrantNeutralHue = getVibrantNeutralHue(sourceColor);
3041
+ const vibrantNeutralChroma = getVibrantNeutralChroma();
3042
+ return TonalPalette.fromHueAndChroma(
3043
+ vibrantNeutralHue,
3044
+ vibrantNeutralChroma * 1.29
3045
+ );
3046
+ },
3047
+ error: ({ sourceColor }) => {
3048
+ const errorHue = getPiecewiseHue(
3049
+ sourceColor,
3050
+ [0, 3, 13, 23, 33, 43, 153, 273, 360],
3051
+ [12, 22, 32, 12, 22, 32, 22, 12]
3052
+ );
3053
+ return TonalPalette.fromHueAndChroma(errorHue, 80);
3054
+ }
3055
+ },
3056
+ customPalettes: (_, colorHct) => TonalPalette.fromHueAndChroma(
3057
+ getRotatedHue(
3058
+ colorHct,
3059
+ [0, 38, 105, 140, 333, 360],
3060
+ [-14, 10, -14, 10, -14]
3061
+ ),
3062
+ 56
3063
+ ),
3064
+ colors: defaultColors
3065
+ });
3066
+ const surfaceContainerToneDelta = 2.5;
3067
+ const inverseTone = (tone) => {
3068
+ return 100 - tone;
3069
+ };
3070
+ const surfaceContainerTone = (layer, api) => {
3071
+ const t = surfaceContainerToneDelta * layer * (1 + api.context.contrastLevel);
3072
+ if (api.context.isDark) {
3073
+ return t * 1.5;
3074
+ } else {
3075
+ if (Hct.isYellow(api.palettes.get("neutral").hue)) {
3076
+ return 100 - t - surfaceContainerToneDelta;
3077
+ }
3078
+ return 100 - t;
3079
+ }
3080
+ };
3081
+ const highestSurface = (context, colorService) => {
3082
+ if (colorService instanceof ColorApi) {
3083
+ return colorService.get("surface");
3084
+ } else {
3085
+ return colorService.get("surface");
3086
+ }
3087
+ };
3088
+ const udixioVariant = variant({
3089
+ name: "udixio",
3090
+ palettes: {
3091
+ primary: ({ sourceColor }) => ({
3092
+ hue: sourceColor.hue,
3093
+ chroma: sourceColor.chroma
3094
+ }),
3095
+ secondary: ({ sourceColor }) => ({
3096
+ hue: sourceColor.hue,
3097
+ chroma: sourceColor.chroma / 1.4
3098
+ }),
3099
+ tertiary: ({ sourceColor }) => ({
3100
+ hue: getRotatedHue(
3101
+ sourceColor,
3102
+ [0, 20, 71, 161, 333, 360],
3103
+ [-40, 48, -32, 40, -32]
3104
+ ),
3105
+ chroma: sourceColor.chroma
3106
+ }),
3107
+ neutral: ({ sourceColor }) => {
3108
+ return {
3109
+ hue: sourceColor.hue,
3110
+ chroma: 5
3111
+ };
3112
+ },
3113
+ neutralVariant: ({ sourceColor }) => {
3114
+ const neutral = 5;
3115
+ return {
3116
+ hue: sourceColor.hue,
3117
+ chroma: neutral * 1.7
3118
+ };
3119
+ },
3120
+ error: ({ sourceColor }) => {
3121
+ const errorHue = getPiecewiseHue(
3122
+ sourceColor,
3123
+ [0, 3, 13, 23, 33, 43, 153, 273, 360],
3124
+ [12, 22, 32, 12, 22, 32, 22, 12]
3125
+ );
3126
+ return {
3127
+ hue: errorHue,
3128
+ chroma: 60
3129
+ };
3130
+ }
3131
+ },
3132
+ customPalettes: ({ sourceColor }, colorHct) => ({
3133
+ hue: colorHct.hue,
3134
+ chroma: sourceColor.chroma
3135
+ }),
3136
+ colorsFromCustomPalette: (key) => {
3137
+ const colorKey = key;
3138
+ const ColorKey = capitalizeFirstLetter(key);
3139
+ const onColorKey = "on" + ColorKey;
3140
+ const colorContainerKey = colorKey + "Container";
3141
+ const onColorContainerKey = "on" + ColorKey + "Container";
3142
+ const colors = ({ palettes, colors: colors2, context: ctx }) => ({
3143
+ [colorKey]: {
3144
+ palette: () => palettes.get(colorKey),
3145
+ tone: () => {
3146
+ if (ctx.variant.name === "neutral") {
3147
+ return ctx.isDark ? tMinC(palettes.get(colorKey), 0, 98) : tMaxC(palettes.get(colorKey));
3148
+ } else if (ctx.variant.name === "vibrant") {
3149
+ return tMaxC(palettes.get(colorKey), 0, ctx.isDark ? 90 : 98);
3150
+ } else {
3151
+ return ctx.isDark ? 80 : tMaxC(palettes.get(colorKey));
3152
+ }
3153
+ },
3154
+ isBackground: true,
3155
+ background: () => highestSurface(ctx, colors2),
3156
+ contrastCurve: () => getCurve(4.5),
3157
+ adjustTone: () => toneDeltaPair(
3158
+ colors2.get(colorContainerKey),
3159
+ colors2.get(colorKey),
3160
+ 5,
3161
+ "relative_lighter",
3162
+ true,
3163
+ "farther"
3164
+ )
3165
+ },
3166
+ // [colorDimKey]: {
3167
+ // palette: () => palettes.get(colorKey),
3168
+ // tone: () => {
3169
+ // if (ctx.variant.name === 'neutral') {
3170
+ // return 85;
3171
+ // } else {
3172
+ // return tMaxC(palettes.get(colorKey), 0, 90);
3173
+ // }
3174
+ // },
3175
+ // isBackground: true,
3176
+ // background: () => colors.get('surfaceContainerHigh'),
3177
+ // contrastCurve: () => getCurve(4.5),
3178
+ // adjustTone: () =>
3179
+ // toneDeltaPair(
3180
+ // colors.get(colorDimKey),
3181
+ // colors.get(colorKey),
3182
+ // 5,
3183
+ // 'darker',
3184
+ // true,
3185
+ // 'farther',
3186
+ // ),
3187
+ // },
3188
+ [onColorKey]: {
3189
+ palette: () => palettes.get(colorKey),
3190
+ background: () => colors2.get(colorKey),
3191
+ contrastCurve: () => getCurve(6)
3192
+ },
3193
+ [colorContainerKey]: {
3194
+ palette: () => palettes.get(colorKey),
3195
+ tone: () => {
3196
+ if (ctx.variant.name === "vibrant") {
3197
+ return ctx.isDark ? tMinC(palettes.get(colorKey), 30, 40) : tMaxC(palettes.get(colorKey), 84, 90);
3198
+ } else if (ctx.variant.name === "expressive") {
3199
+ return ctx.isDark ? 15 : tMaxC(palettes.get(colorKey), 90, 95);
3200
+ } else {
3201
+ return ctx.isDark ? 25 : 90;
3202
+ }
3203
+ },
3204
+ isBackground: true,
3205
+ background: () => highestSurface(ctx, colors2),
3206
+ adjustTone: () => void 0,
3207
+ contrastCurve: () => ctx.contrastLevel > 0 ? getCurve(1.5) : void 0
3208
+ },
3209
+ [onColorContainerKey]: {
3210
+ palette: () => palettes.get(colorKey),
3211
+ background: () => colors2.get(colorContainerKey),
3212
+ contrastCurve: () => getCurve(6)
3213
+ }
3214
+ // [colorFixedKey]: {
3215
+ // palette: () => palettes.get(colorKey),
3216
+ // tone: () => {
3217
+ // return ctx.temp({ isDark: false, contrastLevel: 0 }, () => {
3218
+ // const color = colors.get(colorContainerKey);
3219
+ // return color.getTone();
3220
+ // });
3221
+ // },
3222
+ // isBackground: true,
3223
+ // background: () => highestSurface(ctx, colors),
3224
+ // contrastCurve: () =>
3225
+ // ctx.contrastLevel > 0 ? getCurve(1.5) : undefined,
3226
+ // },
3227
+ // [colorFixedDimKey]: {
3228
+ // palette: () => palettes.get(colorKey),
3229
+ // tone: () => colors.get(colorFixedKey).getTone(),
3230
+ // isBackground: true,
3231
+ // adjustTone: () =>
3232
+ // toneDeltaPair(
3233
+ // colors.get(colorFixedDimKey),
3234
+ // colors.get(colorFixedKey),
3235
+ // 5,
3236
+ // 'darker',
3237
+ // true,
3238
+ // 'exact',
3239
+ // ),
3240
+ // },
3241
+ // [onColorFixedKey]: {
3242
+ // palette: () => palettes.get(colorKey),
3243
+ // background: () => this.get(colorFixedDimKey),
3244
+ // contrastCurve: () => getCurve(7),
3245
+ // },
3246
+ // [onColorFixedVariantKey]: {
3247
+ // palette: () => palettes.get(colorKey),
3248
+ // background: () => colors.get(colorFixedDimKey),
3249
+ // contrastCurve: () => getCurve(4.5),
3250
+ // },
3251
+ });
3252
+ return colors;
3253
+ },
3254
+ colors: ({ colors, context: c, palettes }) => {
3255
+ const getColor = (key) => {
3256
+ return colors.get(key);
3257
+ };
3258
+ return {
3259
+ ////////////////////////////////////////////////////////////////
3260
+ // Surfaces [S] //
3261
+ ////////////////////////////////////////////////////////////////
3262
+ surface: {
3263
+ palette: () => palettes.get("neutral"),
3264
+ tone: () => {
3265
+ if (c.isDark) {
3266
+ return 2;
3267
+ } else {
3268
+ return 99;
3269
+ }
3270
+ },
3271
+ isBackground: true
3272
+ },
3273
+ // surfaceDim: {
3274
+ // palette: () => palettes.get('neutral'),
3275
+ // tone: () => {
3276
+ // if (c.isDark) {
3277
+ // return 4;
3278
+ // } else {
3279
+ // if (Hct.isYellow(palettes.get('neutral').hue)) {
3280
+ // return 90;
3281
+ // } else if (c.variant.name === 'vibrant') {
3282
+ // return 85;
3283
+ // } else {
3284
+ // return 87;
3285
+ // }
3286
+ // }
3287
+ // },
3288
+ // isBackground: true,
3289
+ // chromaMultiplier: () => {
3290
+ // if (!c.isDark) {
3291
+ // if (c.variant.name === 'neutral') {
3292
+ // return 2.5;
3293
+ // } else if (c.variant.name === 'tonalSpot') {
3294
+ // return 1.7;
3295
+ // } else if (c.variant.name === 'expressive') {
3296
+ // return Hct.isYellow(palettes.get('neutral').hue) ? 2.7 : 1.75;
3297
+ // } else if (c.variant.name === 'vibrant') {
3298
+ // return 1.36;
3299
+ // }
3300
+ // }
3301
+ // return 1;
3302
+ // },
3303
+ // },
3304
+ // surfaceBright: {
3305
+ // palette: () => palettes.get('neutral'),
3306
+ // tone: () => {
3307
+ // if (c.isDark) {
3308
+ // return 18;
3309
+ // } else {
3310
+ // if (Hct.isYellow(palettes.get('neutral').hue)) {
3311
+ // return 99;
3312
+ // } else if (c.variant.name === 'vibrant') {
3313
+ // return 97;
3314
+ // } else {
3315
+ // return 98;
3316
+ // }
3317
+ // }
3318
+ // },
3319
+ // isBackground: true,
3320
+ // chromaMultiplier: () => {
3321
+ // if (c.isDark) {
3322
+ // if (c.variant.name === 'neutral') {
3323
+ // return 2.5;
3324
+ // } else if (c.variant.name === 'tonalSpot') {
3325
+ // return 1.7;
3326
+ // } else if (c.variant.name === 'expressive') {
3327
+ // return Hct.isYellow(palettes.get('neutral').hue) ? 2.7 : 1.75;
3328
+ // } else if (c.variant.name === 'vibrant') {
3329
+ // return 1.36;
3330
+ // }
3331
+ // }
3332
+ // return 1;
3333
+ // },
3334
+ // },
3335
+ surfaceContainerLowest: {
3336
+ palette: () => palettes.get("neutral"),
3337
+ tone: () => surfaceContainerTone(0, { palettes, context: c }),
3338
+ isBackground: true
3339
+ },
3340
+ surfaceContainerLow: {
3341
+ palette: () => palettes.get("neutral"),
3342
+ tone: () => surfaceContainerTone(1, { palettes, context: c }),
3343
+ isBackground: true,
3344
+ chromaMultiplier: () => {
3345
+ return 1.25;
3346
+ }
3347
+ },
3348
+ surfaceContainer: {
3349
+ palette: () => palettes.get("neutral"),
3350
+ tone: () => surfaceContainerTone(2, { palettes, context: c }),
3351
+ isBackground: true,
3352
+ chromaMultiplier: () => {
3353
+ return 1.4;
3354
+ }
3355
+ },
3356
+ surfaceContainerHigh: {
3357
+ palette: () => palettes.get("neutral"),
3358
+ tone: () => surfaceContainerTone(3, { palettes, context: c }),
3359
+ isBackground: true,
3360
+ chromaMultiplier: () => {
3361
+ return 1.5;
3362
+ }
3363
+ },
3364
+ surfaceContainerHighest: {
3365
+ palette: () => palettes.get("neutral"),
3366
+ tone: () => surfaceContainerTone(4, { palettes, context: c }),
3367
+ isBackground: true,
3368
+ chromaMultiplier: () => {
3369
+ return 1.7;
3370
+ }
3371
+ },
3372
+ onSurface: {
3373
+ palette: () => palettes.get("neutral"),
3374
+ tone: () => {
3375
+ return getInitialToneFromBackground(highestSurface(c, colors));
3376
+ },
3377
+ chromaMultiplier: () => {
3378
+ return 1.7;
3379
+ },
3380
+ background: () => highestSurface(c, colors),
3381
+ contrastCurve: () => c.isDark ? getCurve(11) : getCurve(9)
3382
+ },
3383
+ onSurfaceVariant: {
3384
+ palette: () => palettes.get("neutralVariant"),
3385
+ chromaMultiplier: () => {
3386
+ return 1.7;
3387
+ },
3388
+ background: () => highestSurface(c, colors),
3389
+ contrastCurve: () => c.isDark ? getCurve(6) : getCurve(4.5)
3390
+ },
3391
+ outline: {
3392
+ palette: () => palettes.get("neutralVariant"),
3393
+ chromaMultiplier: () => {
3394
+ return 1.7;
3395
+ },
3396
+ background: () => highestSurface(c, colors),
3397
+ contrastCurve: () => getCurve(3)
3398
+ },
3399
+ outlineVariant: {
3400
+ palette: () => palettes.get("neutralVariant"),
3401
+ chromaMultiplier: () => {
3402
+ return 1.7;
3403
+ },
3404
+ background: () => highestSurface(c, colors),
3405
+ contrastCurve: () => getCurve(1.5)
3406
+ },
3407
+ inverseSurface: {
3408
+ palette: () => palettes.get("neutral"),
3409
+ tone: () => 100 - colors.get("surface").getTone(),
3410
+ isBackground: true
3411
+ },
3412
+ inverseOnSurface: {
3413
+ palette: () => palettes.get("neutral"),
3414
+ tone: () => c.isDark ? 20 : 95,
3415
+ background: () => colors.get("inverseSurface"),
3416
+ contrastCurve: () => getCurve(7)
3417
+ },
3418
+ ////////////////////////////////////////////////////////////////
3419
+ // Primaries [P] //
3420
+ ////////////////////////////////////////////////////////////////
3421
+ primary: {
3422
+ palette: () => palettes.get("primary"),
3423
+ tone: () => {
3424
+ return c.sourceColor.tone;
3425
+ },
3426
+ isBackground: true,
3427
+ background: () => highestSurface(c, colors),
3428
+ contrastCurve: () => getCurve(4.5),
3429
+ adjustTone: () => () => {
3430
+ const surfaceTone = colors.get("surface").getTone();
3431
+ const primaryTone = colors.get("primary").options.tone;
3432
+ let selfTone = primaryTone;
3433
+ if (Contrast.ratioOfTones(surfaceTone, selfTone) < 3) {
3434
+ const ratio = calculateToneAdjustmentPercentage(
3435
+ surfaceTone,
3436
+ selfTone,
3437
+ 3
3438
+ );
3439
+ const inverseT = inverseTone(primaryTone);
3440
+ selfTone = selfTone + (inverseT - selfTone) * ratio;
3441
+ }
3442
+ return selfTone;
3443
+ }
3444
+ },
3445
+ // primaryDim: {
3446
+ // palette: () => palettes.get('primary'),
3447
+ // tone: () => {
3448
+ // if (c.variant.name === 'neutral') {
3449
+ // return 85;
3450
+ // } else if (c.variant.name === 'tonalSpot') {
3451
+ // return tMaxC(palettes.get('primary'), 0, 90);
3452
+ // } else {
3453
+ // return tMaxC(palettes.get('primary'));
3454
+ // }
3455
+ // },
3456
+ // isBackground: true,
3457
+ // background: () => getColor('surfaceContainerHigh'),
3458
+ // contrastCurve: () => getCurve(4.5),
3459
+ // adjustTone: () =>
3460
+ // toneDeltaPair(
3461
+ // colors.get('primaryDim'),
3462
+ // colors.get('primary'),
3463
+ // 5,
3464
+ // 'darker',
3465
+ // true,
3466
+ // 'farther',
3467
+ // ),
3468
+ // },
3469
+ onPrimary: {
3470
+ palette: () => palettes.get("primary"),
3471
+ background: () => colors.get("primary"),
3472
+ contrastCurve: () => getCurve(6)
3473
+ },
3474
+ primaryContainer: {
3475
+ palette: () => palettes.get("primary"),
3476
+ tone: () => {
3477
+ return c.isDark ? tMinC(palettes.get("primary"), 35, 93) : tMaxC(palettes.get("primary"), 0, 90);
3478
+ },
3479
+ isBackground: true,
3480
+ background: () => highestSurface(c, colors),
3481
+ adjustTone: () => c.variant.name == "fidelity" ? toneDeltaPair(
3482
+ colors.get("primary"),
3483
+ colors.get("primaryContainer"),
3484
+ 15,
3485
+ "relative_darker",
3486
+ true,
3487
+ "farther"
3488
+ ) : void 0,
3489
+ contrastCurve: () => c.contrastLevel > 0 ? getCurve(1.5) : void 0
3490
+ },
3491
+ onPrimaryContainer: {
3492
+ palette: () => palettes.get("primary"),
3493
+ background: () => colors.get("primaryContainer"),
3494
+ contrastCurve: () => getCurve(6)
3495
+ },
3496
+ // primaryFixed: {
3497
+ // palette: () => palettes.get('primary'),
3498
+ // tone: () => {
3499
+ // return c.temp(
3500
+ // {
3501
+ // isDark: false,
3502
+ // contrastLevel: 0,
3503
+ // },
3504
+ // () => {
3505
+ // const color = getColor('primaryContainer');
3506
+ // return color.getTone();
3507
+ // },
3508
+ // );
3509
+ // },
3510
+ // isBackground: true,
3511
+ // background: () => highestSurface(c, colors),
3512
+ // contrastCurve: () => (c.contrastLevel > 0 ? getCurve(1.5) : undefined),
3513
+ // },
3514
+ // primaryFixedDim: {
3515
+ // palette: () => palettes.get('primary'),
3516
+ // tone: () => colors.get('primaryFixed').getTone(),
3517
+ // isBackground: true,
3518
+ // adjustTone: () =>
3519
+ // toneDeltaPair(
3520
+ // getColor('primaryFixedDim'),
3521
+ // getColor('primaryFixed'),
3522
+ // 5,
3523
+ // 'darker',
3524
+ // true,
3525
+ // 'exact',
3526
+ // ),
3527
+ // },
3528
+ // onPrimaryFixed: {
3529
+ // palette: () => palettes.get('primary'),
3530
+ // background: () => colors.get('primaryFixedDim'),
3531
+ // contrastCurve: () => getCurve(7),
3532
+ // },
3533
+ // onPrimaryFixedVariant: {
3534
+ // palette: () => palettes.get('primary'),
3535
+ // background: () => colors.get('primaryFixedDim'),
3536
+ // contrastCurve: () => getCurve(4.5),
3537
+ // },
3538
+ inversePrimary: {
3539
+ palette: () => palettes.get("primary"),
3540
+ tone: () => tMaxC(palettes.get("primary")),
3541
+ background: () => colors.get("inverseSurface"),
3542
+ contrastCurve: () => getCurve(6)
3543
+ },
3544
+ ////////////////////////////////////////////////////////////////
3545
+ // Secondaries [Q] //
3546
+ ////////////////////////////////////////////////////////////////
3547
+ secondary: {
3548
+ palette: () => palettes.get("secondary"),
3549
+ tone: () => {
3550
+ return c.isDark ? 80 : tMaxC(palettes.get("secondary"));
3551
+ },
3552
+ isBackground: true,
3553
+ background: () => highestSurface(c, colors),
3554
+ contrastCurve: () => getCurve(4.5),
3555
+ adjustTone: () => toneDeltaPair(
3556
+ getColor("secondaryContainer"),
3557
+ getColor("secondary"),
3558
+ 5,
3559
+ "relative_lighter",
3560
+ true,
3561
+ "farther"
3562
+ )
3563
+ },
3564
+ // secondaryDim: {
3565
+ // palette: () => palettes.get('secondary'),
3566
+ // tone: () => {
3567
+ // if (c.variant.name === 'neutral') {
3568
+ // return 85;
3569
+ // } else {
3570
+ // return tMaxC(palettes.get('secondary'), 0, 90);
3571
+ // }
3572
+ // },
3573
+ // isBackground: true,
3574
+ // background: () => getColor('surfaceContainerHigh'),
3575
+ // contrastCurve: () => getCurve(4.5),
3576
+ // adjustTone: () =>
3577
+ // toneDeltaPair(
3578
+ // getColor('secondaryDim'),
3579
+ // getColor('secondary'),
3580
+ // 5,
3581
+ // 'darker',
3582
+ // true,
3583
+ // 'farther',
3584
+ // ),
3585
+ // },
3586
+ onSecondary: {
3587
+ palette: () => palettes.get("secondary"),
3588
+ background: () => getColor("secondary"),
3589
+ contrastCurve: () => getCurve(6)
3590
+ },
3591
+ secondaryContainer: {
3592
+ palette: () => palettes.get("secondary"),
3593
+ tone: () => {
3594
+ return c.isDark ? 25 : 90;
3595
+ },
3596
+ isBackground: true,
3597
+ background: () => highestSurface(c, colors),
3598
+ adjustTone: () => void 0,
3599
+ contrastCurve: () => c.contrastLevel > 0 ? getCurve(1.5) : void 0
3600
+ },
3601
+ onSecondaryContainer: {
3602
+ palette: () => palettes.get("secondary"),
3603
+ background: () => getColor("secondaryContainer"),
3604
+ contrastCurve: () => getCurve(6)
3605
+ },
3606
+ // secondaryFixed: {
3607
+ // palette: () => palettes.get('secondary'),
3608
+ // tone: () => {
3609
+ // return c.temp(
3610
+ // {
3611
+ // isDark: false,
3612
+ // contrastLevel: 0,
3613
+ // },
3614
+ // () => {
3615
+ // const color = getColor('secondaryContainer');
3616
+ // return color.getTone();
3617
+ // },
3618
+ // );
3619
+ // },
3620
+ // isBackground: true,
3621
+ // background: () => highestSurface(c, colors),
3622
+ // contrastCurve: () => (c.contrastLevel > 0 ? getCurve(1.5) : undefined),
3623
+ // },
3624
+ // secondaryFixedDim: {
3625
+ // palette: () => palettes.get('secondary'),
3626
+ // tone: () => getColor('secondaryFixed').getTone(),
3627
+ // isBackground: true,
3628
+ // adjustTone: () =>
3629
+ // toneDeltaPair(
3630
+ // getColor('secondaryFixedDim'),
3631
+ // getColor('secondaryFixed'),
3632
+ // 5,
3633
+ // 'darker',
3634
+ // true,
3635
+ // 'exact',
3636
+ // ),
3637
+ // },
3638
+ // onSecondaryFixed: {
3639
+ // palette: () => palettes.get('secondary'),
3640
+ // background: () => getColor('secondaryFixedDim'),
3641
+ // contrastCurve: () => getCurve(7),
3642
+ // },
3643
+ // onSecondaryFixedVariant: {
3644
+ // palette: () => palettes.get('secondary'),
3645
+ // background: () => getColor('secondaryFixedDim'),
3646
+ // contrastCurve: () => getCurve(4.5),
3647
+ // },
3648
+ ////////////////////////////////////////////////////////////////
3649
+ // Tertiaries [T] //
3650
+ ////////////////////////////////////////////////////////////////
3651
+ tertiary: {
3652
+ palette: () => palettes.get("tertiary"),
3653
+ tone: () => {
3654
+ return c.isDark ? tMaxC(palettes.get("tertiary"), 0, 98) : tMaxC(palettes.get("tertiary"));
3655
+ },
3656
+ isBackground: true,
3657
+ background: () => highestSurface(c, colors),
3658
+ contrastCurve: () => getCurve(4.5),
3659
+ adjustTone: () => toneDeltaPair(
3660
+ getColor("tertiaryContainer"),
3661
+ getColor("tertiary"),
3662
+ 5,
3663
+ "relative_lighter",
3664
+ true,
3665
+ "farther"
3666
+ )
3667
+ },
3668
+ // tertiaryDim: {
3669
+ // palette: () => palettes.get('tertiary'),
3670
+ // tone: () => {
3671
+ // if (c.variant.name === 'tonalSpot') {
3672
+ // return tMaxC(palettes.get('tertiary'), 0, 90);
3673
+ // } else {
3674
+ // return tMaxC(palettes.get('tertiary'));
3675
+ // }
3676
+ // },
3677
+ // isBackground: true,
3678
+ // background: () => getColor('surfaceContainerHigh'),
3679
+ // contrastCurve: () => getCurve(4.5),
3680
+ // adjustTone: () =>
3681
+ // toneDeltaPair(
3682
+ // getColor('tertiaryDim'),
3683
+ // getColor('tertiary'),
3684
+ // 5,
3685
+ // 'darker',
3686
+ // true,
3687
+ // 'farther',
3688
+ // ),
3689
+ // },
3690
+ onTertiary: {
3691
+ palette: () => palettes.get("tertiary"),
3692
+ background: () => getColor("tertiary"),
3693
+ contrastCurve: () => getCurve(6)
3694
+ },
3695
+ tertiaryContainer: {
3696
+ palette: () => palettes.get("tertiary"),
3697
+ tone: () => {
3698
+ return tMaxC(palettes.get("tertiary"), 0, c.isDark ? 93 : 100);
3699
+ },
3700
+ isBackground: true,
3701
+ background: () => highestSurface(c, colors),
3702
+ adjustTone: () => void 0,
3703
+ contrastCurve: () => c.contrastLevel > 0 ? getCurve(1.5) : void 0
3704
+ },
3705
+ onTertiaryContainer: {
3706
+ palette: () => palettes.get("tertiary"),
3707
+ background: () => getColor("tertiaryContainer"),
3708
+ contrastCurve: () => getCurve(6)
3709
+ },
3710
+ // tertiaryFixed: {
3711
+ // palette: () => palettes.get('tertiary'),
3712
+ // tone: () => {
3713
+ // return c.temp(
3714
+ // {
3715
+ // isDark: false,
3716
+ // contrastLevel: 0,
3717
+ // },
3718
+ // () => {
3719
+ // const color = getColor('tertiaryContainer');
3720
+ // return color.getTone();
3721
+ // },
3722
+ // );
3723
+ // },
3724
+ // isBackground: true,
3725
+ // background: () => highestSurface(c, colors),
3726
+ // contrastCurve: () => (c.contrastLevel > 0 ? getCurve(1.5) : undefined),
3727
+ // },
3728
+ // tertiaryFixedDim: {
3729
+ // palette: () => palettes.get('tertiary'),
3730
+ // tone: () => getColor('tertiaryFixed').getTone(),
3731
+ // isBackground: true,
3732
+ // adjustTone: () =>
3733
+ // toneDeltaPair(
3734
+ // getColor('tertiaryFixedDim'),
3735
+ // getColor('tertiaryFixed'),
3736
+ // 5,
3737
+ // 'darker',
3738
+ // true,
3739
+ // 'exact',
3740
+ // ),
3741
+ // },
3742
+ // onTertiaryFixed: {
3743
+ // palette: () => palettes.get('tertiary'),
3744
+ // background: () => getColor('tertiaryFixedDim'),
3745
+ // contrastCurve: () => getCurve(7),
3746
+ // },
3747
+ // onTertiaryFixedVariant: {
3748
+ // palette: () => palettes.get('tertiary'),
3749
+ // background: () => getColor('tertiaryFixedDim'),
3750
+ // contrastCurve: () => getCurve(4.5),
3751
+ // },
3752
+ ////////////////////////////////////////////////////////////////
3753
+ // Errors [E] //
3754
+ ////////////////////////////////////////////////////////////////
3755
+ error: {
3756
+ palette: () => palettes.get("error"),
3757
+ tone: () => {
3758
+ return c.isDark ? tMinC(palettes.get("error"), 0, 98) : tMaxC(palettes.get("error"));
3759
+ },
3760
+ isBackground: true,
3761
+ background: () => highestSurface(c, colors),
3762
+ contrastCurve: () => getCurve(4.5),
3763
+ adjustTone: () => toneDeltaPair(
3764
+ colors.get("errorContainer"),
3765
+ colors.get("error"),
3766
+ 5,
3767
+ "relative_lighter",
3768
+ true,
3769
+ "farther"
3770
+ )
3771
+ },
3772
+ // errorDim: {
3773
+ // palette: () => palettes.get('error'),
3774
+ // tone: () => tMinC(palettes.get('error')),
3775
+ // isBackground: true,
3776
+ // background: () => getColor('surfaceContainerHigh'),
3777
+ // contrastCurve: () => getCurve(4.5),
3778
+ // adjustTone: () =>
3779
+ // toneDeltaPair(
3780
+ // getColor('errorDim'),
3781
+ // getColor('error'),
3782
+ // 5,
3783
+ // 'darker',
3784
+ // true,
3785
+ // 'farther',
3786
+ // ),
3787
+ // },
3788
+ onError: {
3789
+ palette: () => palettes.get("error"),
3790
+ background: () => colors.get("error"),
3791
+ contrastCurve: () => getCurve(6)
3792
+ },
3793
+ errorContainer: {
3794
+ palette: () => palettes.get("error"),
3795
+ tone: () => {
3796
+ return c.isDark ? tMinC(palettes.get("error"), 30, 93) : tMaxC(palettes.get("error"), 0, 90);
3797
+ },
3798
+ isBackground: true,
3799
+ background: () => highestSurface(c, colors),
3800
+ adjustTone: () => void 0,
3801
+ contrastCurve: () => c.contrastLevel > 0 ? getCurve(1.5) : void 0
3802
+ },
3803
+ onErrorContainer: {
3804
+ palette: () => palettes.get("error"),
3805
+ background: () => colors.get("errorContainer"),
3806
+ contrastCurve: () => getCurve(4.5)
3807
+ },
3808
+ /////////////////////////////////////////////////////////////////
3809
+ // Remapped Colors //
3810
+ /////////////////////////////////////////////////////////////////
3811
+ surfaceVariant: {
3812
+ alias: "surfaceContainerHighest"
3813
+ },
3814
+ surfaceTint: {
3815
+ alias: "primary"
3816
+ },
3817
+ background: {
3818
+ alias: "surface"
3819
+ },
3820
+ onBackground: {
3821
+ alias: "onSurface"
3822
+ }
3823
+ };
3824
+ }
3825
+ });
3826
+ const Variants = {
3827
+ Expressive: expressiveVariant,
3828
+ Neutral: neutralVariant,
3829
+ TonalSpot: tonalSpotVariant,
3830
+ Vibrant: vibrantVariant,
3831
+ Udixio: udixioVariant
3832
+ };
3833
+ const loader = async (config, load = true) => {
3834
+ const api = bootstrap();
3835
+ const init = () => {
3836
+ const {
3837
+ sourceColor,
3838
+ contrastLevel = 0,
3839
+ isDark = false,
3840
+ variant: variant2 = Variants.TonalSpot,
3841
+ palettes,
3842
+ colors,
3843
+ plugins
3844
+ } = config;
3845
+ api.context.set({
3846
+ contrastLevel,
3847
+ isDark,
3848
+ sourceColor,
3849
+ variant: variant2
3850
+ });
3851
+ if (palettes) {
3852
+ api.palettes.add(palettes);
3853
+ }
3854
+ if (colors) {
3855
+ api.colors.addColors(colors);
3856
+ }
3857
+ if (plugins) {
3858
+ plugins.forEach((plugin) => {
3859
+ api.plugins.addPlugin(plugin);
3860
+ });
3861
+ api.plugins.initPlugins(api);
3862
+ }
3863
+ };
3864
+ init();
3865
+ if (load) {
3866
+ await api.load();
3867
+ }
3868
+ return api;
3869
+ };
3870
+ export {
3871
+ API as A,
3872
+ tonalSpotVariant as B,
3873
+ ColorApi as C,
3874
+ DynamicColor as D,
3875
+ vibrantVariant as E,
3876
+ expressiveVariant as F,
3877
+ neutralVariant as G,
3878
+ Palette as P,
3879
+ Variant as V,
3880
+ AppContainer as a,
3881
+ AppModule as b,
3882
+ bootstrap as c,
3883
+ capitalizeFirstLetter as d,
3884
+ ColorManager as e,
3885
+ ColorModule as f,
3886
+ getInitialToneFromBackground as g,
3887
+ Color as h,
3888
+ ColorAlias as i,
3889
+ ColorFromHex as j,
3890
+ ColorFromPalette as k,
3891
+ highestSurface$1 as l,
3892
+ defaultColors as m,
3893
+ ContextModule as n,
3894
+ Context as o,
3895
+ loader as p,
3896
+ ContrastCurve as q,
3897
+ PaletteApi as r,
3898
+ PaletteModule as s,
3899
+ toneDeltaPair as t,
3900
+ PluginModule as u,
3901
+ PluginApi as v,
3902
+ getPiecewiseHue as w,
3903
+ getRotatedHue as x,
3904
+ variant as y,
3905
+ Variants as z
3906
+ };