Comparing version 0.1.0 to 1.0.0
{ | ||
"name": "color-bits", | ||
"version": "0.1.0", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"sideEffects": false, | ||
"exports": { | ||
@@ -13,2 +14,10 @@ ".": "./build/index.js", | ||
"description": "", | ||
"publishConfig": { | ||
"ignore": [ | ||
"!build/", | ||
"docs/", | ||
"src/", | ||
"test/" | ||
] | ||
}, | ||
"devDependencies": { | ||
@@ -20,5 +29,15 @@ "@babel/preset-env": "^7.25.4", | ||
"@types/jest": "^29.5.12", | ||
"benny": "^3.7.1", | ||
"chai": "^5.1.1", | ||
"chroma-js": "^3.0.0", | ||
"color": "^4.2.3", | ||
"colord": "^2.9.3", | ||
"jest": "^29.7.0", | ||
"npmignore": "^0.3.1", | ||
"tinycolor2": "^1.6.0", | ||
"ts-jest": "^29.2.5", | ||
"tsdoc-markdown": "^0.6.0", | ||
"tsx": "^4.19.0", | ||
"typedoc": "^0.26.6", | ||
"typedoc-plugin-markdown": "^4.2.6", | ||
"typescript": "^5.5.4" | ||
@@ -29,4 +48,8 @@ }, | ||
"start": "tsc --watch", | ||
"docs": "pnpm run docs:core && pnpm run docs:string", | ||
"docs:core": "typedoc --readme none --plugin typedoc-plugin-markdown --out ./docs ./src/index.ts", | ||
"docs:string": "typedoc --readme none --plugin typedoc-plugin-markdown --out ./docs/string ./src/string.ts", | ||
"benchmark": "tsx ./benchmarks/index.ts", | ||
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest --watch" | ||
} | ||
} |
@@ -1,3 +0,83 @@ | ||
# color-bits | ||
<h1 align="center"> | ||
color-bits | ||
</h1> | ||
Fast & efficient color manipulation library. | ||
<p align="center"> | ||
<b>High-performance color library</b> | ||
</p> | ||
This library represents RGBA colors as a single `int32` number and avoids allocating memory as much as possible while parsing, handling, and formatting colors, to provide the best possible memory and CPU efficiency. | ||
<p align="center"> | ||
<a href="#-benchmarks">Benchmarks</a> • | ||
<a href="#-install">Install</a> • | ||
<a href="#-technical-details">Technical details</a> • | ||
<a href="#-documentation">Documentation</a> • | ||
<a href="#-license">License</a> | ||
</p> | ||
<p align="center"> | ||
<small>🔴🟠🟡🟢🔵🟣</small> | ||
</p> | ||
### ⚡ Benchmarks | ||
| Library | Operations/sec | Relative speed | | ||
| --- | --: | --- | | ||
| **color-bits** | **22 966 299** | fastest | | ||
| colord | 4 308 547 | 81.24% slower | | ||
| tinycolor2 | 1 475 762 | 93.57% slower | | ||
| chroma-js | 846 924 | 96.31% slower | | ||
| color | 799 262 | 96.52% slower | | ||
### 🛠️ Install | ||
```sh | ||
pnpm install color-bits | ||
``` | ||
### 📑 Technical details | ||
Due to the compact representation, `color-bits` preserves **at most 8 bits of precision for each channel**, so an operation like `alpha(color, 0.000001)` would simply return the same color with no modification. | ||
`color-bits` supports the full **CSS Color Module Level 4** color spaces **in absolute representations only**, so: | ||
- Yes: `oklab(59.69% 0.1007 0.1191)` | ||
- No: `oklab(from green l a b / 0.5)` | ||
When parsing and converting non-sRGB color spaces, `color-bits` behaves the same as browsers behave, 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. | ||
For performance reasons, the representation is `int32`, not `uint32`. It is expected if you see negative numbers when you print the color value. | ||
Every function is tree-shakeable, so the bundle size cost should be from 1.5kb to 3kb, depending on which functions you use. | ||
### 📚 Documentation | ||
[Documentation: `'color-bits'`](https://github.com/romgrk/color-bits/tree/master/docs/README.md) | ||
[Documentation: `'color-bits/string'`](https://github.com/romgrk/color-bits/tree/master/docs/string/README.md) | ||
If you're storing and manipulating colors frequently, you should use the `color-bits` exports directly, e.g. | ||
```tsx | ||
import * as Color from 'color-bits' | ||
const background = Color.parse('#232323') | ||
const seeThrough = Color.alpha(backround, 0.5) | ||
const output = Color.format(seeThrough) // #RRGGBBAA string | ||
``` | ||
The `color-bits/string` exports wrap some of the functions to accept string colors as input/output, which may be used if you're not storing the colors but just transforming them on the fly. | ||
```tsx | ||
import * as Color from 'color-bits/string' | ||
const background = '#232323' | ||
const output = Color.alpha(backround, 0.5) // #RRGGBBAA string | ||
``` | ||
### 📜 License | ||
I release any of the code here to the public domain. Feel free to copy/paste in part or in full without attribution. 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. | ||
<p align="center"> | ||
<small>🔴🟠🟡🟢🔵🟣</small> | ||
</p> |
{ | ||
"compilerOptions": { | ||
"module": "ES2022", | ||
"module": "NodeNext", | ||
"moduleResolution": "NodeNext", | ||
"lib": ["ES2017"], | ||
@@ -10,3 +11,4 @@ "strict": true, | ||
"outDir": "./build", | ||
"sourceMap": true | ||
"sourceMap": true, | ||
"declaration": true | ||
}, | ||
@@ -13,0 +15,0 @@ "include": ["src/**/*"], |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
98860
36
1411
1
84
19
1