@basemaps/lambda-tiler 6.16.1 → 6.20.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 +49 -0
- package/LICENSE +2 -2
- package/build/__test__/tile.style.json.test.d.ts +2 -0
- package/build/__test__/tile.style.json.test.d.ts.map +1 -0
- package/build/__test__/tile.style.json.test.js +33 -0
- package/build/__test__/xyz.test.js +35 -34
- package/build/cli/dump.js +2 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +10 -0
- package/build/routes/esri/rest.d.ts +10 -0
- package/build/routes/esri/rest.d.ts.map +1 -0
- package/build/routes/esri/rest.js +87 -0
- package/build/routes/imagery.d.ts +10 -0
- package/build/routes/imagery.d.ts.map +1 -0
- package/build/routes/imagery.js +50 -0
- package/build/routes/response.d.ts +4 -0
- package/build/routes/response.d.ts.map +1 -0
- package/build/routes/response.js +3 -0
- package/build/routes/tile.d.ts +0 -20
- package/build/routes/tile.d.ts.map +1 -1
- package/build/routes/tile.js +11 -164
- package/build/routes/tile.json.d.ts +10 -0
- package/build/routes/tile.json.d.ts.map +1 -0
- package/build/routes/tile.json.js +31 -0
- package/build/routes/tile.style.json.d.ts +10 -0
- package/build/routes/tile.style.json.d.ts.map +1 -0
- package/build/routes/tile.style.json.js +74 -0
- package/build/routes/tile.wmts.d.ts +9 -0
- package/build/routes/tile.wmts.d.ts.map +1 -0
- package/build/routes/tile.wmts.js +57 -0
- package/build/routes/tile.xyz.d.ts +13 -0
- package/build/routes/tile.xyz.d.ts.map +1 -0
- package/build/routes/tile.xyz.js +28 -0
- package/build/tile.set.raster.d.ts +2 -0
- package/build/tile.set.raster.d.ts.map +1 -1
- package/build/tile.set.raster.js +3 -1
- package/build/tile.set.vector.js +1 -1
- package/dist/index.js +10580 -9573
- package/dist/node_modules/color/README.md +7 -7
- package/dist/node_modules/color/index.js +173 -158
- package/dist/node_modules/color/package.json +18 -16
- package/dist/node_modules/color-convert/conversions.js +281 -310
- package/dist/node_modules/color-convert/index.js +27 -24
- package/dist/node_modules/color-convert/package.json +16 -14
- package/dist/node_modules/color-convert/route.js +22 -22
- package/dist/node_modules/color-name/package.json +17 -14
- package/dist/node_modules/color-string/index.js +2 -2
- package/dist/node_modules/color-string/package.json +10 -10
- package/dist/node_modules/decompress-response/index.d.ts +14 -21
- package/dist/node_modules/decompress-response/index.js +34 -16
- package/dist/node_modules/decompress-response/license +1 -1
- package/dist/node_modules/decompress-response/package.json +23 -17
- package/dist/node_modules/decompress-response/readme.md +2 -6
- package/dist/node_modules/detect-libc/package.json +0 -1
- package/dist/node_modules/mimic-response/index.d.ts +2 -2
- package/dist/node_modules/mimic-response/index.js +41 -2
- package/dist/node_modules/mimic-response/package.json +17 -17
- package/dist/node_modules/mimic-response/readme.md +22 -1
- package/dist/node_modules/node-abi/.circleci/config.yml +63 -0
- package/dist/node_modules/node-abi/.releaserc.json +9 -0
- package/dist/node_modules/node-abi/abi_registry.json +39 -4
- package/dist/node_modules/node-abi/index.js +5 -2
- package/dist/node_modules/node-abi/package.json +17 -16
- package/dist/node_modules/node-abi/test/index.js +7 -15
- package/dist/node_modules/node-addon-api/README.md +2 -2
- package/dist/node_modules/node-addon-api/except.gypi +20 -11
- package/dist/node_modules/node-addon-api/napi-inl.h +734 -196
- package/dist/node_modules/node-addon-api/napi.h +420 -164
- package/dist/node_modules/node-addon-api/noexcept.gypi +21 -11
- package/dist/node_modules/node-addon-api/package.json +43 -14
- package/dist/node_modules/node-addon-api/tools/clang-format.js +18 -17
- package/dist/node_modules/node-addon-api/tools/eslint-format.js +71 -0
- package/dist/node_modules/prebuild-install/CHANGELOG.md +24 -7
- package/dist/node_modules/prebuild-install/README.md +24 -4
- package/dist/node_modules/prebuild-install/asset.js +10 -10
- package/dist/node_modules/prebuild-install/bin.js +13 -13
- package/dist/node_modules/prebuild-install/download.js +22 -22
- package/dist/node_modules/prebuild-install/log.js +4 -4
- package/dist/node_modules/prebuild-install/node_modules/detect-libc/LICENSE +201 -0
- package/dist/node_modules/prebuild-install/node_modules/detect-libc/README.md +160 -0
- package/dist/node_modules/prebuild-install/node_modules/detect-libc/index.d.ts +11 -0
- package/dist/node_modules/prebuild-install/node_modules/detect-libc/lib/detect-libc.js +178 -0
- package/dist/node_modules/prebuild-install/node_modules/detect-libc/lib/process.js +16 -0
- package/dist/node_modules/prebuild-install/node_modules/detect-libc/package.json +71 -0
- package/dist/node_modules/prebuild-install/package.json +18 -19
- package/dist/node_modules/prebuild-install/proxy.js +10 -10
- package/dist/node_modules/prebuild-install/rc.js +12 -12
- package/dist/node_modules/prebuild-install/util.js +14 -14
- package/dist/node_modules/semver/package.json +1 -0
- package/dist/node_modules/sharp/README.md +2 -2
- package/dist/node_modules/sharp/binding.gyp +12 -9
- package/dist/node_modules/sharp/build/Release/sharp-linux-x64.node +0 -0
- package/dist/node_modules/sharp/install/dll-copy.js +6 -6
- package/dist/node_modules/sharp/install/libvips.js +4 -8
- package/dist/node_modules/sharp/lib/channel.js +11 -7
- package/dist/node_modules/sharp/lib/colour.js +42 -1
- package/dist/node_modules/sharp/lib/constructor.js +18 -31
- package/dist/node_modules/sharp/lib/input.js +45 -3
- package/dist/node_modules/sharp/lib/is.js +19 -5
- package/dist/node_modules/sharp/lib/libvips.js +4 -19
- package/dist/node_modules/sharp/lib/operation.js +28 -5
- package/dist/node_modules/sharp/lib/output.js +147 -16
- package/dist/node_modules/sharp/lib/sharp.js +31 -0
- package/dist/node_modules/sharp/lib/utility.js +3 -2
- package/dist/node_modules/sharp/package.json +32 -23
- package/dist/node_modules/sharp/src/common.cc +67 -11
- package/dist/node_modules/sharp/src/common.h +25 -5
- package/dist/node_modules/sharp/src/libvips/cplusplus/VConnection.cpp +0 -26
- package/dist/node_modules/sharp/src/libvips/cplusplus/VImage.cpp +54 -16
- package/dist/node_modules/sharp/src/libvips/cplusplus/VInterpolate.cpp +0 -13
- package/dist/node_modules/sharp/src/libvips/cplusplus/vips-operators.cpp +185 -1
- package/dist/node_modules/sharp/src/metadata.cc +14 -0
- package/dist/node_modules/sharp/src/metadata.h +1 -0
- package/dist/node_modules/sharp/src/operations.cc +29 -3
- package/dist/node_modules/sharp/src/operations.h +13 -2
- package/dist/node_modules/sharp/src/pipeline.cc +103 -35
- package/dist/node_modules/sharp/src/pipeline.h +23 -3
- package/dist/node_modules/sharp/src/utilities.cc +1 -1
- package/dist/node_modules/sharp/vendor/{8.10.6 → 8.11.3/linux-x64}/THIRD-PARTY-NOTICES.md +2 -3
- package/dist/node_modules/sharp/vendor/{8.10.6 → 8.11.3/linux-x64}/lib/libvips-cpp.so.42 +0 -0
- package/dist/node_modules/sharp/vendor/{8.10.6 → 8.11.3/linux-x64}/platform.json +0 -0
- package/dist/node_modules/sharp/vendor/8.11.3/linux-x64/versions.json +30 -0
- package/dist/node_modules/simple-get/.github/dependabot.yml +15 -0
- package/dist/node_modules/simple-get/.github/workflows/ci.yml +23 -0
- package/dist/node_modules/simple-get/README.md +17 -3
- package/dist/node_modules/simple-get/index.js +9 -0
- package/dist/node_modules/simple-get/package.json +27 -13
- package/dist/package-lock.json +54 -54
- package/dist/package.json +11 -11
- package/package.json +12 -12
- package/src/__test__/tile.style.json.test.ts +40 -0
- package/src/__test__/xyz.test.ts +43 -41
- package/src/cli/dump.ts +2 -2
- package/src/index.ts +10 -0
- package/src/routes/esri/rest.ts +90 -0
- package/src/routes/imagery.ts +52 -0
- package/src/routes/response.ts +4 -0
- package/src/routes/tile.json.ts +44 -0
- package/src/routes/tile.style.json.ts +77 -0
- package/src/routes/tile.ts +11 -186
- package/src/routes/tile.wmts.ts +59 -0
- package/src/routes/tile.xyz.ts +30 -0
- package/src/tile.set.raster.ts +4 -1
- package/src/tile.set.vector.ts +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/node_modules/color-name/.eslintrc.json +0 -43
- package/dist/node_modules/color-name/test.js +0 -7
- package/dist/node_modules/node-abi/.travis.yml +0 -17
- package/dist/node_modules/node-abi/node_modules/semver/CHANGELOG.md +0 -39
- package/dist/node_modules/node-abi/node_modules/semver/LICENSE +0 -15
- package/dist/node_modules/node-abi/node_modules/semver/README.md +0 -412
- package/dist/node_modules/node-abi/node_modules/semver/bin/semver +0 -160
- package/dist/node_modules/node-abi/node_modules/semver/package.json +0 -60
- package/dist/node_modules/node-abi/node_modules/semver/range.bnf +0 -16
- package/dist/node_modules/node-abi/node_modules/semver/semver.js +0 -1483
- package/dist/node_modules/node-addon-api/CHANGELOG.md +0 -722
- package/dist/node_modules/sharp/build/Release/sharp.node +0 -0
- package/dist/node_modules/sharp/vendor/8.10.6/versions.json +0 -31
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
/* MIT license */
|
|
2
|
-
|
|
2
|
+
/* eslint-disable no-mixed-operators */
|
|
3
|
+
const cssKeywords = require('color-name');
|
|
3
4
|
|
|
4
5
|
// NOTE: conversions should only return primitive values (i.e. arrays, or
|
|
5
6
|
// values that give correct `typeof` results).
|
|
6
7
|
// do not use box values types (i.e. Number(), String(), etc.)
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
for (
|
|
10
|
-
|
|
11
|
-
reverseKeywords[cssKeywords[key]] = key;
|
|
12
|
-
}
|
|
9
|
+
const reverseKeywords = {};
|
|
10
|
+
for (const key of Object.keys(cssKeywords)) {
|
|
11
|
+
reverseKeywords[cssKeywords[key]] = key;
|
|
13
12
|
}
|
|
14
13
|
|
|
15
|
-
|
|
14
|
+
const convert = {
|
|
16
15
|
rgb: {channels: 3, labels: 'rgb'},
|
|
17
16
|
hsl: {channels: 3, labels: 'hsl'},
|
|
18
17
|
hsv: {channels: 3, labels: 'hsv'},
|
|
@@ -30,40 +29,38 @@ var convert = module.exports = {
|
|
|
30
29
|
gray: {channels: 1, labels: ['gray']}
|
|
31
30
|
};
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
for (var model in convert) {
|
|
35
|
-
if (convert.hasOwnProperty(model)) {
|
|
36
|
-
if (!('channels' in convert[model])) {
|
|
37
|
-
throw new Error('missing channels property: ' + model);
|
|
38
|
-
}
|
|
32
|
+
module.exports = convert;
|
|
39
33
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
// Hide .channels and .labels properties
|
|
35
|
+
for (const model of Object.keys(convert)) {
|
|
36
|
+
if (!('channels' in convert[model])) {
|
|
37
|
+
throw new Error('missing channels property: ' + model);
|
|
38
|
+
}
|
|
43
39
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
if (!('labels' in convert[model])) {
|
|
41
|
+
throw new Error('missing channel labels property: ' + model);
|
|
42
|
+
}
|
|
47
43
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
delete convert[model].channels;
|
|
51
|
-
delete convert[model].labels;
|
|
52
|
-
Object.defineProperty(convert[model], 'channels', {value: channels});
|
|
53
|
-
Object.defineProperty(convert[model], 'labels', {value: labels});
|
|
44
|
+
if (convert[model].labels.length !== convert[model].channels) {
|
|
45
|
+
throw new Error('channel and label counts mismatch: ' + model);
|
|
54
46
|
}
|
|
47
|
+
|
|
48
|
+
const {channels, labels} = convert[model];
|
|
49
|
+
delete convert[model].channels;
|
|
50
|
+
delete convert[model].labels;
|
|
51
|
+
Object.defineProperty(convert[model], 'channels', {value: channels});
|
|
52
|
+
Object.defineProperty(convert[model], 'labels', {value: labels});
|
|
55
53
|
}
|
|
56
54
|
|
|
57
55
|
convert.rgb.hsl = function (rgb) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
var l;
|
|
56
|
+
const r = rgb[0] / 255;
|
|
57
|
+
const g = rgb[1] / 255;
|
|
58
|
+
const b = rgb[2] / 255;
|
|
59
|
+
const min = Math.min(r, g, b);
|
|
60
|
+
const max = Math.max(r, g, b);
|
|
61
|
+
const delta = max - min;
|
|
62
|
+
let h;
|
|
63
|
+
let s;
|
|
67
64
|
|
|
68
65
|
if (max === min) {
|
|
69
66
|
h = 0;
|
|
@@ -81,7 +78,7 @@ convert.rgb.hsl = function (rgb) {
|
|
|
81
78
|
h += 360;
|
|
82
79
|
}
|
|
83
80
|
|
|
84
|
-
l = (min + max) / 2;
|
|
81
|
+
const l = (min + max) / 2;
|
|
85
82
|
|
|
86
83
|
if (max === min) {
|
|
87
84
|
s = 0;
|
|
@@ -95,23 +92,24 @@ convert.rgb.hsl = function (rgb) {
|
|
|
95
92
|
};
|
|
96
93
|
|
|
97
94
|
convert.rgb.hsv = function (rgb) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
95
|
+
let rdif;
|
|
96
|
+
let gdif;
|
|
97
|
+
let bdif;
|
|
98
|
+
let h;
|
|
99
|
+
let s;
|
|
100
|
+
|
|
101
|
+
const r = rgb[0] / 255;
|
|
102
|
+
const g = rgb[1] / 255;
|
|
103
|
+
const b = rgb[2] / 255;
|
|
104
|
+
const v = Math.max(r, g, b);
|
|
105
|
+
const diff = v - Math.min(r, g, b);
|
|
106
|
+
const diffc = function (c) {
|
|
110
107
|
return (v - c) / 6 / diff + 1 / 2;
|
|
111
108
|
};
|
|
112
109
|
|
|
113
110
|
if (diff === 0) {
|
|
114
|
-
h =
|
|
111
|
+
h = 0;
|
|
112
|
+
s = 0;
|
|
115
113
|
} else {
|
|
116
114
|
s = diff / v;
|
|
117
115
|
rdif = diffc(r);
|
|
@@ -125,6 +123,7 @@ convert.rgb.hsv = function (rgb) {
|
|
|
125
123
|
} else if (b === v) {
|
|
126
124
|
h = (2 / 3) + gdif - rdif;
|
|
127
125
|
}
|
|
126
|
+
|
|
128
127
|
if (h < 0) {
|
|
129
128
|
h += 1;
|
|
130
129
|
} else if (h > 1) {
|
|
@@ -140,11 +139,11 @@ convert.rgb.hsv = function (rgb) {
|
|
|
140
139
|
};
|
|
141
140
|
|
|
142
141
|
convert.rgb.hwb = function (rgb) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
142
|
+
const r = rgb[0];
|
|
143
|
+
const g = rgb[1];
|
|
144
|
+
let b = rgb[2];
|
|
145
|
+
const h = convert.rgb.hsl(rgb)[0];
|
|
146
|
+
const w = 1 / 255 * Math.min(r, Math.min(g, b));
|
|
148
147
|
|
|
149
148
|
b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
|
|
150
149
|
|
|
@@ -152,54 +151,48 @@ convert.rgb.hwb = function (rgb) {
|
|
|
152
151
|
};
|
|
153
152
|
|
|
154
153
|
convert.rgb.cmyk = function (rgb) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
k = Math.min(1 - r, 1 - g, 1 - b);
|
|
164
|
-
c = (1 - r - k) / (1 - k) || 0;
|
|
165
|
-
m = (1 - g - k) / (1 - k) || 0;
|
|
166
|
-
y = (1 - b - k) / (1 - k) || 0;
|
|
154
|
+
const r = rgb[0] / 255;
|
|
155
|
+
const g = rgb[1] / 255;
|
|
156
|
+
const b = rgb[2] / 255;
|
|
157
|
+
|
|
158
|
+
const k = Math.min(1 - r, 1 - g, 1 - b);
|
|
159
|
+
const c = (1 - r - k) / (1 - k) || 0;
|
|
160
|
+
const m = (1 - g - k) / (1 - k) || 0;
|
|
161
|
+
const y = (1 - b - k) / (1 - k) || 0;
|
|
167
162
|
|
|
168
163
|
return [c * 100, m * 100, y * 100, k * 100];
|
|
169
164
|
};
|
|
170
165
|
|
|
171
|
-
/**
|
|
172
|
-
* See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
|
|
173
|
-
* */
|
|
174
166
|
function comparativeDistance(x, y) {
|
|
167
|
+
/*
|
|
168
|
+
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
|
|
169
|
+
*/
|
|
175
170
|
return (
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
171
|
+
((x[0] - y[0]) ** 2) +
|
|
172
|
+
((x[1] - y[1]) ** 2) +
|
|
173
|
+
((x[2] - y[2]) ** 2)
|
|
179
174
|
);
|
|
180
175
|
}
|
|
181
176
|
|
|
182
177
|
convert.rgb.keyword = function (rgb) {
|
|
183
|
-
|
|
178
|
+
const reversed = reverseKeywords[rgb];
|
|
184
179
|
if (reversed) {
|
|
185
180
|
return reversed;
|
|
186
181
|
}
|
|
187
182
|
|
|
188
|
-
|
|
189
|
-
|
|
183
|
+
let currentClosestDistance = Infinity;
|
|
184
|
+
let currentClosestKeyword;
|
|
190
185
|
|
|
191
|
-
for (
|
|
192
|
-
|
|
193
|
-
var value = cssKeywords[keyword];
|
|
186
|
+
for (const keyword of Object.keys(cssKeywords)) {
|
|
187
|
+
const value = cssKeywords[keyword];
|
|
194
188
|
|
|
195
|
-
|
|
196
|
-
|
|
189
|
+
// Compute comparative distance
|
|
190
|
+
const distance = comparativeDistance(rgb, value);
|
|
197
191
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}
|
|
192
|
+
// Check if its less, if so set as closest
|
|
193
|
+
if (distance < currentClosestDistance) {
|
|
194
|
+
currentClosestDistance = distance;
|
|
195
|
+
currentClosestKeyword = keyword;
|
|
203
196
|
}
|
|
204
197
|
}
|
|
205
198
|
|
|
@@ -211,55 +204,50 @@ convert.keyword.rgb = function (keyword) {
|
|
|
211
204
|
};
|
|
212
205
|
|
|
213
206
|
convert.rgb.xyz = function (rgb) {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
207
|
+
let r = rgb[0] / 255;
|
|
208
|
+
let g = rgb[1] / 255;
|
|
209
|
+
let b = rgb[2] / 255;
|
|
217
210
|
|
|
218
|
-
//
|
|
219
|
-
r = r > 0.04045 ?
|
|
220
|
-
g = g > 0.04045 ?
|
|
221
|
-
b = b > 0.04045 ?
|
|
211
|
+
// Assume sRGB
|
|
212
|
+
r = r > 0.04045 ? (((r + 0.055) / 1.055) ** 2.4) : (r / 12.92);
|
|
213
|
+
g = g > 0.04045 ? (((g + 0.055) / 1.055) ** 2.4) : (g / 12.92);
|
|
214
|
+
b = b > 0.04045 ? (((b + 0.055) / 1.055) ** 2.4) : (b / 12.92);
|
|
222
215
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
216
|
+
const x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805);
|
|
217
|
+
const y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722);
|
|
218
|
+
const z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505);
|
|
226
219
|
|
|
227
220
|
return [x * 100, y * 100, z * 100];
|
|
228
221
|
};
|
|
229
222
|
|
|
230
223
|
convert.rgb.lab = function (rgb) {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
var l;
|
|
236
|
-
var a;
|
|
237
|
-
var b;
|
|
224
|
+
const xyz = convert.rgb.xyz(rgb);
|
|
225
|
+
let x = xyz[0];
|
|
226
|
+
let y = xyz[1];
|
|
227
|
+
let z = xyz[2];
|
|
238
228
|
|
|
239
229
|
x /= 95.047;
|
|
240
230
|
y /= 100;
|
|
241
231
|
z /= 108.883;
|
|
242
232
|
|
|
243
|
-
x = x > 0.008856 ?
|
|
244
|
-
y = y > 0.008856 ?
|
|
245
|
-
z = z > 0.008856 ?
|
|
233
|
+
x = x > 0.008856 ? (x ** (1 / 3)) : (7.787 * x) + (16 / 116);
|
|
234
|
+
y = y > 0.008856 ? (y ** (1 / 3)) : (7.787 * y) + (16 / 116);
|
|
235
|
+
z = z > 0.008856 ? (z ** (1 / 3)) : (7.787 * z) + (16 / 116);
|
|
246
236
|
|
|
247
|
-
l = (116 * y) - 16;
|
|
248
|
-
a = 500 * (x - y);
|
|
249
|
-
b = 200 * (y - z);
|
|
237
|
+
const l = (116 * y) - 16;
|
|
238
|
+
const a = 500 * (x - y);
|
|
239
|
+
const b = 200 * (y - z);
|
|
250
240
|
|
|
251
241
|
return [l, a, b];
|
|
252
242
|
};
|
|
253
243
|
|
|
254
244
|
convert.hsl.rgb = function (hsl) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
var rgb;
|
|
262
|
-
var val;
|
|
245
|
+
const h = hsl[0] / 360;
|
|
246
|
+
const s = hsl[1] / 100;
|
|
247
|
+
const l = hsl[2] / 100;
|
|
248
|
+
let t2;
|
|
249
|
+
let t3;
|
|
250
|
+
let val;
|
|
263
251
|
|
|
264
252
|
if (s === 0) {
|
|
265
253
|
val = l * 255;
|
|
@@ -272,14 +260,15 @@ convert.hsl.rgb = function (hsl) {
|
|
|
272
260
|
t2 = l + s - l * s;
|
|
273
261
|
}
|
|
274
262
|
|
|
275
|
-
t1 = 2 * l - t2;
|
|
263
|
+
const t1 = 2 * l - t2;
|
|
276
264
|
|
|
277
|
-
rgb = [0, 0, 0];
|
|
278
|
-
for (
|
|
265
|
+
const rgb = [0, 0, 0];
|
|
266
|
+
for (let i = 0; i < 3; i++) {
|
|
279
267
|
t3 = h + 1 / 3 * -(i - 1);
|
|
280
268
|
if (t3 < 0) {
|
|
281
269
|
t3++;
|
|
282
270
|
}
|
|
271
|
+
|
|
283
272
|
if (t3 > 1) {
|
|
284
273
|
t3--;
|
|
285
274
|
}
|
|
@@ -301,33 +290,31 @@ convert.hsl.rgb = function (hsl) {
|
|
|
301
290
|
};
|
|
302
291
|
|
|
303
292
|
convert.hsl.hsv = function (hsl) {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
var sv;
|
|
310
|
-
var v;
|
|
293
|
+
const h = hsl[0];
|
|
294
|
+
let s = hsl[1] / 100;
|
|
295
|
+
let l = hsl[2] / 100;
|
|
296
|
+
let smin = s;
|
|
297
|
+
const lmin = Math.max(l, 0.01);
|
|
311
298
|
|
|
312
299
|
l *= 2;
|
|
313
300
|
s *= (l <= 1) ? l : 2 - l;
|
|
314
301
|
smin *= lmin <= 1 ? lmin : 2 - lmin;
|
|
315
|
-
v = (l + s) / 2;
|
|
316
|
-
sv = l === 0 ? (2 * smin) / (lmin + smin) : (2 * s) / (l + s);
|
|
302
|
+
const v = (l + s) / 2;
|
|
303
|
+
const sv = l === 0 ? (2 * smin) / (lmin + smin) : (2 * s) / (l + s);
|
|
317
304
|
|
|
318
305
|
return [h, sv * 100, v * 100];
|
|
319
306
|
};
|
|
320
307
|
|
|
321
308
|
convert.hsv.rgb = function (hsv) {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
309
|
+
const h = hsv[0] / 60;
|
|
310
|
+
const s = hsv[1] / 100;
|
|
311
|
+
let v = hsv[2] / 100;
|
|
312
|
+
const hi = Math.floor(h) % 6;
|
|
313
|
+
|
|
314
|
+
const f = h - Math.floor(h);
|
|
315
|
+
const p = 255 * v * (1 - s);
|
|
316
|
+
const q = 255 * v * (1 - (s * f));
|
|
317
|
+
const t = 255 * v * (1 - (s * (1 - f)));
|
|
331
318
|
v *= 255;
|
|
332
319
|
|
|
333
320
|
switch (hi) {
|
|
@@ -347,16 +334,15 @@ convert.hsv.rgb = function (hsv) {
|
|
|
347
334
|
};
|
|
348
335
|
|
|
349
336
|
convert.hsv.hsl = function (hsv) {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
var l;
|
|
337
|
+
const h = hsv[0];
|
|
338
|
+
const s = hsv[1] / 100;
|
|
339
|
+
const v = hsv[2] / 100;
|
|
340
|
+
const vmin = Math.max(v, 0.01);
|
|
341
|
+
let sl;
|
|
342
|
+
let l;
|
|
357
343
|
|
|
358
344
|
l = (2 - s) * v;
|
|
359
|
-
lmin = (2 - s) * vmin;
|
|
345
|
+
const lmin = (2 - s) * vmin;
|
|
360
346
|
sl = s * vmin;
|
|
361
347
|
sl /= (lmin <= 1) ? lmin : 2 - lmin;
|
|
362
348
|
sl = sl || 0;
|
|
@@ -367,87 +353,83 @@ convert.hsv.hsl = function (hsv) {
|
|
|
367
353
|
|
|
368
354
|
// http://dev.w3.org/csswg/css-color/#hwb-to-rgb
|
|
369
355
|
convert.hwb.rgb = function (hwb) {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
var n;
|
|
378
|
-
|
|
379
|
-
// wh + bl cant be > 1
|
|
356
|
+
const h = hwb[0] / 360;
|
|
357
|
+
let wh = hwb[1] / 100;
|
|
358
|
+
let bl = hwb[2] / 100;
|
|
359
|
+
const ratio = wh + bl;
|
|
360
|
+
let f;
|
|
361
|
+
|
|
362
|
+
// Wh + bl cant be > 1
|
|
380
363
|
if (ratio > 1) {
|
|
381
364
|
wh /= ratio;
|
|
382
365
|
bl /= ratio;
|
|
383
366
|
}
|
|
384
367
|
|
|
385
|
-
i = Math.floor(6 * h);
|
|
386
|
-
v = 1 - bl;
|
|
368
|
+
const i = Math.floor(6 * h);
|
|
369
|
+
const v = 1 - bl;
|
|
387
370
|
f = 6 * h - i;
|
|
388
371
|
|
|
389
372
|
if ((i & 0x01) !== 0) {
|
|
390
373
|
f = 1 - f;
|
|
391
374
|
}
|
|
392
375
|
|
|
393
|
-
n = wh + f * (v - wh); //
|
|
376
|
+
const n = wh + f * (v - wh); // Linear interpolation
|
|
394
377
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
378
|
+
let r;
|
|
379
|
+
let g;
|
|
380
|
+
let b;
|
|
381
|
+
/* eslint-disable max-statements-per-line,no-multi-spaces */
|
|
398
382
|
switch (i) {
|
|
399
383
|
default:
|
|
400
384
|
case 6:
|
|
401
|
-
case 0: r = v;
|
|
402
|
-
case 1: r = n;
|
|
403
|
-
case 2: r = wh; g = v;
|
|
404
|
-
case 3: r = wh; g = n;
|
|
405
|
-
case 4: r = n;
|
|
406
|
-
case 5: r = v;
|
|
385
|
+
case 0: r = v; g = n; b = wh; break;
|
|
386
|
+
case 1: r = n; g = v; b = wh; break;
|
|
387
|
+
case 2: r = wh; g = v; b = n; break;
|
|
388
|
+
case 3: r = wh; g = n; b = v; break;
|
|
389
|
+
case 4: r = n; g = wh; b = v; break;
|
|
390
|
+
case 5: r = v; g = wh; b = n; break;
|
|
407
391
|
}
|
|
392
|
+
/* eslint-enable max-statements-per-line,no-multi-spaces */
|
|
408
393
|
|
|
409
394
|
return [r * 255, g * 255, b * 255];
|
|
410
395
|
};
|
|
411
396
|
|
|
412
397
|
convert.cmyk.rgb = function (cmyk) {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
r = 1 - Math.min(1, c * (1 - k) + k);
|
|
422
|
-
g = 1 - Math.min(1, m * (1 - k) + k);
|
|
423
|
-
b = 1 - Math.min(1, y * (1 - k) + k);
|
|
398
|
+
const c = cmyk[0] / 100;
|
|
399
|
+
const m = cmyk[1] / 100;
|
|
400
|
+
const y = cmyk[2] / 100;
|
|
401
|
+
const k = cmyk[3] / 100;
|
|
402
|
+
|
|
403
|
+
const r = 1 - Math.min(1, c * (1 - k) + k);
|
|
404
|
+
const g = 1 - Math.min(1, m * (1 - k) + k);
|
|
405
|
+
const b = 1 - Math.min(1, y * (1 - k) + k);
|
|
424
406
|
|
|
425
407
|
return [r * 255, g * 255, b * 255];
|
|
426
408
|
};
|
|
427
409
|
|
|
428
410
|
convert.xyz.rgb = function (xyz) {
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
411
|
+
const x = xyz[0] / 100;
|
|
412
|
+
const y = xyz[1] / 100;
|
|
413
|
+
const z = xyz[2] / 100;
|
|
414
|
+
let r;
|
|
415
|
+
let g;
|
|
416
|
+
let b;
|
|
435
417
|
|
|
436
418
|
r = (x * 3.2406) + (y * -1.5372) + (z * -0.4986);
|
|
437
419
|
g = (x * -0.9689) + (y * 1.8758) + (z * 0.0415);
|
|
438
420
|
b = (x * 0.0557) + (y * -0.2040) + (z * 1.0570);
|
|
439
421
|
|
|
440
|
-
//
|
|
422
|
+
// Assume sRGB
|
|
441
423
|
r = r > 0.0031308
|
|
442
|
-
? ((1.055 *
|
|
424
|
+
? ((1.055 * (r ** (1.0 / 2.4))) - 0.055)
|
|
443
425
|
: r * 12.92;
|
|
444
426
|
|
|
445
427
|
g = g > 0.0031308
|
|
446
|
-
? ((1.055 *
|
|
428
|
+
? ((1.055 * (g ** (1.0 / 2.4))) - 0.055)
|
|
447
429
|
: g * 12.92;
|
|
448
430
|
|
|
449
431
|
b = b > 0.0031308
|
|
450
|
-
? ((1.055 *
|
|
432
|
+
? ((1.055 * (b ** (1.0 / 2.4))) - 0.055)
|
|
451
433
|
: b * 12.92;
|
|
452
434
|
|
|
453
435
|
r = Math.min(Math.max(0, r), 1);
|
|
@@ -458,43 +440,40 @@ convert.xyz.rgb = function (xyz) {
|
|
|
458
440
|
};
|
|
459
441
|
|
|
460
442
|
convert.xyz.lab = function (xyz) {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
var l;
|
|
465
|
-
var a;
|
|
466
|
-
var b;
|
|
443
|
+
let x = xyz[0];
|
|
444
|
+
let y = xyz[1];
|
|
445
|
+
let z = xyz[2];
|
|
467
446
|
|
|
468
447
|
x /= 95.047;
|
|
469
448
|
y /= 100;
|
|
470
449
|
z /= 108.883;
|
|
471
450
|
|
|
472
|
-
x = x > 0.008856 ?
|
|
473
|
-
y = y > 0.008856 ?
|
|
474
|
-
z = z > 0.008856 ?
|
|
451
|
+
x = x > 0.008856 ? (x ** (1 / 3)) : (7.787 * x) + (16 / 116);
|
|
452
|
+
y = y > 0.008856 ? (y ** (1 / 3)) : (7.787 * y) + (16 / 116);
|
|
453
|
+
z = z > 0.008856 ? (z ** (1 / 3)) : (7.787 * z) + (16 / 116);
|
|
475
454
|
|
|
476
|
-
l = (116 * y) - 16;
|
|
477
|
-
a = 500 * (x - y);
|
|
478
|
-
b = 200 * (y - z);
|
|
455
|
+
const l = (116 * y) - 16;
|
|
456
|
+
const a = 500 * (x - y);
|
|
457
|
+
const b = 200 * (y - z);
|
|
479
458
|
|
|
480
459
|
return [l, a, b];
|
|
481
460
|
};
|
|
482
461
|
|
|
483
462
|
convert.lab.xyz = function (lab) {
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
463
|
+
const l = lab[0];
|
|
464
|
+
const a = lab[1];
|
|
465
|
+
const b = lab[2];
|
|
466
|
+
let x;
|
|
467
|
+
let y;
|
|
468
|
+
let z;
|
|
490
469
|
|
|
491
470
|
y = (l + 16) / 116;
|
|
492
471
|
x = a / 500 + y;
|
|
493
472
|
z = y - b / 200;
|
|
494
473
|
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
474
|
+
const y2 = y ** 3;
|
|
475
|
+
const x2 = x ** 3;
|
|
476
|
+
const z2 = z ** 3;
|
|
498
477
|
y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787;
|
|
499
478
|
x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787;
|
|
500
479
|
z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787;
|
|
@@ -507,45 +486,38 @@ convert.lab.xyz = function (lab) {
|
|
|
507
486
|
};
|
|
508
487
|
|
|
509
488
|
convert.lab.lch = function (lab) {
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
hr = Math.atan2(b, a);
|
|
489
|
+
const l = lab[0];
|
|
490
|
+
const a = lab[1];
|
|
491
|
+
const b = lab[2];
|
|
492
|
+
let h;
|
|
493
|
+
|
|
494
|
+
const hr = Math.atan2(b, a);
|
|
518
495
|
h = hr * 360 / 2 / Math.PI;
|
|
519
496
|
|
|
520
497
|
if (h < 0) {
|
|
521
498
|
h += 360;
|
|
522
499
|
}
|
|
523
500
|
|
|
524
|
-
c = Math.sqrt(a * a + b * b);
|
|
501
|
+
const c = Math.sqrt(a * a + b * b);
|
|
525
502
|
|
|
526
503
|
return [l, c, h];
|
|
527
504
|
};
|
|
528
505
|
|
|
529
506
|
convert.lch.lab = function (lch) {
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
var a;
|
|
534
|
-
var b;
|
|
535
|
-
var hr;
|
|
507
|
+
const l = lch[0];
|
|
508
|
+
const c = lch[1];
|
|
509
|
+
const h = lch[2];
|
|
536
510
|
|
|
537
|
-
hr = h / 360 * 2 * Math.PI;
|
|
538
|
-
a = c * Math.cos(hr);
|
|
539
|
-
b = c * Math.sin(hr);
|
|
511
|
+
const hr = h / 360 * 2 * Math.PI;
|
|
512
|
+
const a = c * Math.cos(hr);
|
|
513
|
+
const b = c * Math.sin(hr);
|
|
540
514
|
|
|
541
515
|
return [l, a, b];
|
|
542
516
|
};
|
|
543
517
|
|
|
544
|
-
convert.rgb.ansi16 = function (args) {
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
var b = args[2];
|
|
548
|
-
var value = 1 in arguments ? arguments[1] : convert.rgb.hsv(args)[2]; // hsv -> ansi16 optimization
|
|
518
|
+
convert.rgb.ansi16 = function (args, saturation = null) {
|
|
519
|
+
const [r, g, b] = args;
|
|
520
|
+
let value = saturation === null ? convert.rgb.hsv(args)[2] : saturation; // Hsv -> ansi16 optimization
|
|
549
521
|
|
|
550
522
|
value = Math.round(value / 50);
|
|
551
523
|
|
|
@@ -553,7 +525,7 @@ convert.rgb.ansi16 = function (args) {
|
|
|
553
525
|
return 30;
|
|
554
526
|
}
|
|
555
527
|
|
|
556
|
-
|
|
528
|
+
let ansi = 30
|
|
557
529
|
+ ((Math.round(b / 255) << 2)
|
|
558
530
|
| (Math.round(g / 255) << 1)
|
|
559
531
|
| Math.round(r / 255));
|
|
@@ -566,17 +538,17 @@ convert.rgb.ansi16 = function (args) {
|
|
|
566
538
|
};
|
|
567
539
|
|
|
568
540
|
convert.hsv.ansi16 = function (args) {
|
|
569
|
-
//
|
|
541
|
+
// Optimization here; we already know the value and don't need to get
|
|
570
542
|
// it converted for us.
|
|
571
543
|
return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
|
|
572
544
|
};
|
|
573
545
|
|
|
574
546
|
convert.rgb.ansi256 = function (args) {
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
547
|
+
const r = args[0];
|
|
548
|
+
const g = args[1];
|
|
549
|
+
const b = args[2];
|
|
578
550
|
|
|
579
|
-
//
|
|
551
|
+
// We use the extended greyscale palette here, with the exception of
|
|
580
552
|
// black and white. normal palette only has 4 greyscale shades.
|
|
581
553
|
if (r === g && g === b) {
|
|
582
554
|
if (r < 8) {
|
|
@@ -590,7 +562,7 @@ convert.rgb.ansi256 = function (args) {
|
|
|
590
562
|
return Math.round(((r - 8) / 247) * 24) + 232;
|
|
591
563
|
}
|
|
592
564
|
|
|
593
|
-
|
|
565
|
+
const ansi = 16
|
|
594
566
|
+ (36 * Math.round(r / 255 * 5))
|
|
595
567
|
+ (6 * Math.round(g / 255 * 5))
|
|
596
568
|
+ Math.round(b / 255 * 5);
|
|
@@ -599,9 +571,9 @@ convert.rgb.ansi256 = function (args) {
|
|
|
599
571
|
};
|
|
600
572
|
|
|
601
573
|
convert.ansi16.rgb = function (args) {
|
|
602
|
-
|
|
574
|
+
let color = args % 10;
|
|
603
575
|
|
|
604
|
-
//
|
|
576
|
+
// Handle greyscale
|
|
605
577
|
if (color === 0 || color === 7) {
|
|
606
578
|
if (args > 50) {
|
|
607
579
|
color += 3.5;
|
|
@@ -612,71 +584,71 @@ convert.ansi16.rgb = function (args) {
|
|
|
612
584
|
return [color, color, color];
|
|
613
585
|
}
|
|
614
586
|
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
587
|
+
const mult = (~~(args > 50) + 1) * 0.5;
|
|
588
|
+
const r = ((color & 1) * mult) * 255;
|
|
589
|
+
const g = (((color >> 1) & 1) * mult) * 255;
|
|
590
|
+
const b = (((color >> 2) & 1) * mult) * 255;
|
|
619
591
|
|
|
620
592
|
return [r, g, b];
|
|
621
593
|
};
|
|
622
594
|
|
|
623
595
|
convert.ansi256.rgb = function (args) {
|
|
624
|
-
//
|
|
596
|
+
// Handle greyscale
|
|
625
597
|
if (args >= 232) {
|
|
626
|
-
|
|
598
|
+
const c = (args - 232) * 10 + 8;
|
|
627
599
|
return [c, c, c];
|
|
628
600
|
}
|
|
629
601
|
|
|
630
602
|
args -= 16;
|
|
631
603
|
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
604
|
+
let rem;
|
|
605
|
+
const r = Math.floor(args / 36) / 5 * 255;
|
|
606
|
+
const g = Math.floor((rem = args % 36) / 6) / 5 * 255;
|
|
607
|
+
const b = (rem % 6) / 5 * 255;
|
|
636
608
|
|
|
637
609
|
return [r, g, b];
|
|
638
610
|
};
|
|
639
611
|
|
|
640
612
|
convert.rgb.hex = function (args) {
|
|
641
|
-
|
|
613
|
+
const integer = ((Math.round(args[0]) & 0xFF) << 16)
|
|
642
614
|
+ ((Math.round(args[1]) & 0xFF) << 8)
|
|
643
615
|
+ (Math.round(args[2]) & 0xFF);
|
|
644
616
|
|
|
645
|
-
|
|
617
|
+
const string = integer.toString(16).toUpperCase();
|
|
646
618
|
return '000000'.substring(string.length) + string;
|
|
647
619
|
};
|
|
648
620
|
|
|
649
621
|
convert.hex.rgb = function (args) {
|
|
650
|
-
|
|
622
|
+
const match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
|
|
651
623
|
if (!match) {
|
|
652
624
|
return [0, 0, 0];
|
|
653
625
|
}
|
|
654
626
|
|
|
655
|
-
|
|
627
|
+
let colorString = match[0];
|
|
656
628
|
|
|
657
629
|
if (match[0].length === 3) {
|
|
658
|
-
colorString = colorString.split('').map(
|
|
630
|
+
colorString = colorString.split('').map(char => {
|
|
659
631
|
return char + char;
|
|
660
632
|
}).join('');
|
|
661
633
|
}
|
|
662
634
|
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
635
|
+
const integer = parseInt(colorString, 16);
|
|
636
|
+
const r = (integer >> 16) & 0xFF;
|
|
637
|
+
const g = (integer >> 8) & 0xFF;
|
|
638
|
+
const b = integer & 0xFF;
|
|
667
639
|
|
|
668
640
|
return [r, g, b];
|
|
669
641
|
};
|
|
670
642
|
|
|
671
643
|
convert.rgb.hcg = function (rgb) {
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
644
|
+
const r = rgb[0] / 255;
|
|
645
|
+
const g = rgb[1] / 255;
|
|
646
|
+
const b = rgb[2] / 255;
|
|
647
|
+
const max = Math.max(Math.max(r, g), b);
|
|
648
|
+
const min = Math.min(Math.min(r, g), b);
|
|
649
|
+
const chroma = (max - min);
|
|
650
|
+
let grayscale;
|
|
651
|
+
let hue;
|
|
680
652
|
|
|
681
653
|
if (chroma < 1) {
|
|
682
654
|
grayscale = min / (1 - chroma);
|
|
@@ -693,7 +665,7 @@ convert.rgb.hcg = function (rgb) {
|
|
|
693
665
|
if (max === g) {
|
|
694
666
|
hue = 2 + (b - r) / chroma;
|
|
695
667
|
} else {
|
|
696
|
-
hue = 4 + (r - g) / chroma
|
|
668
|
+
hue = 4 + (r - g) / chroma;
|
|
697
669
|
}
|
|
698
670
|
|
|
699
671
|
hue /= 6;
|
|
@@ -703,17 +675,12 @@ convert.rgb.hcg = function (rgb) {
|
|
|
703
675
|
};
|
|
704
676
|
|
|
705
677
|
convert.hsl.hcg = function (hsl) {
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
var c = 1;
|
|
709
|
-
var f = 0;
|
|
678
|
+
const s = hsl[1] / 100;
|
|
679
|
+
const l = hsl[2] / 100;
|
|
710
680
|
|
|
711
|
-
|
|
712
|
-
c = 2.0 * s * l;
|
|
713
|
-
} else {
|
|
714
|
-
c = 2.0 * s * (1.0 - l);
|
|
715
|
-
}
|
|
681
|
+
const c = l < 0.5 ? (2.0 * s * l) : (2.0 * s * (1.0 - l));
|
|
716
682
|
|
|
683
|
+
let f = 0;
|
|
717
684
|
if (c < 1.0) {
|
|
718
685
|
f = (l - 0.5 * c) / (1.0 - c);
|
|
719
686
|
}
|
|
@@ -722,11 +689,11 @@ convert.hsl.hcg = function (hsl) {
|
|
|
722
689
|
};
|
|
723
690
|
|
|
724
691
|
convert.hsv.hcg = function (hsv) {
|
|
725
|
-
|
|
726
|
-
|
|
692
|
+
const s = hsv[1] / 100;
|
|
693
|
+
const v = hsv[2] / 100;
|
|
727
694
|
|
|
728
|
-
|
|
729
|
-
|
|
695
|
+
const c = s * v;
|
|
696
|
+
let f = 0;
|
|
730
697
|
|
|
731
698
|
if (c < 1.0) {
|
|
732
699
|
f = (v - c) / (1 - c);
|
|
@@ -736,20 +703,21 @@ convert.hsv.hcg = function (hsv) {
|
|
|
736
703
|
};
|
|
737
704
|
|
|
738
705
|
convert.hcg.rgb = function (hcg) {
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
706
|
+
const h = hcg[0] / 360;
|
|
707
|
+
const c = hcg[1] / 100;
|
|
708
|
+
const g = hcg[2] / 100;
|
|
742
709
|
|
|
743
710
|
if (c === 0.0) {
|
|
744
711
|
return [g * 255, g * 255, g * 255];
|
|
745
712
|
}
|
|
746
713
|
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
714
|
+
const pure = [0, 0, 0];
|
|
715
|
+
const hi = (h % 1) * 6;
|
|
716
|
+
const v = hi % 1;
|
|
717
|
+
const w = 1 - v;
|
|
718
|
+
let mg = 0;
|
|
752
719
|
|
|
720
|
+
/* eslint-disable max-statements-per-line */
|
|
753
721
|
switch (Math.floor(hi)) {
|
|
754
722
|
case 0:
|
|
755
723
|
pure[0] = 1; pure[1] = v; pure[2] = 0; break;
|
|
@@ -764,6 +732,7 @@ convert.hcg.rgb = function (hcg) {
|
|
|
764
732
|
default:
|
|
765
733
|
pure[0] = 1; pure[1] = 0; pure[2] = w;
|
|
766
734
|
}
|
|
735
|
+
/* eslint-enable max-statements-per-line */
|
|
767
736
|
|
|
768
737
|
mg = (1.0 - c) * g;
|
|
769
738
|
|
|
@@ -775,11 +744,11 @@ convert.hcg.rgb = function (hcg) {
|
|
|
775
744
|
};
|
|
776
745
|
|
|
777
746
|
convert.hcg.hsv = function (hcg) {
|
|
778
|
-
|
|
779
|
-
|
|
747
|
+
const c = hcg[1] / 100;
|
|
748
|
+
const g = hcg[2] / 100;
|
|
780
749
|
|
|
781
|
-
|
|
782
|
-
|
|
750
|
+
const v = c + g * (1.0 - c);
|
|
751
|
+
let f = 0;
|
|
783
752
|
|
|
784
753
|
if (v > 0.0) {
|
|
785
754
|
f = c / v;
|
|
@@ -789,11 +758,11 @@ convert.hcg.hsv = function (hcg) {
|
|
|
789
758
|
};
|
|
790
759
|
|
|
791
760
|
convert.hcg.hsl = function (hcg) {
|
|
792
|
-
|
|
793
|
-
|
|
761
|
+
const c = hcg[1] / 100;
|
|
762
|
+
const g = hcg[2] / 100;
|
|
794
763
|
|
|
795
|
-
|
|
796
|
-
|
|
764
|
+
const l = g * (1.0 - c) + 0.5 * c;
|
|
765
|
+
let s = 0;
|
|
797
766
|
|
|
798
767
|
if (l > 0.0 && l < 0.5) {
|
|
799
768
|
s = c / (2 * l);
|
|
@@ -806,18 +775,18 @@ convert.hcg.hsl = function (hcg) {
|
|
|
806
775
|
};
|
|
807
776
|
|
|
808
777
|
convert.hcg.hwb = function (hcg) {
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
778
|
+
const c = hcg[1] / 100;
|
|
779
|
+
const g = hcg[2] / 100;
|
|
780
|
+
const v = c + g * (1.0 - c);
|
|
812
781
|
return [hcg[0], (v - c) * 100, (1 - v) * 100];
|
|
813
782
|
};
|
|
814
783
|
|
|
815
784
|
convert.hwb.hcg = function (hwb) {
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
785
|
+
const w = hwb[1] / 100;
|
|
786
|
+
const b = hwb[2] / 100;
|
|
787
|
+
const v = 1 - b;
|
|
788
|
+
const c = v - w;
|
|
789
|
+
let g = 0;
|
|
821
790
|
|
|
822
791
|
if (c < 1) {
|
|
823
792
|
g = (v - c) / (1 - c);
|
|
@@ -838,10 +807,12 @@ convert.gray.rgb = function (args) {
|
|
|
838
807
|
return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
|
|
839
808
|
};
|
|
840
809
|
|
|
841
|
-
convert.gray.hsl =
|
|
810
|
+
convert.gray.hsl = function (args) {
|
|
842
811
|
return [0, 0, args[0]];
|
|
843
812
|
};
|
|
844
813
|
|
|
814
|
+
convert.gray.hsv = convert.gray.hsl;
|
|
815
|
+
|
|
845
816
|
convert.gray.hwb = function (gray) {
|
|
846
817
|
return [0, 100, gray[0]];
|
|
847
818
|
};
|
|
@@ -855,14 +826,14 @@ convert.gray.lab = function (gray) {
|
|
|
855
826
|
};
|
|
856
827
|
|
|
857
828
|
convert.gray.hex = function (gray) {
|
|
858
|
-
|
|
859
|
-
|
|
829
|
+
const val = Math.round(gray[0] / 100 * 255) & 0xFF;
|
|
830
|
+
const integer = (val << 16) + (val << 8) + val;
|
|
860
831
|
|
|
861
|
-
|
|
832
|
+
const string = integer.toString(16).toUpperCase();
|
|
862
833
|
return '000000'.substring(string.length) + string;
|
|
863
834
|
};
|
|
864
835
|
|
|
865
836
|
convert.rgb.gray = function (rgb) {
|
|
866
|
-
|
|
837
|
+
const val = (rgb[0] + rgb[1] + rgb[2]) / 3;
|
|
867
838
|
return [val / 255 * 100];
|
|
868
839
|
};
|