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