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