@chipmobilesdk/rn-theme 1.2.0 → 1.3.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 +111 -0
- package/README.md +3 -1
- package/lib/commonjs/color/categorical.js +35 -0
- package/lib/commonjs/color/categorical.js.map +1 -0
- package/lib/commonjs/color/contrast.js +199 -0
- package/lib/commonjs/color/contrast.js.map +1 -0
- package/lib/commonjs/color/parse.js +110 -0
- package/lib/commonjs/color/parse.js.map +1 -0
- package/lib/commonjs/color/roles.js +235 -0
- package/lib/commonjs/color/roles.js.map +1 -0
- package/lib/commonjs/index.js +94 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/integration/navigationTheme.js +43 -0
- package/lib/commonjs/integration/navigationTheme.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/presets/byTone.js +28 -0
- package/lib/commonjs/presets/byTone.js.map +1 -0
- package/lib/commonjs/presets/layout.js +67 -0
- package/lib/commonjs/presets/layout.js.map +1 -0
- package/lib/commonjs/presets/themePresets.js +115 -0
- package/lib/commonjs/presets/themePresets.js.map +1 -0
- package/lib/commonjs/theme/buildThemes.js +211 -0
- package/lib/commonjs/theme/buildThemes.js.map +1 -0
- package/lib/commonjs/theme/errors.js +49 -0
- package/lib/commonjs/theme/errors.js.map +1 -0
- package/lib/commonjs/theme/overrides.js +125 -0
- package/lib/commonjs/theme/overrides.js.map +1 -0
- package/lib/commonjs/theme/validateThemeConfig.js +157 -0
- package/lib/commonjs/theme/validateThemeConfig.js.map +1 -0
- package/lib/commonjs/tokens/defaults.js +132 -0
- package/lib/commonjs/tokens/defaults.js.map +1 -0
- package/lib/commonjs/tokens/typography.js +136 -0
- package/lib/commonjs/tokens/typography.js.map +1 -0
- package/lib/commonjs/types/brand.js +2 -0
- package/lib/commonjs/types/brand.js.map +1 -0
- package/lib/commonjs/types/colors.js +2 -0
- package/lib/commonjs/types/colors.js.map +1 -0
- package/lib/commonjs/types/index.js +2 -0
- package/lib/commonjs/types/index.js.map +1 -0
- package/lib/commonjs/types/theme.js +6 -0
- package/lib/commonjs/types/theme.js.map +1 -0
- package/lib/commonjs/types/tokens.js +2 -0
- package/lib/commonjs/types/tokens.js.map +1 -0
- package/lib/commonjs/types/typography.js +2 -0
- package/lib/commonjs/types/typography.js.map +1 -0
- package/lib/commonjs/unistyles/createUnistylesConfig.js +113 -0
- package/lib/commonjs/unistyles/createUnistylesConfig.js.map +1 -0
- package/lib/commonjs/unistyles/themeMode.js +39 -0
- package/lib/commonjs/unistyles/themeMode.js.map +1 -0
- package/lib/commonjs/vendor/mcu/LICENSE +191 -0
- package/lib/commonjs/vendor/mcu/hct/cam16.js +362 -0
- package/lib/commonjs/vendor/mcu/hct/cam16.js.map +1 -0
- package/lib/commonjs/vendor/mcu/hct/hct.js +183 -0
- package/lib/commonjs/vendor/mcu/hct/hct.js.map +1 -0
- package/lib/commonjs/vendor/mcu/hct/hct_solver.js +401 -0
- package/lib/commonjs/vendor/mcu/hct/hct_solver.js.map +1 -0
- package/lib/commonjs/vendor/mcu/hct/viewing_conditions.js +116 -0
- package/lib/commonjs/vendor/mcu/hct/viewing_conditions.js.map +1 -0
- package/lib/commonjs/vendor/mcu/index.js +27 -0
- package/lib/commonjs/vendor/mcu/index.js.map +1 -0
- package/lib/commonjs/vendor/mcu/palettes/tonal_palette.js +177 -0
- package/lib/commonjs/vendor/mcu/palettes/tonal_palette.js.map +1 -0
- package/lib/commonjs/vendor/mcu/utils/color_utils.js +298 -0
- package/lib/commonjs/vendor/mcu/utils/color_utils.js.map +1 -0
- package/lib/commonjs/vendor/mcu/utils/math_utils.js +158 -0
- package/lib/commonjs/vendor/mcu/utils/math_utils.js.map +1 -0
- package/lib/module/color/categorical.js +31 -0
- package/lib/module/color/categorical.js.map +1 -0
- package/lib/module/color/contrast.js +194 -0
- package/lib/module/color/contrast.js.map +1 -0
- package/lib/module/color/parse.js +101 -0
- package/lib/module/color/parse.js.map +1 -0
- package/lib/module/color/roles.js +229 -0
- package/lib/module/color/roles.js.map +1 -0
- package/lib/module/index.js +23 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/integration/navigationTheme.js +39 -0
- package/lib/module/integration/navigationTheme.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/presets/byTone.js +24 -0
- package/lib/module/presets/byTone.js.map +1 -0
- package/lib/module/presets/layout.js +63 -0
- package/lib/module/presets/layout.js.map +1 -0
- package/lib/module/presets/themePresets.js +110 -0
- package/lib/module/presets/themePresets.js.map +1 -0
- package/lib/module/theme/buildThemes.js +208 -0
- package/lib/module/theme/buildThemes.js.map +1 -0
- package/lib/module/theme/errors.js +43 -0
- package/lib/module/theme/errors.js.map +1 -0
- package/lib/module/theme/overrides.js +119 -0
- package/lib/module/theme/overrides.js.map +1 -0
- package/lib/module/theme/validateThemeConfig.js +152 -0
- package/lib/module/theme/validateThemeConfig.js.map +1 -0
- package/lib/module/tokens/defaults.js +120 -0
- package/lib/module/tokens/defaults.js.map +1 -0
- package/lib/module/tokens/typography.js +129 -0
- package/lib/module/tokens/typography.js.map +1 -0
- package/lib/module/types/brand.js +2 -0
- package/lib/module/types/brand.js.map +1 -0
- package/lib/module/types/colors.js +2 -0
- package/lib/module/types/colors.js.map +1 -0
- package/lib/module/types/index.js +2 -0
- package/lib/module/types/index.js.map +1 -0
- package/lib/module/types/theme.js +4 -0
- package/lib/module/types/theme.js.map +1 -0
- package/lib/module/types/tokens.js +2 -0
- package/lib/module/types/tokens.js.map +1 -0
- package/lib/module/types/typography.js +2 -0
- package/lib/module/types/typography.js.map +1 -0
- package/lib/module/unistyles/createUnistylesConfig.js +109 -0
- package/lib/module/unistyles/createUnistylesConfig.js.map +1 -0
- package/lib/module/unistyles/themeMode.js +36 -0
- package/lib/module/unistyles/themeMode.js.map +1 -0
- package/lib/module/vendor/mcu/LICENSE +191 -0
- package/lib/module/vendor/mcu/hct/cam16.js +356 -0
- package/lib/module/vendor/mcu/hct/cam16.js.map +1 -0
- package/lib/module/vendor/mcu/hct/hct.js +178 -0
- package/lib/module/vendor/mcu/hct/hct.js.map +1 -0
- package/lib/module/vendor/mcu/hct/hct_solver.js +396 -0
- package/lib/module/vendor/mcu/hct/hct_solver.js.map +1 -0
- package/lib/module/vendor/mcu/hct/viewing_conditions.js +110 -0
- package/lib/module/vendor/mcu/hct/viewing_conditions.js.map +1 -0
- package/lib/module/vendor/mcu/index.js +8 -0
- package/lib/module/vendor/mcu/index.js.map +1 -0
- package/lib/module/vendor/mcu/palettes/tonal_palette.js +172 -0
- package/lib/module/vendor/mcu/palettes/tonal_palette.js.map +1 -0
- package/lib/module/vendor/mcu/utils/color_utils.js +277 -0
- package/lib/module/vendor/mcu/utils/color_utils.js.map +1 -0
- package/lib/module/vendor/mcu/utils/math_utils.js +146 -0
- package/lib/module/vendor/mcu/utils/math_utils.js.map +1 -0
- package/lib/typescript/commonjs/color/categorical.d.ts +7 -0
- package/lib/typescript/commonjs/color/categorical.d.ts.map +1 -0
- package/lib/typescript/commonjs/color/contrast.d.ts +26 -0
- package/lib/typescript/commonjs/color/contrast.d.ts.map +1 -0
- package/lib/typescript/commonjs/color/parse.d.ts +25 -0
- package/lib/typescript/commonjs/color/parse.d.ts.map +1 -0
- package/lib/typescript/commonjs/color/roles.d.ts +26 -0
- package/lib/typescript/commonjs/color/roles.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +18 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/integration/navigationTheme.d.ts +30 -0
- package/lib/typescript/commonjs/integration/navigationTheme.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/presets/byTone.d.ts +19 -0
- package/lib/typescript/commonjs/presets/byTone.d.ts.map +1 -0
- package/lib/typescript/commonjs/presets/layout.d.ts +63 -0
- package/lib/typescript/commonjs/presets/layout.d.ts.map +1 -0
- package/lib/typescript/commonjs/presets/themePresets.d.ts +11 -0
- package/lib/typescript/commonjs/presets/themePresets.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/buildThemes.d.ts +18 -0
- package/lib/typescript/commonjs/theme/buildThemes.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/errors.d.ts +23 -0
- package/lib/typescript/commonjs/theme/errors.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/overrides.d.ts +11 -0
- package/lib/typescript/commonjs/theme/overrides.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/validateThemeConfig.d.ts +6 -0
- package/lib/typescript/commonjs/theme/validateThemeConfig.d.ts.map +1 -0
- package/lib/typescript/commonjs/tokens/defaults.d.ts +23 -0
- package/lib/typescript/commonjs/tokens/defaults.d.ts.map +1 -0
- package/lib/typescript/commonjs/tokens/typography.d.ts +14 -0
- package/lib/typescript/commonjs/tokens/typography.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/brand.d.ts +21 -0
- package/lib/typescript/commonjs/types/brand.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/colors.d.ts +76 -0
- package/lib/typescript/commonjs/types/colors.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/index.d.ts +6 -0
- package/lib/typescript/commonjs/types/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/theme.d.ts +140 -0
- package/lib/typescript/commonjs/types/theme.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/tokens.d.ts +79 -0
- package/lib/typescript/commonjs/types/tokens.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/typography.d.ts +53 -0
- package/lib/typescript/commonjs/types/typography.d.ts.map +1 -0
- package/lib/typescript/commonjs/unistyles/createUnistylesConfig.d.ts +52 -0
- package/lib/typescript/commonjs/unistyles/createUnistylesConfig.d.ts.map +1 -0
- package/lib/typescript/commonjs/unistyles/themeMode.d.ts +13 -0
- package/lib/typescript/commonjs/unistyles/themeMode.d.ts.map +1 -0
- package/lib/typescript/commonjs/vendor/mcu/hct/cam16.d.ts +132 -0
- package/lib/typescript/commonjs/vendor/mcu/hct/cam16.d.ts.map +1 -0
- package/lib/typescript/commonjs/vendor/mcu/hct/hct.d.ts +93 -0
- package/lib/typescript/commonjs/vendor/mcu/hct/hct.d.ts.map +1 -0
- package/lib/typescript/commonjs/vendor/mcu/hct/hct_solver.d.ts +147 -0
- package/lib/typescript/commonjs/vendor/mcu/hct/hct_solver.d.ts.map +1 -0
- package/lib/typescript/commonjs/vendor/mcu/hct/viewing_conditions.d.ts +75 -0
- package/lib/typescript/commonjs/vendor/mcu/hct/viewing_conditions.d.ts.map +1 -0
- package/lib/typescript/commonjs/vendor/mcu/index.d.ts +4 -0
- package/lib/typescript/commonjs/vendor/mcu/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/vendor/mcu/palettes/tonal_palette.d.ts +56 -0
- package/lib/typescript/commonjs/vendor/mcu/palettes/tonal_palette.d.ts.map +1 -0
- package/lib/typescript/commonjs/vendor/mcu/utils/color_utils.d.ts +129 -0
- package/lib/typescript/commonjs/vendor/mcu/utils/color_utils.d.ts.map +1 -0
- package/lib/typescript/commonjs/vendor/mcu/utils/math_utils.d.ts +83 -0
- package/lib/typescript/commonjs/vendor/mcu/utils/math_utils.d.ts.map +1 -0
- package/lib/typescript/module/color/categorical.d.ts +7 -0
- package/lib/typescript/module/color/categorical.d.ts.map +1 -0
- package/lib/typescript/module/color/contrast.d.ts +26 -0
- package/lib/typescript/module/color/contrast.d.ts.map +1 -0
- package/lib/typescript/module/color/parse.d.ts +25 -0
- package/lib/typescript/module/color/parse.d.ts.map +1 -0
- package/lib/typescript/module/color/roles.d.ts +26 -0
- package/lib/typescript/module/color/roles.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +18 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/integration/navigationTheme.d.ts +30 -0
- package/lib/typescript/module/integration/navigationTheme.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/presets/byTone.d.ts +19 -0
- package/lib/typescript/module/presets/byTone.d.ts.map +1 -0
- package/lib/typescript/module/presets/layout.d.ts +63 -0
- package/lib/typescript/module/presets/layout.d.ts.map +1 -0
- package/lib/typescript/module/presets/themePresets.d.ts +11 -0
- package/lib/typescript/module/presets/themePresets.d.ts.map +1 -0
- package/lib/typescript/module/theme/buildThemes.d.ts +18 -0
- package/lib/typescript/module/theme/buildThemes.d.ts.map +1 -0
- package/lib/typescript/module/theme/errors.d.ts +23 -0
- package/lib/typescript/module/theme/errors.d.ts.map +1 -0
- package/lib/typescript/module/theme/overrides.d.ts +11 -0
- package/lib/typescript/module/theme/overrides.d.ts.map +1 -0
- package/lib/typescript/module/theme/validateThemeConfig.d.ts +6 -0
- package/lib/typescript/module/theme/validateThemeConfig.d.ts.map +1 -0
- package/lib/typescript/module/tokens/defaults.d.ts +23 -0
- package/lib/typescript/module/tokens/defaults.d.ts.map +1 -0
- package/lib/typescript/module/tokens/typography.d.ts +14 -0
- package/lib/typescript/module/tokens/typography.d.ts.map +1 -0
- package/lib/typescript/module/types/brand.d.ts +21 -0
- package/lib/typescript/module/types/brand.d.ts.map +1 -0
- package/lib/typescript/module/types/colors.d.ts +76 -0
- package/lib/typescript/module/types/colors.d.ts.map +1 -0
- package/lib/typescript/module/types/index.d.ts +6 -0
- package/lib/typescript/module/types/index.d.ts.map +1 -0
- package/lib/typescript/module/types/theme.d.ts +140 -0
- package/lib/typescript/module/types/theme.d.ts.map +1 -0
- package/lib/typescript/module/types/tokens.d.ts +79 -0
- package/lib/typescript/module/types/tokens.d.ts.map +1 -0
- package/lib/typescript/module/types/typography.d.ts +53 -0
- package/lib/typescript/module/types/typography.d.ts.map +1 -0
- package/lib/typescript/module/unistyles/createUnistylesConfig.d.ts +52 -0
- package/lib/typescript/module/unistyles/createUnistylesConfig.d.ts.map +1 -0
- package/lib/typescript/module/unistyles/themeMode.d.ts +13 -0
- package/lib/typescript/module/unistyles/themeMode.d.ts.map +1 -0
- package/lib/typescript/module/vendor/mcu/hct/cam16.d.ts +132 -0
- package/lib/typescript/module/vendor/mcu/hct/cam16.d.ts.map +1 -0
- package/lib/typescript/module/vendor/mcu/hct/hct.d.ts +93 -0
- package/lib/typescript/module/vendor/mcu/hct/hct.d.ts.map +1 -0
- package/lib/typescript/module/vendor/mcu/hct/hct_solver.d.ts +147 -0
- package/lib/typescript/module/vendor/mcu/hct/hct_solver.d.ts.map +1 -0
- package/lib/typescript/module/vendor/mcu/hct/viewing_conditions.d.ts +75 -0
- package/lib/typescript/module/vendor/mcu/hct/viewing_conditions.d.ts.map +1 -0
- package/lib/typescript/module/vendor/mcu/index.d.ts +4 -0
- package/lib/typescript/module/vendor/mcu/index.d.ts.map +1 -0
- package/lib/typescript/module/vendor/mcu/palettes/tonal_palette.d.ts +56 -0
- package/lib/typescript/module/vendor/mcu/palettes/tonal_palette.d.ts.map +1 -0
- package/lib/typescript/module/vendor/mcu/utils/color_utils.d.ts +129 -0
- package/lib/typescript/module/vendor/mcu/utils/color_utils.d.ts.map +1 -0
- package/lib/typescript/module/vendor/mcu/utils/math_utils.d.ts +83 -0
- package/lib/typescript/module/vendor/mcu/utils/math_utils.d.ts.map +1 -0
- package/package.json +40 -16
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ViewingConditions = void 0;
|
|
7
|
+
var utils = _interopRequireWildcard(require("../utils/color_utils.js"));
|
|
8
|
+
var math = _interopRequireWildcard(require("../utils/math_utils.js"));
|
|
9
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
10
|
+
/**
|
|
11
|
+
* @license
|
|
12
|
+
* Copyright 2021 Google LLC
|
|
13
|
+
*
|
|
14
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
15
|
+
* you may not use this file except in compliance with the License.
|
|
16
|
+
* You may obtain a copy of the License at
|
|
17
|
+
*
|
|
18
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
19
|
+
*
|
|
20
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
21
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
22
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
23
|
+
* See the License for the specific language governing permissions and
|
|
24
|
+
* limitations under the License.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
// Vendored from material-foundation/material-color-utilities v0.4.0
|
|
28
|
+
// (commit dd62982dfdefdfc9232ce8d76e122fb1c6d188ae, typescript/). Modified:
|
|
29
|
+
// relative import specifiers drop the `.js` suffix so Metro and Jest resolve them.
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* In traditional color spaces, a color can be identified solely by the
|
|
33
|
+
* observer's measurement of the color. Color appearance models such as CAM16
|
|
34
|
+
* also use information about the environment where the color was
|
|
35
|
+
* observed, known as the viewing conditions.
|
|
36
|
+
*
|
|
37
|
+
* For example, white under the traditional assumption of a midday sun white
|
|
38
|
+
* point is accurately measured as a slightly chromatic blue by CAM16. (roughly,
|
|
39
|
+
* hue 203, chroma 3, lightness 100)
|
|
40
|
+
*
|
|
41
|
+
* This class caches intermediate values of the CAM16 conversion process that
|
|
42
|
+
* depend only on viewing conditions, enabling speed ups.
|
|
43
|
+
*/
|
|
44
|
+
class ViewingConditions {
|
|
45
|
+
/** sRGB-like viewing conditions. */
|
|
46
|
+
static DEFAULT = ViewingConditions.make();
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Create ViewingConditions from a simple, physically relevant, set of
|
|
50
|
+
* parameters.
|
|
51
|
+
*
|
|
52
|
+
* @param whitePoint White point, measured in the XYZ color space.
|
|
53
|
+
* default = D65, or sunny day afternoon
|
|
54
|
+
* @param adaptingLuminance The luminance of the adapting field. Informally,
|
|
55
|
+
* how bright it is in the room where the color is viewed. Can be
|
|
56
|
+
* calculated from lux by multiplying lux by 0.0586. default = 11.72,
|
|
57
|
+
* or 200 lux.
|
|
58
|
+
* @param backgroundLstar The lightness of the area surrounding the color.
|
|
59
|
+
* measured by L* in L*a*b*. default = 50.0
|
|
60
|
+
* @param surround A general description of the lighting surrounding the
|
|
61
|
+
* color. 0 is pitch dark, like watching a movie in a theater. 1.0 is a
|
|
62
|
+
* dimly light room, like watching TV at home at night. 2.0 means there
|
|
63
|
+
* is no difference between the lighting on the color and around it.
|
|
64
|
+
* default = 2.0
|
|
65
|
+
* @param discountingIlluminant Whether the eye accounts for the tint of the
|
|
66
|
+
* ambient lighting, such as knowing an apple is still red in green light.
|
|
67
|
+
* default = false, the eye does not perform this process on
|
|
68
|
+
* self-luminous objects like displays.
|
|
69
|
+
*/
|
|
70
|
+
static make(whitePoint = utils.whitePointD65(), adaptingLuminance = 200.0 / Math.PI * utils.yFromLstar(50.0) / 100.0, backgroundLstar = 50.0, surround = 2.0, discountingIlluminant = false) {
|
|
71
|
+
const xyz = whitePoint;
|
|
72
|
+
const rW = xyz[0] * 0.401288 + xyz[1] * 0.650173 + xyz[2] * -0.051461;
|
|
73
|
+
const gW = xyz[0] * -0.250268 + xyz[1] * 1.204414 + xyz[2] * 0.045854;
|
|
74
|
+
const bW = xyz[0] * -0.002079 + xyz[1] * 0.048952 + xyz[2] * 0.953127;
|
|
75
|
+
const f = 0.8 + surround / 10.0;
|
|
76
|
+
const 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);
|
|
77
|
+
let d = discountingIlluminant ? 1.0 : f * (1.0 - 1.0 / 3.6 * Math.exp((-adaptingLuminance - 42.0) / 92.0));
|
|
78
|
+
d = d > 1.0 ? 1.0 : d < 0.0 ? 0.0 : d;
|
|
79
|
+
const nc = f;
|
|
80
|
+
const rgbD = [d * (100.0 / rW) + 1.0 - d, d * (100.0 / gW) + 1.0 - d, d * (100.0 / bW) + 1.0 - d];
|
|
81
|
+
const k = 1.0 / (5.0 * adaptingLuminance + 1.0);
|
|
82
|
+
const k4 = k * k * k * k;
|
|
83
|
+
const k4F = 1.0 - k4;
|
|
84
|
+
const fl = k4 * adaptingLuminance + 0.1 * k4F * k4F * Math.cbrt(5.0 * adaptingLuminance);
|
|
85
|
+
const n = utils.yFromLstar(backgroundLstar) / whitePoint[1];
|
|
86
|
+
const z = 1.48 + Math.sqrt(n);
|
|
87
|
+
const nbb = 0.725 / Math.pow(n, 0.2);
|
|
88
|
+
const ncb = nbb;
|
|
89
|
+
const 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)];
|
|
90
|
+
const 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)];
|
|
91
|
+
const aw = (2.0 * rgbA[0] + rgbA[1] + 0.05 * rgbA[2]) * nbb;
|
|
92
|
+
return new ViewingConditions(n, aw, nbb, ncb, c, nc, rgbD, fl, Math.pow(fl, 0.25), z);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Parameters are intermediate values of the CAM16 conversion process. Their
|
|
97
|
+
* names are shorthand for technical color science terminology, this class
|
|
98
|
+
* would not benefit from documenting them individually. A brief overview
|
|
99
|
+
* is available in the CAM16 specification, and a complete overview requires
|
|
100
|
+
* a color science textbook, such as Fairchild's Color Appearance Models.
|
|
101
|
+
*/
|
|
102
|
+
constructor(n, aw, nbb, ncb, c, nc, rgbD, fl, fLRoot, z) {
|
|
103
|
+
this.n = n;
|
|
104
|
+
this.aw = aw;
|
|
105
|
+
this.nbb = nbb;
|
|
106
|
+
this.ncb = ncb;
|
|
107
|
+
this.c = c;
|
|
108
|
+
this.nc = nc;
|
|
109
|
+
this.rgbD = rgbD;
|
|
110
|
+
this.fl = fl;
|
|
111
|
+
this.fLRoot = fLRoot;
|
|
112
|
+
this.z = z;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.ViewingConditions = ViewingConditions;
|
|
116
|
+
//# sourceMappingURL=viewing_conditions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["utils","_interopRequireWildcard","require","math","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","ViewingConditions","DEFAULT","make","whitePoint","whitePointD65","adaptingLuminance","Math","PI","yFromLstar","backgroundLstar","surround","discountingIlluminant","xyz","rW","gW","bW","c","lerp","d","exp","nc","rgbD","k","k4","k4F","fl","cbrt","z","sqrt","nbb","pow","ncb","rgbAFactors","rgbA","aw","constructor","fLRoot","exports"],"sourceRoot":"../../../../../src","sources":["vendor/mcu/hct/viewing_conditions.ts"],"mappings":";;;;;;AAoBA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,IAAA,GAAAF,uBAAA,CAAAC,OAAA;AAA4C,SAAAD,wBAAAG,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAL,uBAAA,YAAAA,CAAAG,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SA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AAACU,OAAA,CAAArC,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "Hct", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _hct.Hct;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "TonalPalette", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _tonal_palette.TonalPalette;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "argbFromRgb", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _color_utils.argbFromRgb;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
var _hct = require("./hct/hct.js");
|
|
25
|
+
var _tonal_palette = require("./palettes/tonal_palette.js");
|
|
26
|
+
var _color_utils = require("./utils/color_utils.js");
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_hct","require","_tonal_palette","_color_utils"],"sourceRoot":"../../../../src","sources":["vendor/mcu/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.TonalPalette = void 0;
|
|
7
|
+
var _hct = require("../hct/hct.js");
|
|
8
|
+
/**
|
|
9
|
+
* @license
|
|
10
|
+
* Copyright 2021 Google LLC
|
|
11
|
+
*
|
|
12
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
* you may not use this file except in compliance with the License.
|
|
14
|
+
* You may obtain a copy of the License at
|
|
15
|
+
*
|
|
16
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
+
* See the License for the specific language governing permissions and
|
|
22
|
+
* limitations under the License.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
// Vendored from material-foundation/material-color-utilities v0.4.0
|
|
26
|
+
// (commit dd62982dfdefdfc9232ce8d76e122fb1c6d188ae, typescript/). Modified:
|
|
27
|
+
// relative import specifiers drop the `.js` suffix so Metro and Jest resolve them.
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A convenience class for retrieving colors that are constant in hue and
|
|
31
|
+
* chroma, but vary in tone.
|
|
32
|
+
*/
|
|
33
|
+
class TonalPalette {
|
|
34
|
+
cache = new Map();
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param argb ARGB representation of a color
|
|
38
|
+
* @return Tones matching that color's hue and chroma.
|
|
39
|
+
*/
|
|
40
|
+
static fromInt(argb) {
|
|
41
|
+
const hct = _hct.Hct.fromInt(argb);
|
|
42
|
+
return TonalPalette.fromHct(hct);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @param hct Hct
|
|
47
|
+
* @return Tones matching that color's hue and chroma.
|
|
48
|
+
*/
|
|
49
|
+
static fromHct(hct) {
|
|
50
|
+
return new TonalPalette(hct.hue, hct.chroma, hct);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @param hue HCT hue
|
|
55
|
+
* @param chroma HCT chroma
|
|
56
|
+
* @return Tones matching hue and chroma.
|
|
57
|
+
*/
|
|
58
|
+
static fromHueAndChroma(hue, chroma) {
|
|
59
|
+
const keyColor = new KeyColor(hue, chroma).create();
|
|
60
|
+
return new TonalPalette(hue, chroma, keyColor);
|
|
61
|
+
}
|
|
62
|
+
constructor(hue, chroma, keyColor) {
|
|
63
|
+
this.hue = hue;
|
|
64
|
+
this.chroma = chroma;
|
|
65
|
+
this.keyColor = keyColor;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @param tone HCT tone, measured from 0 to 100.
|
|
70
|
+
* @return ARGB representation of a color with that tone.
|
|
71
|
+
*/
|
|
72
|
+
tone(tone) {
|
|
73
|
+
let argb = this.cache.get(tone);
|
|
74
|
+
if (argb === undefined) {
|
|
75
|
+
if (tone == 99 && _hct.Hct.isYellow(this.hue)) {
|
|
76
|
+
argb = this.averageArgb(this.tone(98), this.tone(100));
|
|
77
|
+
} else {
|
|
78
|
+
argb = _hct.Hct.from(this.hue, this.chroma, tone).toInt();
|
|
79
|
+
}
|
|
80
|
+
this.cache.set(tone, argb);
|
|
81
|
+
}
|
|
82
|
+
return argb;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @param tone HCT tone.
|
|
87
|
+
* @return HCT representation of a color with that tone.
|
|
88
|
+
*/
|
|
89
|
+
getHct(tone) {
|
|
90
|
+
return _hct.Hct.fromInt(this.tone(tone));
|
|
91
|
+
}
|
|
92
|
+
averageArgb(argb1, argb2) {
|
|
93
|
+
const red1 = argb1 >>> 16 & 0xff;
|
|
94
|
+
const green1 = argb1 >>> 8 & 0xff;
|
|
95
|
+
const blue1 = argb1 & 0xff;
|
|
96
|
+
const red2 = argb2 >>> 16 & 0xff;
|
|
97
|
+
const green2 = argb2 >>> 8 & 0xff;
|
|
98
|
+
const blue2 = argb2 & 0xff;
|
|
99
|
+
const red = Math.round((red1 + red2) / 2);
|
|
100
|
+
const green = Math.round((green1 + green2) / 2);
|
|
101
|
+
const blue = Math.round((blue1 + blue2) / 2);
|
|
102
|
+
return (255 << 24 | (red & 255) << 16 | (green & 255) << 8 | blue & 255) >>> 0;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Key color is a color that represents the hue and chroma of a tonal palette
|
|
108
|
+
*/
|
|
109
|
+
exports.TonalPalette = TonalPalette;
|
|
110
|
+
class KeyColor {
|
|
111
|
+
// Cache that maps tone to max chroma to avoid duplicated HCT calculation.
|
|
112
|
+
chromaCache = new Map();
|
|
113
|
+
maxChromaValue = 200.0;
|
|
114
|
+
constructor(hue, requestedChroma) {
|
|
115
|
+
this.hue = hue;
|
|
116
|
+
this.requestedChroma = requestedChroma;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Creates a key color from a [hue] and a [chroma].
|
|
121
|
+
* The key color is the first tone, starting from T50, matching the given hue
|
|
122
|
+
* and chroma.
|
|
123
|
+
*
|
|
124
|
+
* @return Key color [Hct]
|
|
125
|
+
*/
|
|
126
|
+
create() {
|
|
127
|
+
// Pivot around T50 because T50 has the most chroma available, on
|
|
128
|
+
// average. Thus it is most likely to have a direct answer.
|
|
129
|
+
const pivotTone = 50;
|
|
130
|
+
const toneStepSize = 1;
|
|
131
|
+
// Epsilon to accept values slightly higher than the requested chroma.
|
|
132
|
+
const epsilon = 0.01;
|
|
133
|
+
|
|
134
|
+
// Binary search to find the tone that can provide a chroma that is closest
|
|
135
|
+
// to the requested chroma.
|
|
136
|
+
let lowerTone = 0;
|
|
137
|
+
let upperTone = 100;
|
|
138
|
+
while (lowerTone < upperTone) {
|
|
139
|
+
const midTone = Math.floor((lowerTone + upperTone) / 2);
|
|
140
|
+
const isAscending = this.maxChroma(midTone) < this.maxChroma(midTone + toneStepSize);
|
|
141
|
+
const sufficientChroma = this.maxChroma(midTone) >= this.requestedChroma - epsilon;
|
|
142
|
+
if (sufficientChroma) {
|
|
143
|
+
// Either range [lowerTone, midTone] or [midTone, upperTone] has
|
|
144
|
+
// the answer, so search in the range that is closer the pivot tone.
|
|
145
|
+
if (Math.abs(lowerTone - pivotTone) < Math.abs(upperTone - pivotTone)) {
|
|
146
|
+
upperTone = midTone;
|
|
147
|
+
} else {
|
|
148
|
+
if (lowerTone === midTone) {
|
|
149
|
+
return _hct.Hct.from(this.hue, this.requestedChroma, lowerTone);
|
|
150
|
+
}
|
|
151
|
+
lowerTone = midTone;
|
|
152
|
+
}
|
|
153
|
+
} else {
|
|
154
|
+
// As there is no sufficient chroma in the midTone, follow the direction
|
|
155
|
+
// to the chroma peak.
|
|
156
|
+
if (isAscending) {
|
|
157
|
+
lowerTone = midTone + toneStepSize;
|
|
158
|
+
} else {
|
|
159
|
+
// Keep midTone for potential chroma peak.
|
|
160
|
+
upperTone = midTone;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return _hct.Hct.from(this.hue, this.requestedChroma, lowerTone);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Find the maximum chroma for a given tone
|
|
168
|
+
maxChroma(tone) {
|
|
169
|
+
if (this.chromaCache.has(tone)) {
|
|
170
|
+
return this.chromaCache.get(tone);
|
|
171
|
+
}
|
|
172
|
+
const chroma = _hct.Hct.from(this.hue, this.maxChromaValue, tone).chroma;
|
|
173
|
+
this.chromaCache.set(tone, chroma);
|
|
174
|
+
return chroma;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=tonal_palette.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_hct","require","TonalPalette","cache","Map","fromInt","argb","hct","Hct","fromHct","hue","chroma","fromHueAndChroma","keyColor","KeyColor","create","constructor","tone","get","undefined","isYellow","averageArgb","from","toInt","set","getHct","argb1","argb2","red1","green1","blue1","red2","green2","blue2","red","Math","round","green","blue","exports","chromaCache","maxChromaValue","requestedChroma","pivotTone","toneStepSize","epsilon","lowerTone","upperTone","midTone","floor","isAscending","maxChroma","sufficientChroma","abs","has"],"sourceRoot":"../../../../../src","sources":["vendor/mcu/palettes/tonal_palette.ts"],"mappings":";;;;;;AAoBA,IAAAA,IAAA,GAAAC,OAAA;AApBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACO,MAAMC,YAAY,CAAC;EACPC,KAAK,GAAG,IAAIC,GAAG,CAAiB,CAAC;;EAElD;AACF;AACA;AACA;EACE,OAAOC,OAAOA,CAACC,IAAY,EAAgB;IACzC,MAAMC,GAAG,GAAGC,QAAG,CAACH,OAAO,CAACC,IAAI,CAAC;IAC7B,OAAOJ,YAAY,CAACO,OAAO,CAACF,GAAG,CAAC;EAClC;;EAEA;AACF;AACA;AACA;EACE,OAAOE,OAAOA,CAACF,GAAQ,EAAE;IACvB,OAAO,IAAIL,YAAY,CAACK,GAAG,CAACG,GAAG,EAAEH,GAAG,CAACI,MAAM,EAAEJ,GAAG,CAAC;EACnD;;EAEA;AACF;AACA;AACA;AACA;EACE,OAAOK,gBAAgBA,CAACF,GAAW,EAAEC,MAAc,EAAgB;IACjE,MAAME,QAAQ,GAAG,IAAIC,QAAQ,CAACJ,GAAG,EAAEC,MAAM,CAAC,CAACI,MAAM,CAAC,CAAC;IACnD,OAAO,IAAIb,YAAY,CAACQ,GAAG,EAAEC,MAAM,EAAEE,QAAQ,CAAC;EAChD;EAEQG,WAAWA,CACNN,GAAW,EAAWC,MAAc,EAAWE,QAAa,EAAE;IAAA,KAA9DH,GAAW,GAAXA,GAAW;IAAA,KAAWC,MAAc,GAAdA,MAAc;IAAA,KAAWE,QAAa,GAAbA,QAAa;EAAG;;EAE5E;AACF;AACA;AACA;EACEI,IAAIA,CAACA,IAAY,EAAU;IACzB,IAAIX,IAAI,GAAG,IAAI,CAACH,KAAK,CAACe,GAAG,CAACD,IAAI,CAAC;IAC/B,IAAIX,IAAI,KAAKa,SAAS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AACN,SAAS,GAAGJ,SAAS,CAAC,EAAE;UACrEI,SAAS,GAAGC,OAAO;QACrB,CAAC,MAAM;UACL,IAAIF,SAAS,KAAKE,OAAO,EAAE;YACzB,OAAOxC,QAAG,CAACc,IAAI,CAAC,IAAI,CAACZ,GAAG,EAAE,IAAI,CAACgC,eAAe,EAAEI,SAAS,CAAC;UAC5D;UACAA,SAAS,GAAGE,OAAO;QACrB;MACF,CAAC,MAAM;QACL;QACA;QACA,IAAIE,WAAW,EAAE;UACfJ,SAAS,GAAGE,OAAO,GAAGJ,YAAY;QACpC,CAAC,MAAM;UACL;UACAG,SAAS,GAAGC,OAAO;QACrB;MACF;IACF;IAEA,OAAOxC,QAAG,CAACc,IAAI,CAAC,IAAI,CAACZ,GAAG,EAAE,IAAI,CAACgC,eAAe,EAAEI,SAAS,CAAC;EAC5D;;EAEA;EACQK,SAASA,CAAClC,IAAY,EAAU;IACtC,IAAI,IAAI,CAACuB,WAAW,CAACc,GAAG,CAACrC,IAAI,CAAC,EAAE;MAC9B,OAAO,IAAI,CAACuB,WAAW,CAACtB,GAAG,CAACD,IAAI,CAAC;IACnC;IACA,MAAMN,MAAM,GAAGH,QAAG,CAACc,IAAI,CAAC,IAAI,CAACZ,GAAG,EAAE,IAAI,CAAC+B,cAAc,EAAExB,IAAI,CAAC,CAACN,MAAM;IACnE,IAAI,CAAC6B,WAAW,CAAChB,GAAG,CAACP,IAAI,EAAEN,MAAM,CAAC;IAClC,OAAOA,MAAM;EACf;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.alphaFromArgb = alphaFromArgb;
|
|
7
|
+
exports.argbFromLab = argbFromLab;
|
|
8
|
+
exports.argbFromLinrgb = argbFromLinrgb;
|
|
9
|
+
exports.argbFromLstar = argbFromLstar;
|
|
10
|
+
exports.argbFromRgb = argbFromRgb;
|
|
11
|
+
exports.argbFromXyz = argbFromXyz;
|
|
12
|
+
exports.blueFromArgb = blueFromArgb;
|
|
13
|
+
exports.delinearized = delinearized;
|
|
14
|
+
exports.greenFromArgb = greenFromArgb;
|
|
15
|
+
exports.isOpaque = isOpaque;
|
|
16
|
+
exports.labFromArgb = labFromArgb;
|
|
17
|
+
exports.linearized = linearized;
|
|
18
|
+
exports.lstarFromArgb = lstarFromArgb;
|
|
19
|
+
exports.lstarFromY = lstarFromY;
|
|
20
|
+
exports.redFromArgb = redFromArgb;
|
|
21
|
+
exports.whitePointD65 = whitePointD65;
|
|
22
|
+
exports.xyzFromArgb = xyzFromArgb;
|
|
23
|
+
exports.yFromLstar = yFromLstar;
|
|
24
|
+
var mathUtils = _interopRequireWildcard(require("./math_utils.js"));
|
|
25
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
26
|
+
/**
|
|
27
|
+
* @license
|
|
28
|
+
* Copyright 2021 Google LLC
|
|
29
|
+
*
|
|
30
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
31
|
+
* you may not use this file except in compliance with the License.
|
|
32
|
+
* You may obtain a copy of the License at
|
|
33
|
+
*
|
|
34
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
35
|
+
*
|
|
36
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
37
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
38
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
39
|
+
* See the License for the specific language governing permissions and
|
|
40
|
+
* limitations under the License.
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
// Vendored from material-foundation/material-color-utilities v0.4.0
|
|
44
|
+
// (commit dd62982dfdefdfc9232ce8d76e122fb1c6d188ae, typescript/). Modified:
|
|
45
|
+
// relative import specifiers drop the `.js` suffix so Metro and Jest resolve them.
|
|
46
|
+
// This file is automatically generated. Do not modify it.
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Color science utilities.
|
|
50
|
+
*
|
|
51
|
+
* Utility methods for color science constants and color space
|
|
52
|
+
* conversions that aren't HCT or CAM16.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
const SRGB_TO_XYZ = [[0.41233895, 0.35762064, 0.18051042], [0.2126, 0.7152, 0.0722], [0.01932141, 0.11916382, 0.95034478]];
|
|
56
|
+
const XYZ_TO_SRGB = [[3.2413774792388685, -1.5376652402851851, -0.49885366846268053], [-0.9691452513005321, 1.8758853451067872, 0.04156585616912061], [0.05562093689691305, -0.20395524564742123, 1.0571799111220335]];
|
|
57
|
+
const WHITE_POINT_D65 = [95.047, 100.0, 108.883];
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Converts a color from RGB components to ARGB format.
|
|
61
|
+
*/
|
|
62
|
+
function argbFromRgb(red, green, blue) {
|
|
63
|
+
return (255 << 24 | (red & 255) << 16 | (green & 255) << 8 | blue & 255) >>> 0;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Converts a color from linear RGB components to ARGB format.
|
|
68
|
+
*/
|
|
69
|
+
function argbFromLinrgb(linrgb) {
|
|
70
|
+
const r = delinearized(linrgb[0]);
|
|
71
|
+
const g = delinearized(linrgb[1]);
|
|
72
|
+
const b = delinearized(linrgb[2]);
|
|
73
|
+
return argbFromRgb(r, g, b);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Returns the alpha component of a color in ARGB format.
|
|
78
|
+
*/
|
|
79
|
+
function alphaFromArgb(argb) {
|
|
80
|
+
return argb >> 24 & 255;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Returns the red component of a color in ARGB format.
|
|
85
|
+
*/
|
|
86
|
+
function redFromArgb(argb) {
|
|
87
|
+
return argb >> 16 & 255;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Returns the green component of a color in ARGB format.
|
|
92
|
+
*/
|
|
93
|
+
function greenFromArgb(argb) {
|
|
94
|
+
return argb >> 8 & 255;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Returns the blue component of a color in ARGB format.
|
|
99
|
+
*/
|
|
100
|
+
function blueFromArgb(argb) {
|
|
101
|
+
return argb & 255;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Returns whether a color in ARGB format is opaque.
|
|
106
|
+
*/
|
|
107
|
+
function isOpaque(argb) {
|
|
108
|
+
return alphaFromArgb(argb) >= 255;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Converts a color from ARGB to XYZ.
|
|
113
|
+
*/
|
|
114
|
+
function argbFromXyz(x, y, z) {
|
|
115
|
+
const matrix = XYZ_TO_SRGB;
|
|
116
|
+
const linearR = matrix[0][0] * x + matrix[0][1] * y + matrix[0][2] * z;
|
|
117
|
+
const linearG = matrix[1][0] * x + matrix[1][1] * y + matrix[1][2] * z;
|
|
118
|
+
const linearB = matrix[2][0] * x + matrix[2][1] * y + matrix[2][2] * z;
|
|
119
|
+
const r = delinearized(linearR);
|
|
120
|
+
const g = delinearized(linearG);
|
|
121
|
+
const b = delinearized(linearB);
|
|
122
|
+
return argbFromRgb(r, g, b);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Converts a color from XYZ to ARGB.
|
|
127
|
+
*/
|
|
128
|
+
function xyzFromArgb(argb) {
|
|
129
|
+
const r = linearized(redFromArgb(argb));
|
|
130
|
+
const g = linearized(greenFromArgb(argb));
|
|
131
|
+
const b = linearized(blueFromArgb(argb));
|
|
132
|
+
return mathUtils.matrixMultiply([r, g, b], SRGB_TO_XYZ);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Converts a color represented in Lab color space into an ARGB
|
|
137
|
+
* integer.
|
|
138
|
+
*/
|
|
139
|
+
function argbFromLab(l, a, b) {
|
|
140
|
+
const whitePoint = WHITE_POINT_D65;
|
|
141
|
+
const fy = (l + 16.0) / 116.0;
|
|
142
|
+
const fx = a / 500.0 + fy;
|
|
143
|
+
const fz = fy - b / 200.0;
|
|
144
|
+
const xNormalized = labInvf(fx);
|
|
145
|
+
const yNormalized = labInvf(fy);
|
|
146
|
+
const zNormalized = labInvf(fz);
|
|
147
|
+
const x = xNormalized * whitePoint[0];
|
|
148
|
+
const y = yNormalized * whitePoint[1];
|
|
149
|
+
const z = zNormalized * whitePoint[2];
|
|
150
|
+
return argbFromXyz(x, y, z);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Converts a color from ARGB representation to L*a*b*
|
|
155
|
+
* representation.
|
|
156
|
+
*
|
|
157
|
+
* @param argb the ARGB representation of a color
|
|
158
|
+
* @return a Lab object representing the color
|
|
159
|
+
*/
|
|
160
|
+
function labFromArgb(argb) {
|
|
161
|
+
const linearR = linearized(redFromArgb(argb));
|
|
162
|
+
const linearG = linearized(greenFromArgb(argb));
|
|
163
|
+
const linearB = linearized(blueFromArgb(argb));
|
|
164
|
+
const matrix = SRGB_TO_XYZ;
|
|
165
|
+
const x = matrix[0][0] * linearR + matrix[0][1] * linearG + matrix[0][2] * linearB;
|
|
166
|
+
const y = matrix[1][0] * linearR + matrix[1][1] * linearG + matrix[1][2] * linearB;
|
|
167
|
+
const z = matrix[2][0] * linearR + matrix[2][1] * linearG + matrix[2][2] * linearB;
|
|
168
|
+
const whitePoint = WHITE_POINT_D65;
|
|
169
|
+
const xNormalized = x / whitePoint[0];
|
|
170
|
+
const yNormalized = y / whitePoint[1];
|
|
171
|
+
const zNormalized = z / whitePoint[2];
|
|
172
|
+
const fx = labF(xNormalized);
|
|
173
|
+
const fy = labF(yNormalized);
|
|
174
|
+
const fz = labF(zNormalized);
|
|
175
|
+
const l = 116.0 * fy - 16;
|
|
176
|
+
const a = 500.0 * (fx - fy);
|
|
177
|
+
const b = 200.0 * (fy - fz);
|
|
178
|
+
return [l, a, b];
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Converts an L* value to an ARGB representation.
|
|
183
|
+
*
|
|
184
|
+
* @param lstar L* in L*a*b*
|
|
185
|
+
* @return ARGB representation of grayscale color with lightness
|
|
186
|
+
* matching L*
|
|
187
|
+
*/
|
|
188
|
+
function argbFromLstar(lstar) {
|
|
189
|
+
const y = yFromLstar(lstar);
|
|
190
|
+
const component = delinearized(y);
|
|
191
|
+
return argbFromRgb(component, component, component);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Computes the L* value of a color in ARGB representation.
|
|
196
|
+
*
|
|
197
|
+
* @param argb ARGB representation of a color
|
|
198
|
+
* @return L*, from L*a*b*, coordinate of the color
|
|
199
|
+
*/
|
|
200
|
+
function lstarFromArgb(argb) {
|
|
201
|
+
const y = xyzFromArgb(argb)[1];
|
|
202
|
+
return 116.0 * labF(y / 100.0) - 16.0;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Converts an L* value to a Y value.
|
|
207
|
+
*
|
|
208
|
+
* L* in L*a*b* and Y in XYZ measure the same quantity, luminance.
|
|
209
|
+
*
|
|
210
|
+
* L* measures perceptual luminance, a linear scale. Y in XYZ
|
|
211
|
+
* measures relative luminance, a logarithmic scale.
|
|
212
|
+
*
|
|
213
|
+
* @param lstar L* in L*a*b*
|
|
214
|
+
* @return Y in XYZ
|
|
215
|
+
*/
|
|
216
|
+
function yFromLstar(lstar) {
|
|
217
|
+
return 100.0 * labInvf((lstar + 16.0) / 116.0);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Converts a Y value to an L* value.
|
|
222
|
+
*
|
|
223
|
+
* L* in L*a*b* and Y in XYZ measure the same quantity, luminance.
|
|
224
|
+
*
|
|
225
|
+
* L* measures perceptual luminance, a linear scale. Y in XYZ
|
|
226
|
+
* measures relative luminance, a logarithmic scale.
|
|
227
|
+
*
|
|
228
|
+
* @param y Y in XYZ
|
|
229
|
+
* @return L* in L*a*b*
|
|
230
|
+
*/
|
|
231
|
+
function lstarFromY(y) {
|
|
232
|
+
return labF(y / 100.0) * 116.0 - 16.0;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Linearizes an RGB component.
|
|
237
|
+
*
|
|
238
|
+
* @param rgbComponent 0 <= rgb_component <= 255, represents R/G/B
|
|
239
|
+
* channel
|
|
240
|
+
* @return 0.0 <= output <= 100.0, color channel converted to
|
|
241
|
+
* linear RGB space
|
|
242
|
+
*/
|
|
243
|
+
function linearized(rgbComponent) {
|
|
244
|
+
const normalized = rgbComponent / 255.0;
|
|
245
|
+
if (normalized <= 0.040449936) {
|
|
246
|
+
return normalized / 12.92 * 100.0;
|
|
247
|
+
} else {
|
|
248
|
+
return Math.pow((normalized + 0.055) / 1.055, 2.4) * 100.0;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Delinearizes an RGB component.
|
|
254
|
+
*
|
|
255
|
+
* @param rgbComponent 0.0 <= rgb_component <= 100.0, represents
|
|
256
|
+
* linear R/G/B channel
|
|
257
|
+
* @return 0 <= output <= 255, color channel converted to regular
|
|
258
|
+
* RGB space
|
|
259
|
+
*/
|
|
260
|
+
function delinearized(rgbComponent) {
|
|
261
|
+
const normalized = rgbComponent / 100.0;
|
|
262
|
+
let delinearized = 0.0;
|
|
263
|
+
if (normalized <= 0.0031308) {
|
|
264
|
+
delinearized = normalized * 12.92;
|
|
265
|
+
} else {
|
|
266
|
+
delinearized = 1.055 * Math.pow(normalized, 1.0 / 2.4) - 0.055;
|
|
267
|
+
}
|
|
268
|
+
return mathUtils.clampInt(0, 255, Math.round(delinearized * 255.0));
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Returns the standard white point; white on a sunny day.
|
|
273
|
+
*
|
|
274
|
+
* @return The white point
|
|
275
|
+
*/
|
|
276
|
+
function whitePointD65() {
|
|
277
|
+
return WHITE_POINT_D65;
|
|
278
|
+
}
|
|
279
|
+
function labF(t) {
|
|
280
|
+
const e = 216.0 / 24389.0;
|
|
281
|
+
const kappa = 24389.0 / 27.0;
|
|
282
|
+
if (t > e) {
|
|
283
|
+
return Math.pow(t, 1.0 / 3.0);
|
|
284
|
+
} else {
|
|
285
|
+
return (kappa * t + 16) / 116;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function labInvf(ft) {
|
|
289
|
+
const e = 216.0 / 24389.0;
|
|
290
|
+
const kappa = 24389.0 / 27.0;
|
|
291
|
+
const ft3 = ft * ft * ft;
|
|
292
|
+
if (ft3 > e) {
|
|
293
|
+
return ft3;
|
|
294
|
+
} else {
|
|
295
|
+
return (116 * ft - 16) / kappa;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
//# sourceMappingURL=color_utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["mathUtils","_interopRequireWildcard","require","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","SRGB_TO_XYZ","XYZ_TO_SRGB","WHITE_POINT_D65","argbFromRgb","red","green","blue","argbFromLinrgb","linrgb","delinearized","g","b","alphaFromArgb","argb","redFromArgb","greenFromArgb","blueFromArgb","isOpaque","argbFromXyz","x","y","z","matrix","linearR","linearG","linearB","xyzFromArgb","linearized","matrixMultiply","argbFromLab","l","a","whitePoint","fy","fx","fz","xNormalized","labInvf","yNormalized","zNormalized","labFromArgb","labF","argbFromLstar","lstar","yFromLstar","component","lstarFromArgb","lstarFromY","rgbComponent","normalized","Math","pow","clampInt","round","whitePointD65","kappa","ft","ft3"],"sourceRoot":"../../../../../src","sources":["vendor/mcu/utils/color_utils.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsBA,IAAAA,SAAA,GAAAC,uBAAA,CAAAC,OAAA;AAA0C,SAAAD,wBAAAE,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAJ,uBAAA,YAAAA,CAAAE,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAC,CAAA,OAAAM,CAAA,CAAAK,GAAA,IAAAL,CAAA,CAAAM,GAAA,IAAAP,CAAA,CAAAE,CAAA,EAAAP,CAAA,EAAAM,CAAA,IAAAC,CAAA,CAAAP,C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