@basemaps/lambda-tiler 6.19.0 → 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 +12 -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 +24 -23
- package/build/cli/dump.js +2 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -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 +2 -0
- package/build/routes/imagery.d.ts.map +1 -1
- package/build/routes/imagery.js +3 -1
- 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 -161
- 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 +10545 -9583
- 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/package.json +5 -5
- 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 +51 -51
- package/dist/package.json +9 -9
- package/package.json +10 -10
- package/src/__test__/tile.style.json.test.ts +40 -0
- package/src/__test__/xyz.test.ts +32 -30
- package/src/cli/dump.ts +2 -2
- package/src/index.ts +2 -0
- package/src/routes/esri/rest.ts +90 -0
- package/src/routes/imagery.ts +3 -1
- 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 -183
- 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,9 +1,9 @@
|
|
|
1
|
-
# color
|
|
1
|
+
# color
|
|
2
2
|
|
|
3
3
|
> JavaScript library for immutable color conversion and manipulation with support for CSS color strings.
|
|
4
4
|
|
|
5
5
|
```js
|
|
6
|
-
|
|
6
|
+
const color = Color('#7743CE').alpha(0.5).lighten(0.5);
|
|
7
7
|
console.log(color.hsl().string()); // 'hsla(262, 59%, 81%, 0.5)'
|
|
8
8
|
|
|
9
9
|
console.log(color.cmyk().round().array()); // [ 16, 25, 0, 8, 0.5 ]
|
|
@@ -18,15 +18,15 @@ $ npm install color
|
|
|
18
18
|
|
|
19
19
|
## Usage
|
|
20
20
|
```js
|
|
21
|
-
|
|
21
|
+
const Color = require('color');
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
### Constructors
|
|
25
25
|
```js
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
const color = Color('rgb(255, 255, 255)')
|
|
27
|
+
const color = Color({r: 255, g: 255, b: 255})
|
|
28
|
+
const color = Color.rgb(255, 255, 255)
|
|
29
|
+
const color = Color.rgb([255, 255, 255])
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
Set the values for individual channels with `alpha`, `red`, `green`, `blue`, `hue`, `saturationl` (hsl), `saturationv` (hsv), `lightness`, `whiteness`, `blackness`, `cyan`, `magenta`, `yellow`, `black`
|
|
@@ -1,31 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
const colorString = require('color-string');
|
|
2
|
+
const convert = require('color-convert');
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
var convert = require('color-convert');
|
|
4
|
+
const _slice = [].slice;
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var skippedModels = [
|
|
9
|
-
// to be honest, I don't really feel like keyword belongs in color convert, but eh.
|
|
6
|
+
const skippedModels = [
|
|
7
|
+
// To be honest, I don't really feel like keyword belongs in color convert, but eh.
|
|
10
8
|
'keyword',
|
|
11
9
|
|
|
12
|
-
//
|
|
10
|
+
// Gray conflicts with some method names, and has its own method defined.
|
|
13
11
|
'gray',
|
|
14
12
|
|
|
15
|
-
//
|
|
16
|
-
'hex'
|
|
13
|
+
// Shouldn't really be in color-convert either...
|
|
14
|
+
'hex',
|
|
17
15
|
];
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
Object.keys(convert)
|
|
17
|
+
const hashedModelKeys = {};
|
|
18
|
+
for (const model of Object.keys(convert)) {
|
|
21
19
|
hashedModelKeys[_slice.call(convert[model].labels).sort().join('')] = model;
|
|
22
|
-
}
|
|
20
|
+
}
|
|
23
21
|
|
|
24
|
-
|
|
22
|
+
const limiters = {};
|
|
25
23
|
|
|
26
|
-
function Color(
|
|
24
|
+
function Color(object, model) {
|
|
27
25
|
if (!(this instanceof Color)) {
|
|
28
|
-
return new Color(
|
|
26
|
+
return new Color(object, model);
|
|
29
27
|
}
|
|
30
28
|
|
|
31
29
|
if (model && model in skippedModels) {
|
|
@@ -36,73 +34,72 @@ function Color(obj, model) {
|
|
|
36
34
|
throw new Error('Unknown model: ' + model);
|
|
37
35
|
}
|
|
38
36
|
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
let i;
|
|
38
|
+
let channels;
|
|
41
39
|
|
|
42
|
-
if (
|
|
40
|
+
if (object == null) { // eslint-disable-line no-eq-null,eqeqeq
|
|
43
41
|
this.model = 'rgb';
|
|
44
42
|
this.color = [0, 0, 0];
|
|
45
43
|
this.valpha = 1;
|
|
46
|
-
} else if (
|
|
47
|
-
this.model =
|
|
48
|
-
this.color =
|
|
49
|
-
this.valpha =
|
|
50
|
-
} else if (typeof
|
|
51
|
-
|
|
44
|
+
} else if (object instanceof Color) {
|
|
45
|
+
this.model = object.model;
|
|
46
|
+
this.color = object.color.slice();
|
|
47
|
+
this.valpha = object.valpha;
|
|
48
|
+
} else if (typeof object === 'string') {
|
|
49
|
+
const result = colorString.get(object);
|
|
52
50
|
if (result === null) {
|
|
53
|
-
throw new Error('Unable to parse color from string: ' +
|
|
51
|
+
throw new Error('Unable to parse color from string: ' + object);
|
|
54
52
|
}
|
|
55
53
|
|
|
56
54
|
this.model = result.model;
|
|
57
55
|
channels = convert[this.model].channels;
|
|
58
56
|
this.color = result.value.slice(0, channels);
|
|
59
57
|
this.valpha = typeof result.value[channels] === 'number' ? result.value[channels] : 1;
|
|
60
|
-
} else if (
|
|
58
|
+
} else if (object.length > 0) {
|
|
61
59
|
this.model = model || 'rgb';
|
|
62
60
|
channels = convert[this.model].channels;
|
|
63
|
-
|
|
64
|
-
this.color = zeroArray(
|
|
65
|
-
this.valpha = typeof
|
|
66
|
-
} else if (typeof
|
|
67
|
-
//
|
|
68
|
-
obj &= 0xFFFFFF;
|
|
61
|
+
const newArray = _slice.call(object, 0, channels);
|
|
62
|
+
this.color = zeroArray(newArray, channels);
|
|
63
|
+
this.valpha = typeof object[channels] === 'number' ? object[channels] : 1;
|
|
64
|
+
} else if (typeof object === 'number') {
|
|
65
|
+
// This is always RGB - can be converted later on.
|
|
69
66
|
this.model = 'rgb';
|
|
70
67
|
this.color = [
|
|
71
|
-
(
|
|
72
|
-
(
|
|
73
|
-
|
|
68
|
+
(object >> 16) & 0xFF,
|
|
69
|
+
(object >> 8) & 0xFF,
|
|
70
|
+
object & 0xFF,
|
|
74
71
|
];
|
|
75
72
|
this.valpha = 1;
|
|
76
73
|
} else {
|
|
77
74
|
this.valpha = 1;
|
|
78
75
|
|
|
79
|
-
|
|
80
|
-
if ('alpha' in
|
|
76
|
+
const keys = Object.keys(object);
|
|
77
|
+
if ('alpha' in object) {
|
|
81
78
|
keys.splice(keys.indexOf('alpha'), 1);
|
|
82
|
-
this.valpha = typeof
|
|
79
|
+
this.valpha = typeof object.alpha === 'number' ? object.alpha : 0;
|
|
83
80
|
}
|
|
84
81
|
|
|
85
|
-
|
|
82
|
+
const hashedKeys = keys.sort().join('');
|
|
86
83
|
if (!(hashedKeys in hashedModelKeys)) {
|
|
87
|
-
throw new Error('Unable to parse color from object: ' + JSON.stringify(
|
|
84
|
+
throw new Error('Unable to parse color from object: ' + JSON.stringify(object));
|
|
88
85
|
}
|
|
89
86
|
|
|
90
87
|
this.model = hashedModelKeys[hashedKeys];
|
|
91
88
|
|
|
92
|
-
|
|
93
|
-
|
|
89
|
+
const labels = convert[this.model].labels;
|
|
90
|
+
const color = [];
|
|
94
91
|
for (i = 0; i < labels.length; i++) {
|
|
95
|
-
color.push(
|
|
92
|
+
color.push(object[labels[i]]);
|
|
96
93
|
}
|
|
97
94
|
|
|
98
95
|
this.color = zeroArray(color);
|
|
99
96
|
}
|
|
100
97
|
|
|
101
|
-
//
|
|
98
|
+
// Perform limitations (clamping, etc.)
|
|
102
99
|
if (limiters[this.model]) {
|
|
103
100
|
channels = convert[this.model].channels;
|
|
104
101
|
for (i = 0; i < channels; i++) {
|
|
105
|
-
|
|
102
|
+
const limit = limiters[this.model][i];
|
|
106
103
|
if (limit) {
|
|
107
104
|
this.color[i] = limit(this.color[i]);
|
|
108
105
|
}
|
|
@@ -117,37 +114,37 @@ function Color(obj, model) {
|
|
|
117
114
|
}
|
|
118
115
|
|
|
119
116
|
Color.prototype = {
|
|
120
|
-
toString
|
|
117
|
+
toString() {
|
|
121
118
|
return this.string();
|
|
122
119
|
},
|
|
123
120
|
|
|
124
|
-
toJSON
|
|
121
|
+
toJSON() {
|
|
125
122
|
return this[this.model]();
|
|
126
123
|
},
|
|
127
124
|
|
|
128
|
-
string
|
|
129
|
-
|
|
125
|
+
string(places) {
|
|
126
|
+
let self = this.model in colorString.to ? this : this.rgb();
|
|
130
127
|
self = self.round(typeof places === 'number' ? places : 1);
|
|
131
|
-
|
|
128
|
+
const args = self.valpha === 1 ? self.color : self.color.concat(this.valpha);
|
|
132
129
|
return colorString.to[self.model](args);
|
|
133
130
|
},
|
|
134
131
|
|
|
135
|
-
percentString
|
|
136
|
-
|
|
137
|
-
|
|
132
|
+
percentString(places) {
|
|
133
|
+
const self = this.rgb().round(typeof places === 'number' ? places : 1);
|
|
134
|
+
const args = self.valpha === 1 ? self.color : self.color.concat(this.valpha);
|
|
138
135
|
return colorString.to.rgb.percent(args);
|
|
139
136
|
},
|
|
140
137
|
|
|
141
|
-
array
|
|
138
|
+
array() {
|
|
142
139
|
return this.valpha === 1 ? this.color.slice() : this.color.concat(this.valpha);
|
|
143
140
|
},
|
|
144
141
|
|
|
145
|
-
object
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
142
|
+
object() {
|
|
143
|
+
const result = {};
|
|
144
|
+
const channels = convert[this.model].channels;
|
|
145
|
+
const labels = convert[this.model].labels;
|
|
149
146
|
|
|
150
|
-
for (
|
|
147
|
+
for (let i = 0; i < channels; i++) {
|
|
151
148
|
result[labels[i]] = this.color[i];
|
|
152
149
|
}
|
|
153
150
|
|
|
@@ -158,8 +155,8 @@ Color.prototype = {
|
|
|
158
155
|
return result;
|
|
159
156
|
},
|
|
160
157
|
|
|
161
|
-
unitArray
|
|
162
|
-
|
|
158
|
+
unitArray() {
|
|
159
|
+
const rgb = this.rgb().color;
|
|
163
160
|
rgb[0] /= 255;
|
|
164
161
|
rgb[1] /= 255;
|
|
165
162
|
rgb[2] /= 255;
|
|
@@ -171,8 +168,8 @@ Color.prototype = {
|
|
|
171
168
|
return rgb;
|
|
172
169
|
},
|
|
173
170
|
|
|
174
|
-
unitObject
|
|
175
|
-
|
|
171
|
+
unitObject() {
|
|
172
|
+
const rgb = this.rgb().object();
|
|
176
173
|
rgb.r /= 255;
|
|
177
174
|
rgb.g /= 255;
|
|
178
175
|
rgb.b /= 255;
|
|
@@ -184,25 +181,25 @@ Color.prototype = {
|
|
|
184
181
|
return rgb;
|
|
185
182
|
},
|
|
186
183
|
|
|
187
|
-
round
|
|
184
|
+
round(places) {
|
|
188
185
|
places = Math.max(places || 0, 0);
|
|
189
186
|
return new Color(this.color.map(roundToPlace(places)).concat(this.valpha), this.model);
|
|
190
187
|
},
|
|
191
188
|
|
|
192
|
-
alpha
|
|
193
|
-
if (arguments.length) {
|
|
194
|
-
return new Color(this.color.concat(Math.max(0, Math.min(1,
|
|
189
|
+
alpha(value) {
|
|
190
|
+
if (arguments.length > 0) {
|
|
191
|
+
return new Color(this.color.concat(Math.max(0, Math.min(1, value))), this.model);
|
|
195
192
|
}
|
|
196
193
|
|
|
197
194
|
return this.valpha;
|
|
198
195
|
},
|
|
199
196
|
|
|
200
|
-
//
|
|
197
|
+
// Rgb
|
|
201
198
|
red: getset('rgb', 0, maxfn(255)),
|
|
202
199
|
green: getset('rgb', 1, maxfn(255)),
|
|
203
200
|
blue: getset('rgb', 2, maxfn(255)),
|
|
204
201
|
|
|
205
|
-
hue: getset(['hsl', 'hsv', 'hsl', 'hwb', 'hcg'], 0,
|
|
202
|
+
hue: getset(['hsl', 'hsv', 'hsl', 'hwb', 'hcg'], 0, value => ((value % 360) + 360) % 360),
|
|
206
203
|
|
|
207
204
|
saturationl: getset('hsl', 1, maxfn(100)),
|
|
208
205
|
lightness: getset('hsl', 2, maxfn(100)),
|
|
@@ -229,44 +226,59 @@ Color.prototype = {
|
|
|
229
226
|
a: getset('lab', 1),
|
|
230
227
|
b: getset('lab', 2),
|
|
231
228
|
|
|
232
|
-
keyword
|
|
233
|
-
if (arguments.length) {
|
|
234
|
-
return new Color(
|
|
229
|
+
keyword(value) {
|
|
230
|
+
if (arguments.length > 0) {
|
|
231
|
+
return new Color(value);
|
|
235
232
|
}
|
|
236
233
|
|
|
237
234
|
return convert[this.model].keyword(this.color);
|
|
238
235
|
},
|
|
239
236
|
|
|
240
|
-
hex
|
|
241
|
-
if (arguments.length) {
|
|
242
|
-
return new Color(
|
|
237
|
+
hex(value) {
|
|
238
|
+
if (arguments.length > 0) {
|
|
239
|
+
return new Color(value);
|
|
243
240
|
}
|
|
244
241
|
|
|
245
242
|
return colorString.to.hex(this.rgb().round().color);
|
|
246
243
|
},
|
|
247
244
|
|
|
248
|
-
|
|
249
|
-
|
|
245
|
+
hexa(value) {
|
|
246
|
+
if (arguments.length > 0) {
|
|
247
|
+
return new Color(value);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const rgbArray = this.rgb().round().color;
|
|
251
|
+
|
|
252
|
+
let alphaHex = Math.round(this.valpha * 255).toString(16).toUpperCase();
|
|
253
|
+
if (alphaHex.length === 1) {
|
|
254
|
+
alphaHex = '0' + alphaHex;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return colorString.to.hex(rgbArray) + alphaHex;
|
|
258
|
+
},
|
|
259
|
+
|
|
260
|
+
rgbNumber() {
|
|
261
|
+
const rgb = this.rgb().color;
|
|
250
262
|
return ((rgb[0] & 0xFF) << 16) | ((rgb[1] & 0xFF) << 8) | (rgb[2] & 0xFF);
|
|
251
263
|
},
|
|
252
264
|
|
|
253
|
-
luminosity
|
|
265
|
+
luminosity() {
|
|
254
266
|
// http://www.w3.org/TR/WCAG20/#relativeluminancedef
|
|
255
|
-
|
|
267
|
+
const rgb = this.rgb().color;
|
|
256
268
|
|
|
257
|
-
|
|
258
|
-
for (
|
|
259
|
-
|
|
260
|
-
lum[i] = (chan <= 0.
|
|
269
|
+
const lum = [];
|
|
270
|
+
for (const [i, element] of rgb.entries()) {
|
|
271
|
+
const chan = element / 255;
|
|
272
|
+
lum[i] = (chan <= 0.039_28) ? chan / 12.92 : ((chan + 0.055) / 1.055) ** 2.4;
|
|
261
273
|
}
|
|
262
274
|
|
|
263
275
|
return 0.2126 * lum[0] + 0.7152 * lum[1] + 0.0722 * lum[2];
|
|
264
276
|
},
|
|
265
277
|
|
|
266
|
-
contrast
|
|
278
|
+
contrast(color2) {
|
|
267
279
|
// http://www.w3.org/TR/WCAG20/#contrast-ratiodef
|
|
268
|
-
|
|
269
|
-
|
|
280
|
+
const lum1 = this.luminosity();
|
|
281
|
+
const lum2 = color2.luminosity();
|
|
270
282
|
|
|
271
283
|
if (lum1 > lum2) {
|
|
272
284
|
return (lum1 + 0.05) / (lum2 + 0.05);
|
|
@@ -275,8 +287,8 @@ Color.prototype = {
|
|
|
275
287
|
return (lum2 + 0.05) / (lum1 + 0.05);
|
|
276
288
|
},
|
|
277
289
|
|
|
278
|
-
level
|
|
279
|
-
|
|
290
|
+
level(color2) {
|
|
291
|
+
const contrastRatio = this.contrast(color2);
|
|
280
292
|
if (contrastRatio >= 7.1) {
|
|
281
293
|
return 'AAA';
|
|
282
294
|
}
|
|
@@ -284,128 +296,130 @@ Color.prototype = {
|
|
|
284
296
|
return (contrastRatio >= 4.5) ? 'AA' : '';
|
|
285
297
|
},
|
|
286
298
|
|
|
287
|
-
isDark
|
|
299
|
+
isDark() {
|
|
288
300
|
// YIQ equation from http://24ways.org/2010/calculating-color-contrast
|
|
289
|
-
|
|
290
|
-
|
|
301
|
+
const rgb = this.rgb().color;
|
|
302
|
+
const yiq = (rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1000;
|
|
291
303
|
return yiq < 128;
|
|
292
304
|
},
|
|
293
305
|
|
|
294
|
-
isLight
|
|
306
|
+
isLight() {
|
|
295
307
|
return !this.isDark();
|
|
296
308
|
},
|
|
297
309
|
|
|
298
|
-
negate
|
|
299
|
-
|
|
300
|
-
for (
|
|
310
|
+
negate() {
|
|
311
|
+
const rgb = this.rgb();
|
|
312
|
+
for (let i = 0; i < 3; i++) {
|
|
301
313
|
rgb.color[i] = 255 - rgb.color[i];
|
|
302
314
|
}
|
|
315
|
+
|
|
303
316
|
return rgb;
|
|
304
317
|
},
|
|
305
318
|
|
|
306
|
-
lighten
|
|
307
|
-
|
|
319
|
+
lighten(ratio) {
|
|
320
|
+
const hsl = this.hsl();
|
|
308
321
|
hsl.color[2] += hsl.color[2] * ratio;
|
|
309
322
|
return hsl;
|
|
310
323
|
},
|
|
311
324
|
|
|
312
|
-
darken
|
|
313
|
-
|
|
325
|
+
darken(ratio) {
|
|
326
|
+
const hsl = this.hsl();
|
|
314
327
|
hsl.color[2] -= hsl.color[2] * ratio;
|
|
315
328
|
return hsl;
|
|
316
329
|
},
|
|
317
330
|
|
|
318
|
-
saturate
|
|
319
|
-
|
|
331
|
+
saturate(ratio) {
|
|
332
|
+
const hsl = this.hsl();
|
|
320
333
|
hsl.color[1] += hsl.color[1] * ratio;
|
|
321
334
|
return hsl;
|
|
322
335
|
},
|
|
323
336
|
|
|
324
|
-
desaturate
|
|
325
|
-
|
|
337
|
+
desaturate(ratio) {
|
|
338
|
+
const hsl = this.hsl();
|
|
326
339
|
hsl.color[1] -= hsl.color[1] * ratio;
|
|
327
340
|
return hsl;
|
|
328
341
|
},
|
|
329
342
|
|
|
330
|
-
whiten
|
|
331
|
-
|
|
343
|
+
whiten(ratio) {
|
|
344
|
+
const hwb = this.hwb();
|
|
332
345
|
hwb.color[1] += hwb.color[1] * ratio;
|
|
333
346
|
return hwb;
|
|
334
347
|
},
|
|
335
348
|
|
|
336
|
-
blacken
|
|
337
|
-
|
|
349
|
+
blacken(ratio) {
|
|
350
|
+
const hwb = this.hwb();
|
|
338
351
|
hwb.color[2] += hwb.color[2] * ratio;
|
|
339
352
|
return hwb;
|
|
340
353
|
},
|
|
341
354
|
|
|
342
|
-
grayscale
|
|
355
|
+
grayscale() {
|
|
343
356
|
// http://en.wikipedia.org/wiki/Grayscale#Converting_color_to_grayscale
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
return Color.rgb(
|
|
357
|
+
const rgb = this.rgb().color;
|
|
358
|
+
const value = rgb[0] * 0.3 + rgb[1] * 0.59 + rgb[2] * 0.11;
|
|
359
|
+
return Color.rgb(value, value, value);
|
|
347
360
|
},
|
|
348
361
|
|
|
349
|
-
fade
|
|
362
|
+
fade(ratio) {
|
|
350
363
|
return this.alpha(this.valpha - (this.valpha * ratio));
|
|
351
364
|
},
|
|
352
365
|
|
|
353
|
-
opaquer
|
|
366
|
+
opaquer(ratio) {
|
|
354
367
|
return this.alpha(this.valpha + (this.valpha * ratio));
|
|
355
368
|
},
|
|
356
369
|
|
|
357
|
-
rotate
|
|
358
|
-
|
|
359
|
-
|
|
370
|
+
rotate(degrees) {
|
|
371
|
+
const hsl = this.hsl();
|
|
372
|
+
let hue = hsl.color[0];
|
|
360
373
|
hue = (hue + degrees) % 360;
|
|
361
374
|
hue = hue < 0 ? 360 + hue : hue;
|
|
362
375
|
hsl.color[0] = hue;
|
|
363
376
|
return hsl;
|
|
364
377
|
},
|
|
365
378
|
|
|
366
|
-
mix
|
|
367
|
-
//
|
|
379
|
+
mix(mixinColor, weight) {
|
|
380
|
+
// Ported from sass implementation in C
|
|
368
381
|
// https://github.com/sass/libsass/blob/0e6b4a2850092356aa3ece07c6b249f0221caced/functions.cpp#L209
|
|
369
382
|
if (!mixinColor || !mixinColor.rgb) {
|
|
370
383
|
throw new Error('Argument to "mix" was not a Color instance, but rather an instance of ' + typeof mixinColor);
|
|
371
384
|
}
|
|
372
|
-
var color1 = mixinColor.rgb();
|
|
373
|
-
var color2 = this.rgb();
|
|
374
|
-
var p = weight === undefined ? 0.5 : weight;
|
|
375
385
|
|
|
376
|
-
|
|
377
|
-
|
|
386
|
+
const color1 = mixinColor.rgb();
|
|
387
|
+
const color2 = this.rgb();
|
|
388
|
+
const p = weight === undefined ? 0.5 : weight;
|
|
378
389
|
|
|
379
|
-
|
|
380
|
-
|
|
390
|
+
const w = 2 * p - 1;
|
|
391
|
+
const a = color1.alpha() - color2.alpha();
|
|
392
|
+
|
|
393
|
+
const w1 = (((w * a === -1) ? w : (w + a) / (1 + w * a)) + 1) / 2;
|
|
394
|
+
const w2 = 1 - w1;
|
|
381
395
|
|
|
382
396
|
return Color.rgb(
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
}
|
|
397
|
+
w1 * color1.red() + w2 * color2.red(),
|
|
398
|
+
w1 * color1.green() + w2 * color2.green(),
|
|
399
|
+
w1 * color1.blue() + w2 * color2.blue(),
|
|
400
|
+
color1.alpha() * p + color2.alpha() * (1 - p));
|
|
401
|
+
},
|
|
388
402
|
};
|
|
389
403
|
|
|
390
|
-
//
|
|
391
|
-
Object.keys(convert)
|
|
392
|
-
if (skippedModels.
|
|
393
|
-
|
|
404
|
+
// Model conversion methods and static constructors
|
|
405
|
+
for (const model of Object.keys(convert)) {
|
|
406
|
+
if (skippedModels.includes(model)) {
|
|
407
|
+
continue;
|
|
394
408
|
}
|
|
395
409
|
|
|
396
|
-
|
|
410
|
+
const channels = convert[model].channels;
|
|
397
411
|
|
|
398
|
-
//
|
|
412
|
+
// Conversion methods
|
|
399
413
|
Color.prototype[model] = function () {
|
|
400
414
|
if (this.model === model) {
|
|
401
415
|
return new Color(this);
|
|
402
416
|
}
|
|
403
417
|
|
|
404
|
-
if (arguments.length) {
|
|
418
|
+
if (arguments.length > 0) {
|
|
405
419
|
return new Color(arguments, model);
|
|
406
420
|
}
|
|
407
421
|
|
|
408
|
-
|
|
422
|
+
const newAlpha = typeof arguments[channels] === 'number' ? channels : this.valpha;
|
|
409
423
|
return new Color(assertArray(convert[this.model][model].raw(this.color)).concat(newAlpha), model);
|
|
410
424
|
};
|
|
411
425
|
|
|
@@ -414,39 +428,40 @@ Object.keys(convert).forEach(function (model) {
|
|
|
414
428
|
if (typeof color === 'number') {
|
|
415
429
|
color = zeroArray(_slice.call(arguments), channels);
|
|
416
430
|
}
|
|
431
|
+
|
|
417
432
|
return new Color(color, model);
|
|
418
433
|
};
|
|
419
|
-
}
|
|
434
|
+
}
|
|
420
435
|
|
|
421
|
-
function roundTo(
|
|
422
|
-
return Number(
|
|
436
|
+
function roundTo(number, places) {
|
|
437
|
+
return Number(number.toFixed(places));
|
|
423
438
|
}
|
|
424
439
|
|
|
425
440
|
function roundToPlace(places) {
|
|
426
|
-
return function (
|
|
427
|
-
return roundTo(
|
|
441
|
+
return function (number) {
|
|
442
|
+
return roundTo(number, places);
|
|
428
443
|
};
|
|
429
444
|
}
|
|
430
445
|
|
|
431
446
|
function getset(model, channel, modifier) {
|
|
432
447
|
model = Array.isArray(model) ? model : [model];
|
|
433
448
|
|
|
434
|
-
|
|
449
|
+
for (const m of model) {
|
|
435
450
|
(limiters[m] || (limiters[m] = []))[channel] = modifier;
|
|
436
|
-
}
|
|
451
|
+
}
|
|
437
452
|
|
|
438
453
|
model = model[0];
|
|
439
454
|
|
|
440
|
-
return function (
|
|
441
|
-
|
|
455
|
+
return function (value) {
|
|
456
|
+
let result;
|
|
442
457
|
|
|
443
|
-
if (arguments.length) {
|
|
458
|
+
if (arguments.length > 0) {
|
|
444
459
|
if (modifier) {
|
|
445
|
-
|
|
460
|
+
value = modifier(value);
|
|
446
461
|
}
|
|
447
462
|
|
|
448
463
|
result = this[model]();
|
|
449
|
-
result.color[channel] =
|
|
464
|
+
result.color[channel] = value;
|
|
450
465
|
return result;
|
|
451
466
|
}
|
|
452
467
|
|
|
@@ -465,18 +480,18 @@ function maxfn(max) {
|
|
|
465
480
|
};
|
|
466
481
|
}
|
|
467
482
|
|
|
468
|
-
function assertArray(
|
|
469
|
-
return Array.isArray(
|
|
483
|
+
function assertArray(value) {
|
|
484
|
+
return Array.isArray(value) ? value : [value];
|
|
470
485
|
}
|
|
471
486
|
|
|
472
|
-
function zeroArray(
|
|
473
|
-
for (
|
|
474
|
-
if (typeof
|
|
475
|
-
|
|
487
|
+
function zeroArray(array, length) {
|
|
488
|
+
for (let i = 0; i < length; i++) {
|
|
489
|
+
if (typeof array[i] !== 'number') {
|
|
490
|
+
array[i] = 0;
|
|
476
491
|
}
|
|
477
492
|
}
|
|
478
493
|
|
|
479
|
-
return
|
|
494
|
+
return array;
|
|
480
495
|
}
|
|
481
496
|
|
|
482
497
|
module.exports = Color;
|