Skip to content

Commit e70d288

Browse files
committed
Remove color-normalize dependency
1 parent 4d4e767 commit e70d288

6 files changed

Lines changed: 25 additions & 5 deletions

File tree

package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
"@turf/meta": "^7.3.5",
7676
"base64-arraybuffer": "^1.0.2",
7777
"color": "^5.0.3",
78-
"color-normalize": "1.5.0",
7978
"country-iso-search": "^0.1.1",
8079
"d3-force": "^1.2.1",
8180
"d3-format": "^1.4.5",

src/components/color/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,27 @@ const rgb = (cstr) => {
4040
*/
4141
const opacity = (cstr) => (cstr ? color(cstr).alpha() : 0);
4242

43+
/**
44+
* Convert a color specifier to a 4-element `[r, g, b, a]` representation.
45+
*
46+
* @param {*} cstr - color specifier
47+
* @param {'float'|'uint8'} [type='float'] - `'float'` returns `[r, g, b, a]` in `[0, 1]`;
48+
* `'uint8'` returns a `Uint8Array` in `[0, 255]`.
49+
* @return {Number[]|Uint8Array}
50+
*/
51+
const normalize = (cstr, type) => {
52+
const [r, g, b, a] = color(cstr).rgb().array();
53+
if (type === 'uint8') {
54+
const out = new Uint8Array(4);
55+
out[0] = r;
56+
out[1] = g;
57+
out[2] = b;
58+
out[3] = Math.floor(a * 255);
59+
return out;
60+
}
61+
return [r / 255, g / 255, b / 255, a];
62+
};
63+
4364
/**
4465
* Build an `rgba(...)` string from a color and an explicit opacity value.
4566
*
@@ -265,6 +286,7 @@ module.exports = {
265286
lightLine,
266287
mix,
267288
mostReadable,
289+
normalize,
268290
opacity,
269291
rgb,
270292
stroke

src/lib/gl_format_color.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict';
22

33
var isNumeric = require('fast-isnumeric');
4-
var rgba = require('color-normalize');
54

65
var Colorscale = require('../components/colorscale');
76
var Color = require('../components/color');
7+
var rgba = Color.normalize;
88
var colorDflt = require('../components/color/attributes').defaultLine;
99
var isArrayOrTypedArray = require('./array').isArrayOrTypedArray;
1010

src/lib/str2rgbarray.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
var rgba = require('color-normalize');
3+
const { normalize: rgba } = require('../components/color');
44

55
function str2RgbaArray(color) {
66
if(!color) return [0, 0, 0, 1];

src/traces/scattergl/convert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
var isNumeric = require('fast-isnumeric');
44
var svgSdf = require('svg-path-sdf');
5-
var rgba = require('color-normalize');
5+
const { normalize: rgba } = require('../../components/color');
66

77
var Registry = require('../../registry');
88
var Lib = require('../../lib');

0 commit comments

Comments
 (0)