color-bits 1.0.2 → 1.0.4
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/README.md +7 -8
- package/package.json +2 -1
- package/build/transform.d.ts +0 -19
- package/build/transform.js +0 -40
- package/build/transform.js.map +0 -1
- package/build/transformString.d.ts +0 -3
- package/build/transformString.js +0 -35
- package/build/transformString.js.map +0 -1
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@ Due to the compact representation, `color-bits` preserves **at most 8 bits of pr
|
|
|
44
44
|
- Yes: `oklab(59.69% 0.1007 0.1191)`
|
|
45
45
|
- No: `oklab(from green l a b / 0.5)`
|
|
46
46
|
|
|
47
|
-
When parsing and converting non-sRGB color spaces, `color-bits` behaves the same as browsers
|
|
47
|
+
When parsing and converting non-sRGB color spaces, `color-bits` behaves the same as browsers do, which differs from the formal CSS spec! In technical terms: non-sRGB color spaces with a wider gamut are converted using clipping rather than gamut-mapping.
|
|
48
48
|
|
|
49
49
|
For performance reasons, the representation is `int32`, not `uint32`. It is expected if you see negative numbers when you print the color value.
|
|
50
50
|
|
|
@@ -52,8 +52,8 @@ Every function is tree-shakeable, so the bundle size cost should be from 1.5kb t
|
|
|
52
52
|
|
|
53
53
|
### 📚 Documentation
|
|
54
54
|
|
|
55
|
-
[
|
|
56
|
-
[
|
|
55
|
+
[Docs for color-bits](https://github.com/romgrk/color-bits/tree/master/docs/README.md)
|
|
56
|
+
[Docs for color-bits/string](https://github.com/romgrk/color-bits/tree/master/docs/string/README.md)
|
|
57
57
|
|
|
58
58
|
If you're storing and manipulating colors frequently, you should use the `color-bits` exports directly, e.g.
|
|
59
59
|
|
|
@@ -61,24 +61,23 @@ If you're storing and manipulating colors frequently, you should use the `color-
|
|
|
61
61
|
import * as Color from 'color-bits'
|
|
62
62
|
|
|
63
63
|
const background = Color.parse('#232323')
|
|
64
|
-
const seeThrough = Color.alpha(
|
|
64
|
+
const seeThrough = Color.alpha(background, 0.5)
|
|
65
65
|
const output = Color.format(seeThrough) // #RRGGBBAA string
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
The `color-bits/string`
|
|
68
|
+
The `color-bits/string` module wraps some of the functions to accept string colors as input/output, which may be useful if you're not storing the colors but just transforming them on the fly. It can be faster than calling the functions separately in some cases.
|
|
69
69
|
|
|
70
70
|
```tsx
|
|
71
71
|
import * as Color from 'color-bits/string'
|
|
72
72
|
|
|
73
|
-
const
|
|
74
|
-
const output = Color.alpha(backround, 0.5) // #RRGGBBAA string
|
|
73
|
+
const output = Color.alpha('#232323', 0.5) // #RRGGBBAA string
|
|
75
74
|
```
|
|
76
75
|
|
|
77
76
|
### 📜 License
|
|
78
77
|
|
|
79
78
|
I release any of the code I wrote here to the public domain. Feel free to copy/paste in part or in full without attribution.
|
|
80
79
|
|
|
81
|
-
Some parts of the codebase have been extracted from Chrome's devtools, MaterialUI, and stackoverflow, those contain a license notice or attribution in code comments, inline.
|
|
80
|
+
Some parts of the codebase have been extracted from Chrome's devtools, MaterialUI, and stackoverflow, those contain a license notice or attribution in code comments, inline. Everything is MIT-compatible.
|
|
82
81
|
|
|
83
82
|
<p align="center">
|
|
84
83
|
<small>🔴🟠🟡🟢🔵🟣</small>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "color-bits",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"exports": {
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"./*": "./build/*",
|
|
9
9
|
"./string": "./build/string.js"
|
|
10
10
|
},
|
|
11
|
+
"types": "./build/index.d.ts",
|
|
11
12
|
"keywords": [
|
|
12
13
|
"color",
|
|
13
14
|
"colors"
|
package/build/transform.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Color } from './core';
|
|
2
|
-
/**
|
|
3
|
-
* Modifies color alpha channel.
|
|
4
|
-
* @param color - Color
|
|
5
|
-
* @param value - Value in the range [0, 1]
|
|
6
|
-
*/
|
|
7
|
-
export declare function alpha(color: Color, value: number): Color;
|
|
8
|
-
/**
|
|
9
|
-
* Darkens a color.
|
|
10
|
-
* @param color - Color
|
|
11
|
-
* @param coefficient - Multiplier in the range [0, 1]
|
|
12
|
-
*/
|
|
13
|
-
export declare function darken(color: Color, coefficient: number): Color;
|
|
14
|
-
/**
|
|
15
|
-
* Lighten a color.
|
|
16
|
-
* @param color - Color
|
|
17
|
-
* @param coefficient - Multiplier in the range [0, 1]
|
|
18
|
-
*/
|
|
19
|
-
export declare function lighten(color: Color, coefficient: number): Color;
|
package/build/transform.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.alpha = alpha;
|
|
4
|
-
exports.darken = darken;
|
|
5
|
-
exports.lighten = lighten;
|
|
6
|
-
const core_1 = require("./core");
|
|
7
|
-
/**
|
|
8
|
-
* Modifies color alpha channel.
|
|
9
|
-
* @param color - Color
|
|
10
|
-
* @param value - Value in the range [0, 1]
|
|
11
|
-
*/
|
|
12
|
-
function alpha(color, value) {
|
|
13
|
-
return (0, core_1.setAlpha)(color, Math.round(value * 255));
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Darkens a color.
|
|
17
|
-
* @param color - Color
|
|
18
|
-
* @param coefficient - Multiplier in the range [0, 1]
|
|
19
|
-
*/
|
|
20
|
-
function darken(color, coefficient) {
|
|
21
|
-
const r = (0, core_1.getRed)(color);
|
|
22
|
-
const g = (0, core_1.getGreen)(color);
|
|
23
|
-
const b = (0, core_1.getBlue)(color);
|
|
24
|
-
const a = (0, core_1.getAlpha)(color);
|
|
25
|
-
const factor = 1 - coefficient;
|
|
26
|
-
return (0, core_1.newColor)(r * factor, g * factor, b * factor, a);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Lighten a color.
|
|
30
|
-
* @param color - Color
|
|
31
|
-
* @param coefficient - Multiplier in the range [0, 1]
|
|
32
|
-
*/
|
|
33
|
-
function lighten(color, coefficient) {
|
|
34
|
-
const r = (0, core_1.getRed)(color);
|
|
35
|
-
const g = (0, core_1.getGreen)(color);
|
|
36
|
-
const b = (0, core_1.getBlue)(color);
|
|
37
|
-
const a = (0, core_1.getAlpha)(color);
|
|
38
|
-
return (0, core_1.newColor)(r + (255 - r) * coefficient, g + (255 - g) * coefficient, b + (255 - b) * coefficient, a);
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=transform.js.map
|
package/build/transform.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../src/transform.ts"],"names":[],"mappings":";;AAeA,sBAEC;AAOD,wBAcC;AAOD,0BAYC;AAzDD,iCAQgB;AAEhB;;;;GAIG;AACH,SAAgB,KAAK,CAAC,KAAY,EAAE,KAAa;IAC/C,OAAO,IAAA,eAAQ,EAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC,CAAA;AACjD,CAAC;AAED;;;;GAIG;AACH,SAAgB,MAAM,CAAC,KAAY,EAAE,WAAmB;IACtD,MAAM,CAAC,GAAG,IAAA,aAAM,EAAC,KAAK,CAAC,CAAC;IACxB,MAAM,CAAC,GAAG,IAAA,eAAQ,EAAC,KAAK,CAAC,CAAC;IAC1B,MAAM,CAAC,GAAG,IAAA,cAAO,EAAC,KAAK,CAAC,CAAC;IACzB,MAAM,CAAC,GAAG,IAAA,eAAQ,EAAC,KAAK,CAAC,CAAC;IAE1B,MAAM,MAAM,GAAG,CAAC,GAAG,WAAW,CAAC;IAE/B,OAAO,IAAA,eAAQ,EACb,CAAC,GAAG,MAAM,EACV,CAAC,GAAG,MAAM,EACV,CAAC,GAAG,MAAM,EACV,CAAC,CACF,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,SAAgB,OAAO,CAAC,KAAY,EAAE,WAAmB;IACvD,MAAM,CAAC,GAAG,IAAA,aAAM,EAAC,KAAK,CAAC,CAAC;IACxB,MAAM,CAAC,GAAG,IAAA,eAAQ,EAAC,KAAK,CAAC,CAAC;IAC1B,MAAM,CAAC,GAAG,IAAA,cAAO,EAAC,KAAK,CAAC,CAAC;IACzB,MAAM,CAAC,GAAG,IAAA,eAAQ,EAAC,KAAK,CAAC,CAAC;IAE1B,OAAO,IAAA,eAAQ,EACb,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,WAAW,EAC3B,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,WAAW,EAC3B,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,WAAW,EAC3B,CAAC,CACF,CAAA;AACH,CAAC"}
|
package/build/transformString.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.alpha = alpha;
|
|
27
|
-
exports.darken = darken;
|
|
28
|
-
exports.lighten = lighten;
|
|
29
|
-
const core_1 = require("./core");
|
|
30
|
-
const parse_1 = require("./parse");
|
|
31
|
-
const Transform = __importStar(require("./transform"));
|
|
32
|
-
function alpha(color, value) { return (0, core_1.from)(Transform.alpha((0, parse_1.parse)(color), value)); }
|
|
33
|
-
function darken(color, value) { return (0, core_1.from)(Transform.darken((0, parse_1.parse)(color), value)); }
|
|
34
|
-
function lighten(color, value) { return (0, core_1.from)(Transform.lighten((0, parse_1.parse)(color), value)); }
|
|
35
|
-
//# sourceMappingURL=transformString.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transformString.js","sourceRoot":"","sources":["../src/transformString.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAIA,sBAAyG;AACzG,wBAA2G;AAC3G,0BAA6G;AAN7G,iCAA6B;AAC7B,mCAA+B;AAC/B,uDAAwC;AAExC,SAAgB,KAAK,CAAC,KAAa,EAAE,KAAa,IAAI,OAAO,IAAA,WAAI,EAAC,SAAS,CAAC,KAAK,CAAC,IAAA,aAAK,EAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,CAAA,CAAC,CAAC;AACzG,SAAgB,MAAM,CAAC,KAAa,EAAE,KAAa,IAAI,OAAO,IAAA,WAAI,EAAC,SAAS,CAAC,MAAM,CAAC,IAAA,aAAK,EAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,CAAA,CAAC,CAAC;AAC3G,SAAgB,OAAO,CAAC,KAAa,EAAE,KAAa,IAAI,OAAO,IAAA,WAAI,EAAC,SAAS,CAAC,OAAO,CAAC,IAAA,aAAK,EAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,CAAA,CAAC,CAAC"}
|