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