@atlaskit/tokens 1.11.2 → 1.12.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/CHANGELOG.md +20 -0
- package/dist/cjs/artifacts/atlassian-dark-token-value-for-contrast-check.js +24 -0
- package/dist/cjs/artifacts/atlassian-light-token-value-for-contrast-check.js +24 -0
- package/dist/cjs/artifacts/themes/atlassian-dark-new-input-border.js +2 -2
- package/dist/cjs/artifacts/tokens-raw/atlassian-dark-new-input-border.js +3 -3
- package/dist/cjs/constants.js +3 -1
- package/dist/cjs/custom-theme.js +108 -0
- package/dist/cjs/get-token-value.js +1 -1
- package/dist/cjs/get-token.js +1 -1
- package/dist/cjs/set-global-theme.js +156 -59
- package/dist/cjs/tokens/atlassian-dark-new-input-border/color/border.js +1 -1
- package/dist/cjs/utils/color-utils.js +178 -0
- package/dist/cjs/utils/custom-theme-loading-utils.js +47 -0
- package/dist/cjs/utils/custom-theme-token-contrast-check.js +74 -0
- package/dist/cjs/utils/generate-custom-color-ramp.js +213 -0
- package/dist/cjs/utils/hash.js +17 -0
- package/dist/cjs/utils/hct-color-utils/color-utils.js +310 -0
- package/dist/cjs/utils/hct-color-utils/contrast.js +188 -0
- package/dist/cjs/utils/hct-color-utils/hct.js +1036 -0
- package/dist/cjs/utils/hct-color-utils/index.js +32 -0
- package/dist/cjs/utils/hct-color-utils/math-utils.js +159 -0
- package/dist/cjs/utils/theme-loading.js +1 -1
- package/dist/cjs/utils/theme-state-transformer.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/artifacts/atlassian-dark-token-value-for-contrast-check.js +17 -0
- package/dist/es2019/artifacts/atlassian-light-token-value-for-contrast-check.js +17 -0
- package/dist/es2019/artifacts/themes/atlassian-dark-new-input-border.js +2 -2
- package/dist/es2019/artifacts/tokens-raw/atlassian-dark-new-input-border.js +3 -3
- package/dist/es2019/constants.js +1 -0
- package/dist/es2019/custom-theme.js +77 -0
- package/dist/es2019/get-token-value.js +1 -1
- package/dist/es2019/get-token.js +1 -1
- package/dist/es2019/set-global-theme.js +67 -13
- package/dist/es2019/tokens/atlassian-dark-new-input-border/color/border.js +1 -1
- package/dist/es2019/utils/color-utils.js +154 -0
- package/dist/es2019/utils/custom-theme-loading-utils.js +31 -0
- package/dist/es2019/utils/custom-theme-token-contrast-check.js +68 -0
- package/dist/es2019/utils/generate-custom-color-ramp.js +187 -0
- package/dist/es2019/utils/hash.js +10 -0
- package/dist/es2019/utils/hct-color-utils/color-utils.js +286 -0
- package/dist/es2019/utils/hct-color-utils/contrast.js +161 -0
- package/dist/es2019/utils/hct-color-utils/hct.js +931 -0
- package/dist/es2019/utils/hct-color-utils/index.js +3 -0
- package/dist/es2019/utils/hct-color-utils/math-utils.js +145 -0
- package/dist/es2019/utils/theme-loading.js +2 -2
- package/dist/es2019/utils/theme-state-transformer.js +3 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/artifacts/atlassian-dark-token-value-for-contrast-check.js +17 -0
- package/dist/esm/artifacts/atlassian-light-token-value-for-contrast-check.js +17 -0
- package/dist/esm/artifacts/themes/atlassian-dark-new-input-border.js +2 -2
- package/dist/esm/artifacts/tokens-raw/atlassian-dark-new-input-border.js +3 -3
- package/dist/esm/constants.js +1 -0
- package/dist/esm/custom-theme.js +98 -0
- package/dist/esm/get-token-value.js +1 -1
- package/dist/esm/get-token.js +1 -1
- package/dist/esm/set-global-theme.js +149 -60
- package/dist/esm/tokens/atlassian-dark-new-input-border/color/border.js +1 -1
- package/dist/esm/utils/color-utils.js +162 -0
- package/dist/esm/utils/custom-theme-loading-utils.js +38 -0
- package/dist/esm/utils/custom-theme-token-contrast-check.js +65 -0
- package/dist/esm/utils/generate-custom-color-ramp.js +202 -0
- package/dist/esm/utils/hash.js +10 -0
- package/dist/esm/utils/hct-color-utils/color-utils.js +285 -0
- package/dist/esm/utils/hct-color-utils/contrast.js +181 -0
- package/dist/esm/utils/hct-color-utils/hct.js +1029 -0
- package/dist/esm/utils/hct-color-utils/index.js +3 -0
- package/dist/esm/utils/hct-color-utils/math-utils.js +145 -0
- package/dist/esm/utils/theme-loading.js +2 -2
- package/dist/esm/utils/theme-state-transformer.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/artifacts/atlassian-dark-token-value-for-contrast-check.d.ts +17 -0
- package/dist/types/artifacts/atlassian-light-token-value-for-contrast-check.d.ts +17 -0
- package/dist/types/artifacts/themes/atlassian-dark-new-input-border.d.ts +2 -2
- package/dist/types/artifacts/tokens-raw/atlassian-dark-new-input-border.d.ts +1 -1
- package/dist/types/constants.d.ts +1 -0
- package/dist/types/custom-theme.d.ts +30 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/set-global-theme.d.ts +9 -3
- package/dist/types/tokens/atlassian-dark/utility/utility.d.ts +1 -1
- package/dist/types/tokens/atlassian-light/utility/utility.d.ts +1 -1
- package/dist/types/tokens/default/utility/utility.d.ts +1 -1
- package/dist/types/utils/color-utils.d.ts +10 -0
- package/dist/types/utils/custom-theme-loading-utils.d.ts +11 -0
- package/dist/types/utils/custom-theme-token-contrast-check.d.ts +20 -0
- package/dist/types/utils/generate-custom-color-ramp.d.ts +19 -0
- package/dist/types/utils/hash.d.ts +1 -0
- package/dist/types/utils/hct-color-utils/color-utils.d.ts +131 -0
- package/dist/types/utils/hct-color-utils/contrast.d.ts +78 -0
- package/dist/types/utils/hct-color-utils/hct.d.ts +137 -0
- package/dist/types/utils/hct-color-utils/index.d.ts +3 -0
- package/dist/types/utils/hct-color-utils/math-utils.d.ts +86 -0
- package/dist/types-ts4.5/artifacts/atlassian-dark-token-value-for-contrast-check.d.ts +17 -0
- package/dist/types-ts4.5/artifacts/atlassian-light-token-value-for-contrast-check.d.ts +17 -0
- package/dist/types-ts4.5/artifacts/themes/atlassian-dark-new-input-border.d.ts +2 -2
- package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-dark-new-input-border.d.ts +1 -1
- package/dist/types-ts4.5/constants.d.ts +1 -0
- package/dist/types-ts4.5/custom-theme.d.ts +30 -0
- package/dist/types-ts4.5/index.d.ts +1 -0
- package/dist/types-ts4.5/set-global-theme.d.ts +9 -3
- package/dist/types-ts4.5/tokens/atlassian-dark/utility/utility.d.ts +1 -1
- package/dist/types-ts4.5/tokens/atlassian-light/utility/utility.d.ts +1 -1
- package/dist/types-ts4.5/tokens/default/utility/utility.d.ts +1 -1
- package/dist/types-ts4.5/utils/color-utils.d.ts +27 -0
- package/dist/types-ts4.5/utils/custom-theme-loading-utils.d.ts +11 -0
- package/dist/types-ts4.5/utils/custom-theme-token-contrast-check.d.ts +20 -0
- package/dist/types-ts4.5/utils/generate-custom-color-ramp.d.ts +19 -0
- package/dist/types-ts4.5/utils/hash.d.ts +1 -0
- package/dist/types-ts4.5/utils/hct-color-utils/color-utils.d.ts +131 -0
- package/dist/types-ts4.5/utils/hct-color-utils/contrast.d.ts +78 -0
- package/dist/types-ts4.5/utils/hct-color-utils/hct.d.ts +137 -0
- package/dist/types-ts4.5/utils/hct-color-utils/index.d.ts +3 -0
- package/dist/types-ts4.5/utils/hct-color-utils/math-utils.d.ts +86 -0
- package/figma/atlassian-dark-new-input-border.json +1 -1
- package/package.json +35 -40
- package/report.api.md +24 -1
- package/tmp/api-report-tmp.d.ts +0 -1132
|
@@ -0,0 +1,1029 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
|
+
/**
|
|
5
|
+
* Below lines are copied from @material/material-color-utilities.
|
|
6
|
+
* Do not modify it.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @license
|
|
11
|
+
* Copyright 2021 Google LLC
|
|
12
|
+
*
|
|
13
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
14
|
+
* you may not use this file except in compliance with the License.
|
|
15
|
+
* You may obtain a copy of the License at
|
|
16
|
+
*
|
|
17
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
18
|
+
*
|
|
19
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
20
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
21
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
22
|
+
* See the License for the specific language governing permissions and
|
|
23
|
+
* limitations under the License.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import * as utils from './color-utils';
|
|
27
|
+
import * as math from './math-utils';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A color system built using CAM16 hue and chroma, and L* from
|
|
31
|
+
* L*a*b*.
|
|
32
|
+
*
|
|
33
|
+
* Using L* creates a link between the color system, contrast, and thus
|
|
34
|
+
* accessibility. Contrast ratio depends on relative luminance, or Y in the XYZ
|
|
35
|
+
* color space. L*, or perceptual luminance can be calculated from Y.
|
|
36
|
+
*
|
|
37
|
+
* Unlike Y, L* is linear to human perception, allowing trivial creation of
|
|
38
|
+
* accurate color tones.
|
|
39
|
+
*
|
|
40
|
+
* Unlike contrast ratio, measuring contrast in L* is linear, and simple to
|
|
41
|
+
* calculate. A difference of 40 in HCT tone guarantees a contrast ratio >= 3.0,
|
|
42
|
+
* and a difference of 50 guarantees a contrast ratio >= 4.5.
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* HCT, hue, chroma, and tone. A color system that provides a perceptually
|
|
47
|
+
* accurate color measurement system that can also accurately render what colors
|
|
48
|
+
* will appear as in different lighting environments.
|
|
49
|
+
*/
|
|
50
|
+
export var Hct = /*#__PURE__*/function () {
|
|
51
|
+
function Hct(argb) {
|
|
52
|
+
_classCallCheck(this, Hct);
|
|
53
|
+
this.argb = argb;
|
|
54
|
+
var cam = Cam16.fromInt(argb);
|
|
55
|
+
this.internalHue = cam.hue;
|
|
56
|
+
this.internalChroma = cam.chroma;
|
|
57
|
+
this.internalTone = utils.lstarFromArgb(argb);
|
|
58
|
+
this.argb = argb;
|
|
59
|
+
}
|
|
60
|
+
_createClass(Hct, [{
|
|
61
|
+
key: "toInt",
|
|
62
|
+
value: function toInt() {
|
|
63
|
+
return this.argb;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* A number, in degrees, representing ex. red, orange, yellow, etc.
|
|
68
|
+
* Ranges from 0 <= hue < 360.
|
|
69
|
+
*/
|
|
70
|
+
}, {
|
|
71
|
+
key: "hue",
|
|
72
|
+
get: function get() {
|
|
73
|
+
return this.internalHue;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @param newHue 0 <= newHue < 360; invalid values are corrected.
|
|
78
|
+
* Chroma may decrease because chroma has a different maximum for any given
|
|
79
|
+
* hue and tone.
|
|
80
|
+
*/,
|
|
81
|
+
set: function set(newHue) {
|
|
82
|
+
this.setInternalState(HctSolver.solveToInt(newHue, this.internalChroma, this.internalTone));
|
|
83
|
+
}
|
|
84
|
+
}, {
|
|
85
|
+
key: "chroma",
|
|
86
|
+
get: function get() {
|
|
87
|
+
return this.internalChroma;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @param newChroma 0 <= newChroma < ?
|
|
92
|
+
* Chroma may decrease because chroma has a different maximum for any given
|
|
93
|
+
* hue and tone.
|
|
94
|
+
*/,
|
|
95
|
+
set: function set(newChroma) {
|
|
96
|
+
this.setInternalState(HctSolver.solveToInt(this.internalHue, newChroma, this.internalTone));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Lightness. Ranges from 0 to 100.
|
|
101
|
+
*/
|
|
102
|
+
}, {
|
|
103
|
+
key: "tone",
|
|
104
|
+
get: function get() {
|
|
105
|
+
return this.internalTone;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @param newTone 0 <= newTone <= 100; invalid valids are corrected.
|
|
110
|
+
* Chroma may decrease because chroma has a different maximum for any given
|
|
111
|
+
* hue and tone.
|
|
112
|
+
*/,
|
|
113
|
+
set: function set(newTone) {
|
|
114
|
+
this.setInternalState(HctSolver.solveToInt(this.internalHue, this.internalChroma, newTone));
|
|
115
|
+
}
|
|
116
|
+
}, {
|
|
117
|
+
key: "setInternalState",
|
|
118
|
+
value: function setInternalState(argb) {
|
|
119
|
+
var cam = Cam16.fromInt(argb);
|
|
120
|
+
this.internalHue = cam.hue;
|
|
121
|
+
this.internalChroma = cam.chroma;
|
|
122
|
+
this.internalTone = utils.lstarFromArgb(argb);
|
|
123
|
+
this.argb = argb;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Translates a color into different [ViewingConditions].
|
|
128
|
+
*
|
|
129
|
+
* Colors change appearance. They look different with lights on versus off,
|
|
130
|
+
* the same color, as in hex code, on white looks different when on black.
|
|
131
|
+
* This is called color relativity, most famously explicated by Josef Albers
|
|
132
|
+
* in Interaction of Color.
|
|
133
|
+
*
|
|
134
|
+
* In color science, color appearance models can account for this and
|
|
135
|
+
* calculate the appearance of a color in different settings. HCT is based on
|
|
136
|
+
* CAM16, a color appearance model, and uses it to make these calculations.
|
|
137
|
+
*
|
|
138
|
+
* See [ViewingConditions.make] for parameters affecting color appearance.
|
|
139
|
+
*/
|
|
140
|
+
}, {
|
|
141
|
+
key: "inViewingConditions",
|
|
142
|
+
value: function inViewingConditions(vc) {
|
|
143
|
+
// 1. Use CAM16 to find XYZ coordinates of color in specified VC.
|
|
144
|
+
var cam = Cam16.fromInt(this.toInt());
|
|
145
|
+
var viewedInVc = cam.xyzInViewingConditions(vc);
|
|
146
|
+
|
|
147
|
+
// 2. Create CAM16 of those XYZ coordinates in default VC.
|
|
148
|
+
var recastInVc = Cam16.fromXyzInViewingConditions(viewedInVc[0], viewedInVc[1], viewedInVc[2], ViewingConditions.make());
|
|
149
|
+
|
|
150
|
+
// 3. Create HCT from:
|
|
151
|
+
// - CAM16 using default VC with XYZ coordinates in specified VC.
|
|
152
|
+
// - L* converted from Y in XYZ coordinates in specified VC.
|
|
153
|
+
var recastHct = Hct.from(recastInVc.hue, recastInVc.chroma, utils.lstarFromY(viewedInVc[1]));
|
|
154
|
+
return recastHct;
|
|
155
|
+
}
|
|
156
|
+
}], [{
|
|
157
|
+
key: "from",
|
|
158
|
+
value:
|
|
159
|
+
/**
|
|
160
|
+
* @param hue 0 <= hue < 360; invalid values are corrected.
|
|
161
|
+
* @param chroma 0 <= chroma < ?; Informally, colorfulness. The color
|
|
162
|
+
* returned may be lower than the requested chroma. Chroma has a different
|
|
163
|
+
* maximum for any given hue and tone.
|
|
164
|
+
* @param tone 0 <= tone <= 100; invalid values are corrected.
|
|
165
|
+
* @return HCT representation of a color in default viewing conditions.
|
|
166
|
+
*/
|
|
167
|
+
|
|
168
|
+
function from(hue, chroma, tone) {
|
|
169
|
+
return new Hct(HctSolver.solveToInt(hue, chroma, tone));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* @param argb ARGB representation of a color.
|
|
174
|
+
* @return HCT representation of a color in default viewing conditions
|
|
175
|
+
*/
|
|
176
|
+
}, {
|
|
177
|
+
key: "fromInt",
|
|
178
|
+
value: function fromInt(argb) {
|
|
179
|
+
return new Hct(argb);
|
|
180
|
+
}
|
|
181
|
+
}]);
|
|
182
|
+
return Hct;
|
|
183
|
+
}();
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* CAM16, a color appearance model. Colors are not just defined by their hex
|
|
187
|
+
* code, but rather, a hex code and viewing conditions.
|
|
188
|
+
*
|
|
189
|
+
* CAM16 instances also have coordinates in the CAM16-UCS space, called J*, a*,
|
|
190
|
+
* b*, or jstar, astar, bstar in code. CAM16-UCS is included in the CAM16
|
|
191
|
+
* specification, and should be used when measuring distances between colors.
|
|
192
|
+
*
|
|
193
|
+
* In traditional color spaces, a color can be identified solely by the
|
|
194
|
+
* observer's measurement of the color. Color appearance models such as CAM16
|
|
195
|
+
* also use information about the environment where the color was
|
|
196
|
+
* observed, known as the viewing conditions.
|
|
197
|
+
*
|
|
198
|
+
* For example, white under the traditional assumption of a midday sun white
|
|
199
|
+
* point is accurately measured as a slightly chromatic blue by CAM16. (roughly,
|
|
200
|
+
* hue 203, chroma 3, lightness 100)
|
|
201
|
+
*/
|
|
202
|
+
var Cam16 = /*#__PURE__*/function () {
|
|
203
|
+
/**
|
|
204
|
+
* All of the CAM16 dimensions can be calculated from 3 of the dimensions, in
|
|
205
|
+
* the following combinations:
|
|
206
|
+
* - {j or q} and {c, m, or s} and hue
|
|
207
|
+
* - jstar, astar, bstar
|
|
208
|
+
* Prefer using a static method that constructs from 3 of those dimensions.
|
|
209
|
+
* This constructor is intended for those methods to use to return all
|
|
210
|
+
* possible dimensions.
|
|
211
|
+
*
|
|
212
|
+
* @param hue
|
|
213
|
+
* @param chroma informally, colorfulness / color intensity. like saturation
|
|
214
|
+
* in HSL, except perceptually accurate.
|
|
215
|
+
* @param j lightness
|
|
216
|
+
* @param q brightness; ratio of lightness to white point's lightness
|
|
217
|
+
* @param m colorfulness
|
|
218
|
+
* @param s saturation; ratio of chroma to white point's chroma
|
|
219
|
+
* @param jstar CAM16-UCS J coordinate
|
|
220
|
+
* @param astar CAM16-UCS a coordinate
|
|
221
|
+
* @param bstar CAM16-UCS b coordinate
|
|
222
|
+
*/
|
|
223
|
+
function Cam16(hue, chroma, j, q, m, s, jstar, astar, bstar) {
|
|
224
|
+
_classCallCheck(this, Cam16);
|
|
225
|
+
this.hue = hue;
|
|
226
|
+
this.chroma = chroma;
|
|
227
|
+
this.j = j;
|
|
228
|
+
this.q = q;
|
|
229
|
+
this.m = m;
|
|
230
|
+
this.s = s;
|
|
231
|
+
this.jstar = jstar;
|
|
232
|
+
this.astar = astar;
|
|
233
|
+
this.bstar = bstar;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* CAM16 instances also have coordinates in the CAM16-UCS space, called J*,
|
|
238
|
+
* a*, b*, or jstar, astar, bstar in code. CAM16-UCS is included in the CAM16
|
|
239
|
+
* specification, and is used to measure distances between colors.
|
|
240
|
+
*/
|
|
241
|
+
_createClass(Cam16, [{
|
|
242
|
+
key: "distance",
|
|
243
|
+
value: function distance(other) {
|
|
244
|
+
var dJ = this.jstar - other.jstar;
|
|
245
|
+
var dA = this.astar - other.astar;
|
|
246
|
+
var dB = this.bstar - other.bstar;
|
|
247
|
+
var dEPrime = Math.sqrt(dJ * dJ + dA * dA + dB * dB);
|
|
248
|
+
var dE = 1.41 * Math.pow(dEPrime, 0.63);
|
|
249
|
+
return dE;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* @param argb ARGB representation of a color.
|
|
254
|
+
* @return CAM16 color, assuming the color was viewed in default viewing
|
|
255
|
+
* conditions.
|
|
256
|
+
*/
|
|
257
|
+
}, {
|
|
258
|
+
key: "toInt",
|
|
259
|
+
value:
|
|
260
|
+
/**
|
|
261
|
+
* @return ARGB representation of color, assuming the color was viewed in
|
|
262
|
+
* default viewing conditions, which are near-identical to the default
|
|
263
|
+
* viewing conditions for sRGB.
|
|
264
|
+
*/
|
|
265
|
+
function toInt() {
|
|
266
|
+
return this.viewed(ViewingConditions.DEFAULT);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* @param viewingConditions Information about the environment where the color
|
|
271
|
+
* will be viewed.
|
|
272
|
+
* @return ARGB representation of color
|
|
273
|
+
*/
|
|
274
|
+
}, {
|
|
275
|
+
key: "viewed",
|
|
276
|
+
value: function viewed(viewingConditions) {
|
|
277
|
+
var alpha = this.chroma === 0.0 || this.j === 0.0 ? 0.0 : this.chroma / Math.sqrt(this.j / 100.0);
|
|
278
|
+
var t = Math.pow(alpha / Math.pow(1.64 - Math.pow(0.29, viewingConditions.n), 0.73), 1.0 / 0.9);
|
|
279
|
+
var hRad = this.hue * Math.PI / 180.0;
|
|
280
|
+
var eHue = 0.25 * (Math.cos(hRad + 2.0) + 3.8);
|
|
281
|
+
var ac = viewingConditions.aw * Math.pow(this.j / 100.0, 1.0 / viewingConditions.c / viewingConditions.z);
|
|
282
|
+
var p1 = eHue * (50000.0 / 13.0) * viewingConditions.nc * viewingConditions.ncb;
|
|
283
|
+
var p2 = ac / viewingConditions.nbb;
|
|
284
|
+
var hSin = Math.sin(hRad);
|
|
285
|
+
var hCos = Math.cos(hRad);
|
|
286
|
+
var gamma = 23.0 * (p2 + 0.305) * t / (23.0 * p1 + 11.0 * t * hCos + 108.0 * t * hSin);
|
|
287
|
+
var a = gamma * hCos;
|
|
288
|
+
var b = gamma * hSin;
|
|
289
|
+
var rA = (460.0 * p2 + 451.0 * a + 288.0 * b) / 1403.0;
|
|
290
|
+
var gA = (460.0 * p2 - 891.0 * a - 261.0 * b) / 1403.0;
|
|
291
|
+
var bA = (460.0 * p2 - 220.0 * a - 6300.0 * b) / 1403.0;
|
|
292
|
+
var rCBase = Math.max(0, 27.13 * Math.abs(rA) / (400.0 - Math.abs(rA)));
|
|
293
|
+
var rC = math.signum(rA) * (100.0 / viewingConditions.fl) * Math.pow(rCBase, 1.0 / 0.42);
|
|
294
|
+
var gCBase = Math.max(0, 27.13 * Math.abs(gA) / (400.0 - Math.abs(gA)));
|
|
295
|
+
var gC = math.signum(gA) * (100.0 / viewingConditions.fl) * Math.pow(gCBase, 1.0 / 0.42);
|
|
296
|
+
var bCBase = Math.max(0, 27.13 * Math.abs(bA) / (400.0 - Math.abs(bA)));
|
|
297
|
+
var bC = math.signum(bA) * (100.0 / viewingConditions.fl) * Math.pow(bCBase, 1.0 / 0.42);
|
|
298
|
+
var rF = rC / viewingConditions.rgbD[0];
|
|
299
|
+
var gF = gC / viewingConditions.rgbD[1];
|
|
300
|
+
var bF = bC / viewingConditions.rgbD[2];
|
|
301
|
+
var x = 1.86206786 * rF - 1.01125463 * gF + 0.14918677 * bF;
|
|
302
|
+
var y = 0.38752654 * rF + 0.62144744 * gF - 0.00897398 * bF;
|
|
303
|
+
var z = -0.0158415 * rF - 0.03412294 * gF + 1.04996444 * bF;
|
|
304
|
+
var argb = utils.argbFromXyz(x, y, z);
|
|
305
|
+
return argb;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/// Given color expressed in XYZ and viewed in [viewingConditions], convert to
|
|
309
|
+
/// CAM16.
|
|
310
|
+
}, {
|
|
311
|
+
key: "xyzInViewingConditions",
|
|
312
|
+
value:
|
|
313
|
+
/// XYZ representation of CAM16 seen in [viewingConditions].
|
|
314
|
+
function xyzInViewingConditions(viewingConditions) {
|
|
315
|
+
var alpha = this.chroma === 0.0 || this.j === 0.0 ? 0.0 : this.chroma / Math.sqrt(this.j / 100.0);
|
|
316
|
+
var t = Math.pow(alpha / Math.pow(1.64 - Math.pow(0.29, viewingConditions.n), 0.73), 1.0 / 0.9);
|
|
317
|
+
var hRad = this.hue * Math.PI / 180.0;
|
|
318
|
+
var eHue = 0.25 * (Math.cos(hRad + 2.0) + 3.8);
|
|
319
|
+
var ac = viewingConditions.aw * Math.pow(this.j / 100.0, 1.0 / viewingConditions.c / viewingConditions.z);
|
|
320
|
+
var p1 = eHue * (50000.0 / 13.0) * viewingConditions.nc * viewingConditions.ncb;
|
|
321
|
+
var p2 = ac / viewingConditions.nbb;
|
|
322
|
+
var hSin = Math.sin(hRad);
|
|
323
|
+
var hCos = Math.cos(hRad);
|
|
324
|
+
var gamma = 23.0 * (p2 + 0.305) * t / (23.0 * p1 + 11 * t * hCos + 108.0 * t * hSin);
|
|
325
|
+
var a = gamma * hCos;
|
|
326
|
+
var b = gamma * hSin;
|
|
327
|
+
var rA = (460.0 * p2 + 451.0 * a + 288.0 * b) / 1403.0;
|
|
328
|
+
var gA = (460.0 * p2 - 891.0 * a - 261.0 * b) / 1403.0;
|
|
329
|
+
var bA = (460.0 * p2 - 220.0 * a - 6300.0 * b) / 1403.0;
|
|
330
|
+
var rCBase = Math.max(0, 27.13 * Math.abs(rA) / (400.0 - Math.abs(rA)));
|
|
331
|
+
var rC = math.signum(rA) * (100.0 / viewingConditions.fl) * Math.pow(rCBase, 1.0 / 0.42);
|
|
332
|
+
var gCBase = Math.max(0, 27.13 * Math.abs(gA) / (400.0 - Math.abs(gA)));
|
|
333
|
+
var gC = math.signum(gA) * (100.0 / viewingConditions.fl) * Math.pow(gCBase, 1.0 / 0.42);
|
|
334
|
+
var bCBase = Math.max(0, 27.13 * Math.abs(bA) / (400.0 - Math.abs(bA)));
|
|
335
|
+
var bC = math.signum(bA) * (100.0 / viewingConditions.fl) * Math.pow(bCBase, 1.0 / 0.42);
|
|
336
|
+
var rF = rC / viewingConditions.rgbD[0];
|
|
337
|
+
var gF = gC / viewingConditions.rgbD[1];
|
|
338
|
+
var bF = bC / viewingConditions.rgbD[2];
|
|
339
|
+
var x = 1.86206786 * rF - 1.01125463 * gF + 0.14918677 * bF;
|
|
340
|
+
var y = 0.38752654 * rF + 0.62144744 * gF - 0.00897398 * bF;
|
|
341
|
+
var z = -0.0158415 * rF - 0.03412294 * gF + 1.04996444 * bF;
|
|
342
|
+
return [x, y, z];
|
|
343
|
+
}
|
|
344
|
+
}], [{
|
|
345
|
+
key: "fromInt",
|
|
346
|
+
value: function fromInt(argb) {
|
|
347
|
+
return Cam16.fromIntInViewingConditions(argb, ViewingConditions.DEFAULT);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* @param argb ARGB representation of a color.
|
|
352
|
+
* @param viewingConditions Information about the environment where the color
|
|
353
|
+
* was observed.
|
|
354
|
+
* @return CAM16 color.
|
|
355
|
+
*/
|
|
356
|
+
}, {
|
|
357
|
+
key: "fromIntInViewingConditions",
|
|
358
|
+
value: function fromIntInViewingConditions(argb, viewingConditions) {
|
|
359
|
+
var red = (argb & 0x00ff0000) >> 16;
|
|
360
|
+
var green = (argb & 0x0000ff00) >> 8;
|
|
361
|
+
var blue = argb & 0x000000ff;
|
|
362
|
+
var redL = utils.linearized(red);
|
|
363
|
+
var greenL = utils.linearized(green);
|
|
364
|
+
var blueL = utils.linearized(blue);
|
|
365
|
+
var x = 0.41233895 * redL + 0.35762064 * greenL + 0.18051042 * blueL;
|
|
366
|
+
var y = 0.2126 * redL + 0.7152 * greenL + 0.0722 * blueL;
|
|
367
|
+
var z = 0.01932141 * redL + 0.11916382 * greenL + 0.95034478 * blueL;
|
|
368
|
+
var rC = 0.401288 * x + 0.650173 * y - 0.051461 * z;
|
|
369
|
+
var gC = -0.250268 * x + 1.204414 * y + 0.045854 * z;
|
|
370
|
+
var bC = -0.002079 * x + 0.048952 * y + 0.953127 * z;
|
|
371
|
+
var rD = viewingConditions.rgbD[0] * rC;
|
|
372
|
+
var gD = viewingConditions.rgbD[1] * gC;
|
|
373
|
+
var bD = viewingConditions.rgbD[2] * bC;
|
|
374
|
+
var rAF = Math.pow(viewingConditions.fl * Math.abs(rD) / 100.0, 0.42);
|
|
375
|
+
var gAF = Math.pow(viewingConditions.fl * Math.abs(gD) / 100.0, 0.42);
|
|
376
|
+
var bAF = Math.pow(viewingConditions.fl * Math.abs(bD) / 100.0, 0.42);
|
|
377
|
+
var rA = math.signum(rD) * 400.0 * rAF / (rAF + 27.13);
|
|
378
|
+
var gA = math.signum(gD) * 400.0 * gAF / (gAF + 27.13);
|
|
379
|
+
var bA = math.signum(bD) * 400.0 * bAF / (bAF + 27.13);
|
|
380
|
+
var a = (11.0 * rA + -12.0 * gA + bA) / 11.0;
|
|
381
|
+
var b = (rA + gA - 2.0 * bA) / 9.0;
|
|
382
|
+
var u = (20.0 * rA + 20.0 * gA + 21.0 * bA) / 20.0;
|
|
383
|
+
var p2 = (40.0 * rA + 20.0 * gA + bA) / 20.0;
|
|
384
|
+
var atan2 = Math.atan2(b, a);
|
|
385
|
+
var atanDegrees = atan2 * 180.0 / Math.PI;
|
|
386
|
+
var hue = atanDegrees < 0 ? atanDegrees + 360.0 : atanDegrees >= 360 ? atanDegrees - 360.0 : atanDegrees;
|
|
387
|
+
var hueRadians = hue * Math.PI / 180.0;
|
|
388
|
+
var ac = p2 * viewingConditions.nbb;
|
|
389
|
+
var j = 100.0 * Math.pow(ac / viewingConditions.aw, viewingConditions.c * viewingConditions.z);
|
|
390
|
+
var q = 4.0 / viewingConditions.c * Math.sqrt(j / 100.0) * (viewingConditions.aw + 4.0) * viewingConditions.fLRoot;
|
|
391
|
+
var huePrime = hue < 20.14 ? hue + 360 : hue;
|
|
392
|
+
var eHue = 0.25 * (Math.cos(huePrime * Math.PI / 180.0 + 2.0) + 3.8);
|
|
393
|
+
var p1 = 50000.0 / 13.0 * eHue * viewingConditions.nc * viewingConditions.ncb;
|
|
394
|
+
var t = p1 * Math.sqrt(a * a + b * b) / (u + 0.305);
|
|
395
|
+
var alpha = Math.pow(t, 0.9) * Math.pow(1.64 - Math.pow(0.29, viewingConditions.n), 0.73);
|
|
396
|
+
var c = alpha * Math.sqrt(j / 100.0);
|
|
397
|
+
var m = c * viewingConditions.fLRoot;
|
|
398
|
+
var s = 50.0 * Math.sqrt(alpha * viewingConditions.c / (viewingConditions.aw + 4.0));
|
|
399
|
+
var jstar = (1.0 + 100.0 * 0.007) * j / (1.0 + 0.007 * j);
|
|
400
|
+
var mstar = 1.0 / 0.0228 * Math.log(1.0 + 0.0228 * m);
|
|
401
|
+
var astar = mstar * Math.cos(hueRadians);
|
|
402
|
+
var bstar = mstar * Math.sin(hueRadians);
|
|
403
|
+
return new Cam16(hue, c, j, q, m, s, jstar, astar, bstar);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* @param j CAM16 lightness
|
|
408
|
+
* @param c CAM16 chroma
|
|
409
|
+
* @param h CAM16 hue
|
|
410
|
+
*/
|
|
411
|
+
}, {
|
|
412
|
+
key: "fromJch",
|
|
413
|
+
value: function fromJch(j, c, h) {
|
|
414
|
+
return Cam16.fromJchInViewingConditions(j, c, h, ViewingConditions.DEFAULT);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* @param j CAM16 lightness
|
|
419
|
+
* @param c CAM16 chroma
|
|
420
|
+
* @param h CAM16 hue
|
|
421
|
+
* @param viewingConditions Information about the environment where the color
|
|
422
|
+
* was observed.
|
|
423
|
+
*/
|
|
424
|
+
}, {
|
|
425
|
+
key: "fromJchInViewingConditions",
|
|
426
|
+
value: function fromJchInViewingConditions(j, c, h, viewingConditions) {
|
|
427
|
+
var q = 4.0 / viewingConditions.c * Math.sqrt(j / 100.0) * (viewingConditions.aw + 4.0) * viewingConditions.fLRoot;
|
|
428
|
+
var m = c * viewingConditions.fLRoot;
|
|
429
|
+
var alpha = c / Math.sqrt(j / 100.0);
|
|
430
|
+
var s = 50.0 * Math.sqrt(alpha * viewingConditions.c / (viewingConditions.aw + 4.0));
|
|
431
|
+
var hueRadians = h * Math.PI / 180.0;
|
|
432
|
+
var jstar = (1.0 + 100.0 * 0.007) * j / (1.0 + 0.007 * j);
|
|
433
|
+
var mstar = 1.0 / 0.0228 * Math.log(1.0 + 0.0228 * m);
|
|
434
|
+
var astar = mstar * Math.cos(hueRadians);
|
|
435
|
+
var bstar = mstar * Math.sin(hueRadians);
|
|
436
|
+
return new Cam16(h, c, j, q, m, s, jstar, astar, bstar);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* @param jstar CAM16-UCS lightness.
|
|
441
|
+
* @param astar CAM16-UCS a dimension. Like a* in L*a*b*, it is a Cartesian
|
|
442
|
+
* coordinate on the Y axis.
|
|
443
|
+
* @param bstar CAM16-UCS b dimension. Like a* in L*a*b*, it is a Cartesian
|
|
444
|
+
* coordinate on the X axis.
|
|
445
|
+
*/
|
|
446
|
+
}, {
|
|
447
|
+
key: "fromUcs",
|
|
448
|
+
value: function fromUcs(jstar, astar, bstar) {
|
|
449
|
+
return Cam16.fromUcsInViewingConditions(jstar, astar, bstar, ViewingConditions.DEFAULT);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* @param jstar CAM16-UCS lightness.
|
|
454
|
+
* @param astar CAM16-UCS a dimension. Like a* in L*a*b*, it is a Cartesian
|
|
455
|
+
* coordinate on the Y axis.
|
|
456
|
+
* @param bstar CAM16-UCS b dimension. Like a* in L*a*b*, it is a Cartesian
|
|
457
|
+
* coordinate on the X axis.
|
|
458
|
+
* @param viewingConditions Information about the environment where the color
|
|
459
|
+
* was observed.
|
|
460
|
+
*/
|
|
461
|
+
}, {
|
|
462
|
+
key: "fromUcsInViewingConditions",
|
|
463
|
+
value: function fromUcsInViewingConditions(jstar, astar, bstar, viewingConditions) {
|
|
464
|
+
var a = astar;
|
|
465
|
+
var b = bstar;
|
|
466
|
+
var m = Math.sqrt(a * a + b * b);
|
|
467
|
+
var M = (Math.exp(m * 0.0228) - 1.0) / 0.0228;
|
|
468
|
+
var c = M / viewingConditions.fLRoot;
|
|
469
|
+
var h = Math.atan2(b, a) * (180.0 / Math.PI);
|
|
470
|
+
if (h < 0.0) {
|
|
471
|
+
h += 360.0;
|
|
472
|
+
}
|
|
473
|
+
var j = jstar / (1 - (jstar - 100) * 0.007);
|
|
474
|
+
return Cam16.fromJchInViewingConditions(j, c, h, viewingConditions);
|
|
475
|
+
}
|
|
476
|
+
}, {
|
|
477
|
+
key: "fromXyzInViewingConditions",
|
|
478
|
+
value: function fromXyzInViewingConditions(x, y, z, viewingConditions) {
|
|
479
|
+
// Transform XYZ to 'cone'/'rgb' responses
|
|
480
|
+
|
|
481
|
+
var rC = 0.401288 * x + 0.650173 * y - 0.051461 * z;
|
|
482
|
+
var gC = -0.250268 * x + 1.204414 * y + 0.045854 * z;
|
|
483
|
+
var bC = -0.002079 * x + 0.048952 * y + 0.953127 * z;
|
|
484
|
+
|
|
485
|
+
// Discount illuminant
|
|
486
|
+
var rD = viewingConditions.rgbD[0] * rC;
|
|
487
|
+
var gD = viewingConditions.rgbD[1] * gC;
|
|
488
|
+
var bD = viewingConditions.rgbD[2] * bC;
|
|
489
|
+
|
|
490
|
+
// chromatic adaptation
|
|
491
|
+
var rAF = Math.pow(viewingConditions.fl * Math.abs(rD) / 100.0, 0.42);
|
|
492
|
+
var gAF = Math.pow(viewingConditions.fl * Math.abs(gD) / 100.0, 0.42);
|
|
493
|
+
var bAF = Math.pow(viewingConditions.fl * Math.abs(bD) / 100.0, 0.42);
|
|
494
|
+
var rA = math.signum(rD) * 400.0 * rAF / (rAF + 27.13);
|
|
495
|
+
var gA = math.signum(gD) * 400.0 * gAF / (gAF + 27.13);
|
|
496
|
+
var bA = math.signum(bD) * 400.0 * bAF / (bAF + 27.13);
|
|
497
|
+
|
|
498
|
+
// redness-greenness
|
|
499
|
+
var a = (11.0 * rA + -12.0 * gA + bA) / 11.0;
|
|
500
|
+
// yellowness-blueness
|
|
501
|
+
var b = (rA + gA - 2.0 * bA) / 9.0;
|
|
502
|
+
|
|
503
|
+
// auxiliary components
|
|
504
|
+
var u = (20.0 * rA + 20.0 * gA + 21.0 * bA) / 20.0;
|
|
505
|
+
var p2 = (40.0 * rA + 20.0 * gA + bA) / 20.0;
|
|
506
|
+
|
|
507
|
+
// hue
|
|
508
|
+
var atan2 = Math.atan2(b, a);
|
|
509
|
+
var atanDegrees = atan2 * 180.0 / Math.PI;
|
|
510
|
+
var hue = atanDegrees < 0 ? atanDegrees + 360.0 : atanDegrees >= 360 ? atanDegrees - 360 : atanDegrees;
|
|
511
|
+
var hueRadians = hue * Math.PI / 180.0;
|
|
512
|
+
|
|
513
|
+
// achromatic response to color
|
|
514
|
+
var ac = p2 * viewingConditions.nbb;
|
|
515
|
+
|
|
516
|
+
// CAM16 lightness and brightness
|
|
517
|
+
var J = 100.0 * Math.pow(ac / viewingConditions.aw, viewingConditions.c * viewingConditions.z);
|
|
518
|
+
var Q = 4.0 / viewingConditions.c * Math.sqrt(J / 100.0) * (viewingConditions.aw + 4.0) * viewingConditions.fLRoot;
|
|
519
|
+
var huePrime = hue < 20.14 ? hue + 360 : hue;
|
|
520
|
+
var eHue = 1.0 / 4.0 * (Math.cos(huePrime * Math.PI / 180.0 + 2.0) + 3.8);
|
|
521
|
+
var p1 = 50000.0 / 13.0 * eHue * viewingConditions.nc * viewingConditions.ncb;
|
|
522
|
+
var t = p1 * Math.sqrt(a * a + b * b) / (u + 0.305);
|
|
523
|
+
var alpha = Math.pow(t, 0.9) * Math.pow(1.64 - Math.pow(0.29, viewingConditions.n), 0.73);
|
|
524
|
+
// CAM16 chroma, colorfulness, chroma
|
|
525
|
+
var C = alpha * Math.sqrt(J / 100.0);
|
|
526
|
+
var M = C * viewingConditions.fLRoot;
|
|
527
|
+
var s = 50.0 * Math.sqrt(alpha * viewingConditions.c / (viewingConditions.aw + 4.0));
|
|
528
|
+
|
|
529
|
+
// CAM16-UCS components
|
|
530
|
+
var jstar = (1.0 + 100.0 * 0.007) * J / (1.0 + 0.007 * J);
|
|
531
|
+
var mstar = Math.log(1.0 + 0.0228 * M) / 0.0228;
|
|
532
|
+
var astar = mstar * Math.cos(hueRadians);
|
|
533
|
+
var bstar = mstar * Math.sin(hueRadians);
|
|
534
|
+
return new Cam16(hue, C, J, Q, M, s, jstar, astar, bstar);
|
|
535
|
+
}
|
|
536
|
+
}]);
|
|
537
|
+
return Cam16;
|
|
538
|
+
}(); // This file is automatically generated. Do not modify it.
|
|
539
|
+
// material_color_utilities is designed to have a consistent API across
|
|
540
|
+
// platforms and modular components that can be moved around easily. Using a
|
|
541
|
+
// class as a namespace facilitates this.
|
|
542
|
+
//
|
|
543
|
+
// tslint:disable:class-as-namespace
|
|
544
|
+
/**
|
|
545
|
+
* A class that solves the HCT equation.
|
|
546
|
+
*/
|
|
547
|
+
var HctSolver = /*#__PURE__*/function () {
|
|
548
|
+
function HctSolver() {
|
|
549
|
+
_classCallCheck(this, HctSolver);
|
|
550
|
+
}
|
|
551
|
+
_createClass(HctSolver, null, [{
|
|
552
|
+
key: "sanitizeRadians",
|
|
553
|
+
value:
|
|
554
|
+
/**
|
|
555
|
+
* Sanitizes a small enough angle in radians.
|
|
556
|
+
*
|
|
557
|
+
* @param angle An angle in radians; must not deviate too much
|
|
558
|
+
* from 0.
|
|
559
|
+
* @return A coterminal angle between 0 and 2pi.
|
|
560
|
+
*/
|
|
561
|
+
function sanitizeRadians(angle) {
|
|
562
|
+
return (angle + Math.PI * 8) % (Math.PI * 2);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* Delinearizes an RGB component, returning a floating-point
|
|
567
|
+
* number.
|
|
568
|
+
*
|
|
569
|
+
* @param rgbComponent 0.0 <= rgb_component <= 100.0, represents
|
|
570
|
+
* linear R/G/B channel
|
|
571
|
+
* @return 0.0 <= output <= 255.0, color channel converted to
|
|
572
|
+
* regular RGB space
|
|
573
|
+
*/
|
|
574
|
+
}, {
|
|
575
|
+
key: "trueDelinearized",
|
|
576
|
+
value: function trueDelinearized(rgbComponent) {
|
|
577
|
+
var normalized = rgbComponent / 100.0;
|
|
578
|
+
var delinearized = 0.0;
|
|
579
|
+
if (normalized <= 0.0031308) {
|
|
580
|
+
delinearized = normalized * 12.92;
|
|
581
|
+
} else {
|
|
582
|
+
delinearized = 1.055 * Math.pow(normalized, 1.0 / 2.4) - 0.055;
|
|
583
|
+
}
|
|
584
|
+
return delinearized * 255.0;
|
|
585
|
+
}
|
|
586
|
+
}, {
|
|
587
|
+
key: "chromaticAdaptation",
|
|
588
|
+
value: function chromaticAdaptation(component) {
|
|
589
|
+
var af = Math.pow(Math.abs(component), 0.42);
|
|
590
|
+
return math.signum(component) * 400.0 * af / (af + 27.13);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* Returns the hue of a linear RGB color in CAM16.
|
|
595
|
+
*
|
|
596
|
+
* @param linrgb The linear RGB coordinates of a color.
|
|
597
|
+
* @return The hue of the color in CAM16, in radians.
|
|
598
|
+
*/
|
|
599
|
+
}, {
|
|
600
|
+
key: "hueOf",
|
|
601
|
+
value: function hueOf(linrgb) {
|
|
602
|
+
var scaledDiscount = math.matrixMultiply(linrgb, HctSolver.SCALED_DISCOUNT_FROM_LINRGB);
|
|
603
|
+
var rA = HctSolver.chromaticAdaptation(scaledDiscount[0]);
|
|
604
|
+
var gA = HctSolver.chromaticAdaptation(scaledDiscount[1]);
|
|
605
|
+
var bA = HctSolver.chromaticAdaptation(scaledDiscount[2]);
|
|
606
|
+
// redness-greenness
|
|
607
|
+
var a = (11.0 * rA + -12.0 * gA + bA) / 11.0;
|
|
608
|
+
// yellowness-blueness
|
|
609
|
+
var b = (rA + gA - 2.0 * bA) / 9.0;
|
|
610
|
+
return Math.atan2(b, a);
|
|
611
|
+
}
|
|
612
|
+
}, {
|
|
613
|
+
key: "areInCyclicOrder",
|
|
614
|
+
value: function areInCyclicOrder(a, b, c) {
|
|
615
|
+
var deltaAB = HctSolver.sanitizeRadians(b - a);
|
|
616
|
+
var deltaAC = HctSolver.sanitizeRadians(c - a);
|
|
617
|
+
return deltaAB < deltaAC;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* Solves the lerp equation.
|
|
622
|
+
*
|
|
623
|
+
* @param source The starting number.
|
|
624
|
+
* @param mid The number in the middle.
|
|
625
|
+
* @param target The ending number.
|
|
626
|
+
* @return A number t such that lerp(source, target, t) = mid.
|
|
627
|
+
*/
|
|
628
|
+
}, {
|
|
629
|
+
key: "intercept",
|
|
630
|
+
value: function intercept(source, mid, target) {
|
|
631
|
+
return (mid - source) / (target - source);
|
|
632
|
+
}
|
|
633
|
+
}, {
|
|
634
|
+
key: "lerpPoint",
|
|
635
|
+
value: function lerpPoint(source, t, target) {
|
|
636
|
+
return [source[0] + (target[0] - source[0]) * t, source[1] + (target[1] - source[1]) * t, source[2] + (target[2] - source[2]) * t];
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* Intersects a segment with a plane.
|
|
641
|
+
*
|
|
642
|
+
* @param source The coordinates of point A.
|
|
643
|
+
* @param coordinate The R-, G-, or B-coordinate of the plane.
|
|
644
|
+
* @param target The coordinates of point B.
|
|
645
|
+
* @param axis The axis the plane is perpendicular with. (0: R, 1:
|
|
646
|
+
* G, 2: B)
|
|
647
|
+
* @return The intersection point of the segment AB with the plane
|
|
648
|
+
* R=coordinate, G=coordinate, or B=coordinate
|
|
649
|
+
*/
|
|
650
|
+
}, {
|
|
651
|
+
key: "setCoordinate",
|
|
652
|
+
value: function setCoordinate(source, coordinate, target, axis) {
|
|
653
|
+
var t = HctSolver.intercept(source[axis], coordinate, target[axis]);
|
|
654
|
+
return HctSolver.lerpPoint(source, t, target);
|
|
655
|
+
}
|
|
656
|
+
}, {
|
|
657
|
+
key: "isBounded",
|
|
658
|
+
value: function isBounded(x) {
|
|
659
|
+
return 0.0 <= x && x <= 100.0;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
/**
|
|
663
|
+
* Returns the nth possible vertex of the polygonal intersection.
|
|
664
|
+
*
|
|
665
|
+
* @param y The Y value of the plane.
|
|
666
|
+
* @param n The zero-based index of the point. 0 <= n <= 11.
|
|
667
|
+
* @return The nth possible vertex of the polygonal intersection
|
|
668
|
+
* of the y plane and the RGB cube, in linear RGB coordinates, if
|
|
669
|
+
* it exists. If this possible vertex lies outside of the cube,
|
|
670
|
+
* [-1.0, -1.0, -1.0] is returned.
|
|
671
|
+
*/
|
|
672
|
+
}, {
|
|
673
|
+
key: "nthVertex",
|
|
674
|
+
value: function nthVertex(y, n) {
|
|
675
|
+
var kR = HctSolver.Y_FROM_LINRGB[0];
|
|
676
|
+
var kG = HctSolver.Y_FROM_LINRGB[1];
|
|
677
|
+
var kB = HctSolver.Y_FROM_LINRGB[2];
|
|
678
|
+
var coordA = n % 4 <= 1 ? 0.0 : 100.0;
|
|
679
|
+
var coordB = n % 2 === 0 ? 0.0 : 100.0;
|
|
680
|
+
if (n < 4) {
|
|
681
|
+
var g = coordA;
|
|
682
|
+
var b = coordB;
|
|
683
|
+
var r = (y - g * kG - b * kB) / kR;
|
|
684
|
+
if (HctSolver.isBounded(r)) {
|
|
685
|
+
return [r, g, b];
|
|
686
|
+
} else {
|
|
687
|
+
return [-1.0, -1.0, -1.0];
|
|
688
|
+
}
|
|
689
|
+
} else if (n < 8) {
|
|
690
|
+
var _b = coordA;
|
|
691
|
+
var _r = coordB;
|
|
692
|
+
var _g = (y - _r * kR - _b * kB) / kG;
|
|
693
|
+
if (HctSolver.isBounded(_g)) {
|
|
694
|
+
return [_r, _g, _b];
|
|
695
|
+
} else {
|
|
696
|
+
return [-1.0, -1.0, -1.0];
|
|
697
|
+
}
|
|
698
|
+
} else {
|
|
699
|
+
var _r2 = coordA;
|
|
700
|
+
var _g2 = coordB;
|
|
701
|
+
var _b2 = (y - _r2 * kR - _g2 * kG) / kB;
|
|
702
|
+
if (HctSolver.isBounded(_b2)) {
|
|
703
|
+
return [_r2, _g2, _b2];
|
|
704
|
+
} else {
|
|
705
|
+
return [-1.0, -1.0, -1.0];
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
/**
|
|
711
|
+
* Finds the segment containing the desired color.
|
|
712
|
+
*
|
|
713
|
+
* @param y The Y value of the color.
|
|
714
|
+
* @param targetHue The hue of the color.
|
|
715
|
+
* @return A list of two sets of linear RGB coordinates, each
|
|
716
|
+
* corresponding to an endpoint of the segment containing the
|
|
717
|
+
* desired color.
|
|
718
|
+
*/
|
|
719
|
+
}, {
|
|
720
|
+
key: "bisectToSegment",
|
|
721
|
+
value: function bisectToSegment(y, targetHue) {
|
|
722
|
+
var left = [-1.0, -1.0, -1.0];
|
|
723
|
+
var right = left;
|
|
724
|
+
var leftHue = 0.0;
|
|
725
|
+
var rightHue = 0.0;
|
|
726
|
+
var initialized = false;
|
|
727
|
+
var uncut = true;
|
|
728
|
+
for (var _n = 0; _n < 12; _n++) {
|
|
729
|
+
var mid = HctSolver.nthVertex(y, _n);
|
|
730
|
+
if (mid[0] < 0) {
|
|
731
|
+
continue;
|
|
732
|
+
}
|
|
733
|
+
var midHue = HctSolver.hueOf(mid);
|
|
734
|
+
if (!initialized) {
|
|
735
|
+
left = mid;
|
|
736
|
+
right = mid;
|
|
737
|
+
leftHue = midHue;
|
|
738
|
+
rightHue = midHue;
|
|
739
|
+
initialized = true;
|
|
740
|
+
continue;
|
|
741
|
+
}
|
|
742
|
+
if (uncut || HctSolver.areInCyclicOrder(leftHue, midHue, rightHue)) {
|
|
743
|
+
uncut = false;
|
|
744
|
+
if (HctSolver.areInCyclicOrder(leftHue, targetHue, midHue)) {
|
|
745
|
+
right = mid;
|
|
746
|
+
rightHue = midHue;
|
|
747
|
+
} else {
|
|
748
|
+
left = mid;
|
|
749
|
+
leftHue = midHue;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
return [left, right];
|
|
754
|
+
}
|
|
755
|
+
}, {
|
|
756
|
+
key: "midpoint",
|
|
757
|
+
value: function midpoint(a, b) {
|
|
758
|
+
return [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2, (a[2] + b[2]) / 2];
|
|
759
|
+
}
|
|
760
|
+
}, {
|
|
761
|
+
key: "criticalPlaneBelow",
|
|
762
|
+
value: function criticalPlaneBelow(x) {
|
|
763
|
+
return Math.floor(x - 0.5);
|
|
764
|
+
}
|
|
765
|
+
}, {
|
|
766
|
+
key: "criticalPlaneAbove",
|
|
767
|
+
value: function criticalPlaneAbove(x) {
|
|
768
|
+
return Math.ceil(x - 0.5);
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
/**
|
|
772
|
+
* Finds a color with the given Y and hue on the boundary of the
|
|
773
|
+
* cube.
|
|
774
|
+
*
|
|
775
|
+
* @param y The Y value of the color.
|
|
776
|
+
* @param targetHue The hue of the color.
|
|
777
|
+
* @return The desired color, in linear RGB coordinates.
|
|
778
|
+
*/
|
|
779
|
+
}, {
|
|
780
|
+
key: "bisectToLimit",
|
|
781
|
+
value: function bisectToLimit(y, targetHue) {
|
|
782
|
+
var segment = HctSolver.bisectToSegment(y, targetHue);
|
|
783
|
+
var left = segment[0];
|
|
784
|
+
var leftHue = HctSolver.hueOf(left);
|
|
785
|
+
var right = segment[1];
|
|
786
|
+
for (var axis = 0; axis < 3; axis++) {
|
|
787
|
+
if (left[axis] !== right[axis]) {
|
|
788
|
+
var lPlane = -1;
|
|
789
|
+
var rPlane = 255;
|
|
790
|
+
if (left[axis] < right[axis]) {
|
|
791
|
+
lPlane = HctSolver.criticalPlaneBelow(HctSolver.trueDelinearized(left[axis]));
|
|
792
|
+
rPlane = HctSolver.criticalPlaneAbove(HctSolver.trueDelinearized(right[axis]));
|
|
793
|
+
} else {
|
|
794
|
+
lPlane = HctSolver.criticalPlaneAbove(HctSolver.trueDelinearized(left[axis]));
|
|
795
|
+
rPlane = HctSolver.criticalPlaneBelow(HctSolver.trueDelinearized(right[axis]));
|
|
796
|
+
}
|
|
797
|
+
for (var i = 0; i < 8; i++) {
|
|
798
|
+
if (Math.abs(rPlane - lPlane) <= 1) {
|
|
799
|
+
break;
|
|
800
|
+
} else {
|
|
801
|
+
var mPlane = Math.floor((lPlane + rPlane) / 2.0);
|
|
802
|
+
var midPlaneCoordinate = HctSolver.CRITICAL_PLANES[mPlane];
|
|
803
|
+
var mid = HctSolver.setCoordinate(left, midPlaneCoordinate, right, axis);
|
|
804
|
+
var midHue = HctSolver.hueOf(mid);
|
|
805
|
+
if (HctSolver.areInCyclicOrder(leftHue, targetHue, midHue)) {
|
|
806
|
+
right = mid;
|
|
807
|
+
rPlane = mPlane;
|
|
808
|
+
} else {
|
|
809
|
+
left = mid;
|
|
810
|
+
leftHue = midHue;
|
|
811
|
+
lPlane = mPlane;
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
return HctSolver.midpoint(left, right);
|
|
818
|
+
}
|
|
819
|
+
}, {
|
|
820
|
+
key: "inverseChromaticAdaptation",
|
|
821
|
+
value: function inverseChromaticAdaptation(adapted) {
|
|
822
|
+
var adaptedAbs = Math.abs(adapted);
|
|
823
|
+
var base = Math.max(0, 27.13 * adaptedAbs / (400.0 - adaptedAbs));
|
|
824
|
+
return math.signum(adapted) * Math.pow(base, 1.0 / 0.42);
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
/**
|
|
828
|
+
* Finds a color with the given hue, chroma, and Y.
|
|
829
|
+
*
|
|
830
|
+
* @param hueRadians The desired hue in radians.
|
|
831
|
+
* @param chroma The desired chroma.
|
|
832
|
+
* @param y The desired Y.
|
|
833
|
+
* @return The desired color as a hexadecimal integer, if found; 0
|
|
834
|
+
* otherwise.
|
|
835
|
+
*/
|
|
836
|
+
}, {
|
|
837
|
+
key: "findResultByJ",
|
|
838
|
+
value: function findResultByJ(hueRadians, chroma, y) {
|
|
839
|
+
// Initial estimate of j.
|
|
840
|
+
var j = Math.sqrt(y) * 11.0;
|
|
841
|
+
// ===========================================================
|
|
842
|
+
// Operations inlined from Cam16 to avoid repeated calculation
|
|
843
|
+
// ===========================================================
|
|
844
|
+
var viewingConditions = ViewingConditions.DEFAULT;
|
|
845
|
+
var tInnerCoeff = 1 / Math.pow(1.64 - Math.pow(0.29, viewingConditions.n), 0.73);
|
|
846
|
+
var eHue = 0.25 * (Math.cos(hueRadians + 2.0) + 3.8);
|
|
847
|
+
var p1 = eHue * (50000.0 / 13.0) * viewingConditions.nc * viewingConditions.ncb;
|
|
848
|
+
var hSin = Math.sin(hueRadians);
|
|
849
|
+
var hCos = Math.cos(hueRadians);
|
|
850
|
+
for (var iterationRound = 0; iterationRound < 5; iterationRound++) {
|
|
851
|
+
// ===========================================================
|
|
852
|
+
// Operations inlined from Cam16 to avoid repeated calculation
|
|
853
|
+
// ===========================================================
|
|
854
|
+
var jNormalized = j / 100.0;
|
|
855
|
+
var alpha = chroma === 0.0 || j === 0.0 ? 0.0 : chroma / Math.sqrt(jNormalized);
|
|
856
|
+
var t = Math.pow(alpha * tInnerCoeff, 1.0 / 0.9);
|
|
857
|
+
var ac = viewingConditions.aw * Math.pow(jNormalized, 1.0 / viewingConditions.c / viewingConditions.z);
|
|
858
|
+
var p2 = ac / viewingConditions.nbb;
|
|
859
|
+
var gamma = 23.0 * (p2 + 0.305) * t / (23.0 * p1 + 11 * t * hCos + 108.0 * t * hSin);
|
|
860
|
+
var a = gamma * hCos;
|
|
861
|
+
var b = gamma * hSin;
|
|
862
|
+
var rA = (460.0 * p2 + 451.0 * a + 288.0 * b) / 1403.0;
|
|
863
|
+
var gA = (460.0 * p2 - 891.0 * a - 261.0 * b) / 1403.0;
|
|
864
|
+
var bA = (460.0 * p2 - 220.0 * a - 6300.0 * b) / 1403.0;
|
|
865
|
+
var rCScaled = HctSolver.inverseChromaticAdaptation(rA);
|
|
866
|
+
var gCScaled = HctSolver.inverseChromaticAdaptation(gA);
|
|
867
|
+
var bCScaled = HctSolver.inverseChromaticAdaptation(bA);
|
|
868
|
+
var linrgb = math.matrixMultiply([rCScaled, gCScaled, bCScaled], HctSolver.LINRGB_FROM_SCALED_DISCOUNT);
|
|
869
|
+
// ===========================================================
|
|
870
|
+
// Operations inlined from Cam16 to avoid repeated calculation
|
|
871
|
+
// ===========================================================
|
|
872
|
+
if (linrgb[0] < 0 || linrgb[1] < 0 || linrgb[2] < 0) {
|
|
873
|
+
return 0;
|
|
874
|
+
}
|
|
875
|
+
var kR = HctSolver.Y_FROM_LINRGB[0];
|
|
876
|
+
var kG = HctSolver.Y_FROM_LINRGB[1];
|
|
877
|
+
var kB = HctSolver.Y_FROM_LINRGB[2];
|
|
878
|
+
var fnj = kR * linrgb[0] + kG * linrgb[1] + kB * linrgb[2];
|
|
879
|
+
if (fnj <= 0) {
|
|
880
|
+
return 0;
|
|
881
|
+
}
|
|
882
|
+
if (iterationRound === 4 || Math.abs(fnj - y) < 0.002) {
|
|
883
|
+
if (linrgb[0] > 100.01 || linrgb[1] > 100.01 || linrgb[2] > 100.01) {
|
|
884
|
+
return 0;
|
|
885
|
+
}
|
|
886
|
+
return utils.argbFromLinrgb(linrgb);
|
|
887
|
+
}
|
|
888
|
+
// Iterates with Newton method,
|
|
889
|
+
// Using 2 * fn(j) / j as the approximation of fn'(j)
|
|
890
|
+
j = j - (fnj - y) * j / (2 * fnj);
|
|
891
|
+
}
|
|
892
|
+
return 0;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
/**
|
|
896
|
+
* Finds an sRGB color with the given hue, chroma, and L*, if
|
|
897
|
+
* possible.
|
|
898
|
+
*
|
|
899
|
+
* @param hueDegrees The desired hue, in degrees.
|
|
900
|
+
* @param chroma The desired chroma.
|
|
901
|
+
* @param lstar The desired L*.
|
|
902
|
+
* @return A hexadecimal representing the sRGB color. The color
|
|
903
|
+
* has sufficiently close hue, chroma, and L* to the desired
|
|
904
|
+
* values, if possible; otherwise, the hue and L* will be
|
|
905
|
+
* sufficiently close, and chroma will be maximized.
|
|
906
|
+
*/
|
|
907
|
+
}, {
|
|
908
|
+
key: "solveToInt",
|
|
909
|
+
value: function solveToInt(hueDegrees, chroma, lstar) {
|
|
910
|
+
if (chroma < 0.0001 || lstar < 0.0001 || lstar > 99.9999) {
|
|
911
|
+
return utils.argbFromLstar(lstar);
|
|
912
|
+
}
|
|
913
|
+
hueDegrees = math.sanitizeDegreesDouble(hueDegrees);
|
|
914
|
+
var hueRadians = hueDegrees / 180 * Math.PI;
|
|
915
|
+
var y = utils.yFromLstar(lstar);
|
|
916
|
+
var exactAnswer = HctSolver.findResultByJ(hueRadians, chroma, y);
|
|
917
|
+
if (exactAnswer !== 0) {
|
|
918
|
+
return exactAnswer;
|
|
919
|
+
}
|
|
920
|
+
var linrgb = HctSolver.bisectToLimit(y, hueRadians);
|
|
921
|
+
return utils.argbFromLinrgb(linrgb);
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
/**
|
|
925
|
+
* Finds an sRGB color with the given hue, chroma, and L*, if
|
|
926
|
+
* possible.
|
|
927
|
+
*
|
|
928
|
+
* @param hueDegrees The desired hue, in degrees.
|
|
929
|
+
* @param chroma The desired chroma.
|
|
930
|
+
* @param lstar The desired L*.
|
|
931
|
+
* @return An CAM16 object representing the sRGB color. The color
|
|
932
|
+
* has sufficiently close hue, chroma, and L* to the desired
|
|
933
|
+
* values, if possible; otherwise, the hue and L* will be
|
|
934
|
+
* sufficiently close, and chroma will be maximized.
|
|
935
|
+
*/
|
|
936
|
+
}, {
|
|
937
|
+
key: "solveToCam",
|
|
938
|
+
value: function solveToCam(hueDegrees, chroma, lstar) {
|
|
939
|
+
return Cam16.fromInt(HctSolver.solveToInt(hueDegrees, chroma, lstar));
|
|
940
|
+
}
|
|
941
|
+
}]);
|
|
942
|
+
return HctSolver;
|
|
943
|
+
}();
|
|
944
|
+
_defineProperty(HctSolver, "SCALED_DISCOUNT_FROM_LINRGB", [[0.001200833568784504, 0.002389694492170889, 0.0002795742885861124], [0.0005891086651375999, 0.0029785502573438758, 0.0003270666104008398], [0.00010146692491640572, 0.0005364214359186694, 0.0032979401770712076]]);
|
|
945
|
+
_defineProperty(HctSolver, "LINRGB_FROM_SCALED_DISCOUNT", [[1373.2198709594231, -1100.4251190754821, -7.278681089101213], [-271.815969077903, 559.6580465940733, -32.46047482791194], [1.9622899599665666, -57.173814538844006, 308.7233197812385]]);
|
|
946
|
+
_defineProperty(HctSolver, "Y_FROM_LINRGB", [0.2126, 0.7152, 0.0722]);
|
|
947
|
+
_defineProperty(HctSolver, "CRITICAL_PLANES", [0.015176349177441876, 0.045529047532325624, 0.07588174588720938, 0.10623444424209313, 0.13658714259697685, 0.16693984095186062, 0.19729253930674434, 0.2276452376616281, 0.2579979360165119, 0.28835063437139563, 0.3188300904430532, 0.350925934958123, 0.3848314933096426, 0.42057480301049466, 0.458183274052838, 0.4976837250274023, 0.5391024159806381, 0.5824650784040898, 0.6277969426914107, 0.6751227633498623, 0.7244668422128921, 0.775853049866786, 0.829304845476233, 0.8848452951698498, 0.942497089126609, 1.0022825574869039, 1.0642236851973577, 1.1283421258858297, 1.1946592148522128, 1.2631959812511864, 1.3339731595349034, 1.407011200216447, 1.4823302800086415, 1.5599503113873272, 1.6398909516233677, 1.7221716113234105, 1.8068114625156377, 1.8938294463134073, 1.9832442801866852, 2.075074464868551, 2.1693382909216234, 2.2660538449872063, 2.36523901573795, 2.4669114995532007, 2.5710888059345764, 2.6777882626779785, 2.7870270208169257, 2.898822059350997, 3.0131901897720907, 3.1301480604002863, 3.2497121605402226, 3.3718988244681087, 3.4967242352587946, 3.624204428461639, 3.754355295633311, 3.887192587735158, 4.022731918402185, 4.160988767090289, 4.301978482107941, 4.445716283538092, 4.592217266055746, 4.741496401646282, 4.893568542229298, 5.048448422192488, 5.20615066083972, 5.3666897647573375, 5.5300801301023865, 5.696336044816294, 5.865471690767354, 6.037501145825082, 6.212438385869475, 6.390297286737924, 6.571091626112461, 6.7548350853498045, 6.941541251256611, 7.131223617812143, 7.323895587840543, 7.5195704746346665, 7.7182615035334345, 7.919981813454504, 8.124744458384042, 8.332562408825165, 8.543448553206703, 8.757415699253682, 8.974476575321063, 9.194643831691977, 9.417930041841839, 9.644347703669503, 9.873909240696694, 10.106627003236781, 10.342513269534024, 10.58158024687427, 10.8238400726681, 11.069304815507364, 11.317986476196008, 11.569896988756009, 11.825048221409341, 12.083451977536606, 12.345119996613247, 12.610063955123938, 12.878295467455942, 13.149826086772048, 13.42466730586372, 13.702830557985108, 13.984327217668513, 14.269168601521828, 14.55736596900856, 14.848930523210871, 15.143873411576273, 15.44220572664832, 15.743938506781891, 16.04908273684337, 16.35764934889634, 16.66964922287304, 16.985093187232053, 17.30399201960269, 17.62635644741625, 17.95219714852476, 18.281524751807332, 18.614349837764564, 18.95068293910138, 19.290534541298456, 19.633915083172692, 19.98083495742689, 20.331304511189067, 20.685334046541502, 21.042933821039977, 21.404114048223256, 21.76888489811322, 22.137256497705877, 22.50923893145328, 22.884842241736916, 23.264076429332462, 23.6469514538663, 24.033477234264016, 24.42366364919083, 24.817520537484558, 25.21505769858089, 25.61628489293138, 26.021211842414342, 26.429848230738664, 26.842203703840827, 27.258287870275353, 27.678110301598522, 28.10168053274597, 28.529008062403893, 28.96010235337422, 29.39497283293396, 29.83362889318845, 30.276079891419332, 30.722335150426627, 31.172403958865512, 31.62629557157785, 32.08401920991837, 32.54558406207592, 33.010999283389665, 33.4802739966603, 33.953417292456834, 34.430438229418264, 34.911345834551085, 35.39614910352207, 35.88485700094671, 36.37747846067349, 36.87402238606382, 37.37449765026789, 37.87891309649659, 38.38727753828926, 38.89959975977785, 39.41588851594697, 39.93615253289054, 40.460400508064545, 40.98864111053629, 41.520882981230194, 42.05713473317016, 42.597404951718396, 43.141702194811224, 43.6900349931913, 44.24241185063697, 44.798841244188324, 45.35933162437017, 45.92389141541209, 46.49252901546552, 47.065252796817916, 47.64207110610409, 48.22299226451468, 48.808024568002054, 49.3971762874833, 49.9904556690408, 50.587870934119984, 51.189430279724725, 51.79514187861014, 52.40501387947288, 53.0190544071392, 53.637271562750364, 54.259673423945976, 54.88626804504493, 55.517063457223934, 56.15206766869424, 56.79128866487574, 57.43473440856916, 58.08241284012621, 58.734331877617365, 59.39049941699807, 60.05092333227251, 60.715611475655585, 61.38457167773311, 62.057811747619894, 62.7353394731159, 63.417162620860914, 64.10328893648692, 64.79372614476921, 65.48848194977529, 66.18756403501224, 66.89098006357258, 67.59873767827808, 68.31084450182222, 69.02730813691093, 69.74813616640164, 70.47333615344107, 71.20291564160104, 71.93688215501312, 72.67524319850172, 73.41800625771542, 74.16517879925733, 74.9167682708136, 75.67278210128072, 76.43322770089146, 77.1981124613393, 77.96744375590167, 78.74122893956174, 79.51947534912904, 80.30219030335869, 81.08938110306934, 81.88105503125999, 82.67721935322541, 83.4778813166706, 84.28304815182372, 85.09272707154808, 85.90692527145302, 86.72564993000343, 87.54890820862819, 88.3767072518277, 89.2090541872801, 90.04595612594655, 90.88742016217518, 91.73345337380438, 92.58406282226491, 93.43925555268066, 94.29903859396902, 95.16341895893969, 96.03240364439274, 96.9059996312159, 97.78421388448044, 98.6670533535366, 99.55452497210776]);
|
|
948
|
+
export var ViewingConditions = /*#__PURE__*/function () {
|
|
949
|
+
/**
|
|
950
|
+
* Parameters are intermediate values of the CAM16 conversion process. Their
|
|
951
|
+
* names are shorthand for technical color science terminology, this class
|
|
952
|
+
* would not benefit from documenting them individually. A brief overview
|
|
953
|
+
* is available in the CAM16 specification, and a complete overview requires
|
|
954
|
+
* a color science textbook, such as Fairchild's Color Appearance Models.
|
|
955
|
+
*/
|
|
956
|
+
function ViewingConditions(n, aw, nbb, ncb, c, nc, rgbD, fl, fLRoot, z) {
|
|
957
|
+
_classCallCheck(this, ViewingConditions);
|
|
958
|
+
this.n = n;
|
|
959
|
+
this.aw = aw;
|
|
960
|
+
this.nbb = nbb;
|
|
961
|
+
this.ncb = ncb;
|
|
962
|
+
this.c = c;
|
|
963
|
+
this.nc = nc;
|
|
964
|
+
this.rgbD = rgbD;
|
|
965
|
+
this.fl = fl;
|
|
966
|
+
this.fLRoot = fLRoot;
|
|
967
|
+
this.z = z;
|
|
968
|
+
}
|
|
969
|
+
_createClass(ViewingConditions, null, [{
|
|
970
|
+
key: "make",
|
|
971
|
+
value:
|
|
972
|
+
/**
|
|
973
|
+
* Create ViewingConditions from a simple, physically relevant, set of
|
|
974
|
+
* parameters.
|
|
975
|
+
*
|
|
976
|
+
* @param whitePoint White point, measured in the XYZ color space.
|
|
977
|
+
* default = D65, or sunny day afternoon
|
|
978
|
+
* @param adaptingLuminance The luminance of the adapting field. Informally,
|
|
979
|
+
* how bright it is in the room where the color is viewed. Can be
|
|
980
|
+
* calculated from lux by multiplying lux by 0.0586. default = 11.72,
|
|
981
|
+
* or 200 lux.
|
|
982
|
+
* @param backgroundLstar The lightness of the area surrounding the color.
|
|
983
|
+
* measured by L* in L*a*b*. default = 50.0
|
|
984
|
+
* @param surround A general description of the lighting surrounding the
|
|
985
|
+
* color. 0 is pitch dark, like watching a movie in a theater. 1.0 is a
|
|
986
|
+
* dimly light room, like watching TV at home at night. 2.0 means there
|
|
987
|
+
* is no difference between the lighting on the color and around it.
|
|
988
|
+
* default = 2.0
|
|
989
|
+
* @param discountingIlluminant Whether the eye accounts for the tint of the
|
|
990
|
+
* ambient lighting, such as knowing an apple is still red in green light.
|
|
991
|
+
* default = false, the eye does not perform this process on
|
|
992
|
+
* self-luminous objects like displays.
|
|
993
|
+
*/
|
|
994
|
+
function make() {
|
|
995
|
+
var whitePoint = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : utils.whitePointD65();
|
|
996
|
+
var adaptingLuminance = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 200.0 / Math.PI * utils.yFromLstar(50.0) / 100.0;
|
|
997
|
+
var backgroundLstar = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 50.0;
|
|
998
|
+
var surround = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 2.0;
|
|
999
|
+
var discountingIlluminant = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
1000
|
+
var xyz = whitePoint;
|
|
1001
|
+
var rW = xyz[0] * 0.401288 + xyz[1] * 0.650173 + xyz[2] * -0.051461;
|
|
1002
|
+
var gW = xyz[0] * -0.250268 + xyz[1] * 1.204414 + xyz[2] * 0.045854;
|
|
1003
|
+
var bW = xyz[0] * -0.002079 + xyz[1] * 0.048952 + xyz[2] * 0.953127;
|
|
1004
|
+
var f = 0.8 + surround / 10.0;
|
|
1005
|
+
var c = f >= 0.9 ? math.lerp(0.59, 0.69, (f - 0.9) * 10.0) : math.lerp(0.525, 0.59, (f - 0.8) * 10.0);
|
|
1006
|
+
var d = discountingIlluminant ? 1.0 : f * (1.0 - 1.0 / 3.6 * Math.exp((-adaptingLuminance - 42.0) / 92.0));
|
|
1007
|
+
d = d > 1.0 ? 1.0 : d < 0.0 ? 0.0 : d;
|
|
1008
|
+
var nc = f;
|
|
1009
|
+
var rgbD = [d * (100.0 / rW) + 1.0 - d, d * (100.0 / gW) + 1.0 - d, d * (100.0 / bW) + 1.0 - d];
|
|
1010
|
+
var k = 1.0 / (5.0 * adaptingLuminance + 1.0);
|
|
1011
|
+
var k4 = k * k * k * k;
|
|
1012
|
+
var k4F = 1.0 - k4;
|
|
1013
|
+
var fl = k4 * adaptingLuminance + 0.1 * k4F * k4F * Math.cbrt(5.0 * adaptingLuminance);
|
|
1014
|
+
var n = utils.yFromLstar(backgroundLstar) / whitePoint[1];
|
|
1015
|
+
var z = 1.48 + Math.sqrt(n);
|
|
1016
|
+
var nbb = 0.725 / Math.pow(n, 0.2);
|
|
1017
|
+
var ncb = nbb;
|
|
1018
|
+
var rgbAFactors = [Math.pow(fl * rgbD[0] * rW / 100.0, 0.42), Math.pow(fl * rgbD[1] * gW / 100.0, 0.42), Math.pow(fl * rgbD[2] * bW / 100.0, 0.42)];
|
|
1019
|
+
var rgbA = [400.0 * rgbAFactors[0] / (rgbAFactors[0] + 27.13), 400.0 * rgbAFactors[1] / (rgbAFactors[1] + 27.13), 400.0 * rgbAFactors[2] / (rgbAFactors[2] + 27.13)];
|
|
1020
|
+
var aw = (2.0 * rgbA[0] + rgbA[1] + 0.05 * rgbA[2]) * nbb;
|
|
1021
|
+
return new ViewingConditions(n, aw, nbb, ncb, c, nc, rgbD, fl, Math.pow(fl, 0.25), z);
|
|
1022
|
+
}
|
|
1023
|
+
}]);
|
|
1024
|
+
return ViewingConditions;
|
|
1025
|
+
}();
|
|
1026
|
+
/**
|
|
1027
|
+
* sRGB-like viewing conditions.
|
|
1028
|
+
*/
|
|
1029
|
+
_defineProperty(ViewingConditions, "DEFAULT", ViewingConditions.make());
|