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