Skip to content

Commit

Permalink
feat: add gray and add ral, hks, apple and ansi extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Skyleen77 committed Mar 10, 2024
1 parent 822caef commit 7efeeea
Show file tree
Hide file tree
Showing 21 changed files with 1,000 additions and 7 deletions.
70 changes: 69 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
## Features

- **Fully typed** - Written in TypeScript
- **Tiny** - Less than 3kb gzipped
- **Tiny** - Less than 3kb gzipped (without plugins)
- **Fast** - 3x faster than the most popular color library
- **Simple** - Chainable methods
- **Complete** - Supports a lot of color models
Expand Down Expand Up @@ -49,6 +49,8 @@ colorblender({ h: 360, s: 100, l: 100, a: 1 });
// HSV
colorblender({ h: 360, s: 100, v: 100 });
colorblender({ h: 360, s: 100, v: 100, a: 1 });
// Gray
colorblender({ gray: 100 });
// HWB (with extension hwb)
colorblender({ h: 0, s: 0, i: 1 });
colorblender({ h: 0, s: 0, i: 1, a: 1 });
Expand All @@ -67,6 +69,14 @@ colorblender({ l: 100, a: 0, b: 0, alpha: 1 }); // for lab, you need to use alph
// LCH (with extension lch)
colorblender({ l: 100, c: 0, h: 0 });
colorblender({ l: 100, c: 0, h: 0, a: 1 });
// Ansi16 (with extension ansi)
colorblender({ ansi16: 97 });
// Ansi256 (with extension ansi)
colorblender({ ansi256: 231 });
// RAL (with extension ral)
colorblender('9010');
// HKS (with extension hks)
colorblender('81-K');
// Name (with extension name)
colorblender('White');
// Keyword (with extension keyword)
Expand Down Expand Up @@ -128,6 +138,15 @@ colorblender({ r: 167, g: 40, b: 13 }).hsv(true); // { h: 10.519480519480492, s:

</details>

<details>
<summary><b><code>.gray(raw = false)</code></b></summary><br>

```typescript
colorblender({ r: 167, g: 40, b: 13 }).gray(); // { gray: 29 }
```

</details>

<details>
<summary><b><code>.hwb(raw = false)</code></b> extension <b>hwb</b></summary><br>

Expand Down Expand Up @@ -194,6 +213,51 @@ colorblender({ r: 167, g: 40, b: 13 }).lch(true); // { l: 37.41702066350787, c:

</details>

<details>
<summary><b><code>.ansi16()</code></b> extension <b>ansi</b></summary><br>

```typescript
colorblender({ r: 167, g: 40, b: 13 }).ansi16(); // { ansi16: 31 }
```

</details>

<details>
<summary><b><code>.ansi256()</code></b> extension <b>ansi</b></summary><br>

```typescript
colorblender({ r: 167, g: 40, b: 13 }).ansi256(); // { ansi256: 130 }
```

</details>

<details>
<summary><b><code>.apple(raw = false)</code></b> extension <b>apple</b></summary><br>

```typescript
colorblender({ r: 167, g: 40, b: 13 }).apple(); // { r: 42919, g: 10280, b: 3341, a: 1 }
```

</details>

<details>
<summary><b><code>.ral()</code></b> extension <b>ral</b></summary><br>

```typescript
colorblender({ r: 167, g: 40, b: 13 }).ral(); // "3013"
```

</details>

<details>
<summary><b><code>.hks()</code></b> extension <b>hks</b></summary><br>

```typescript
colorblender({ r: 167, g: 40, b: 13 }).hks(); // "82-K"
```

</details>

<details>
<summary><b><code>.name()</code></b> extension <b>name</b></summary><br>

Expand Down Expand Up @@ -601,6 +665,10 @@ extend([hwbExtension, mixExtension]);
- **mix** - Mix colors and create palettes _0.52kb_
- **a11y** - Accessibility analysis _0.48kb_
- **harmony** - Color harmonies _0.34kb_
- **ansi** - ANSI color models _1.48kb_
- **apple** - APPLE color models _0.4kb_
- **ral** - RAL color models _4.13kb_
- **hks** - HKS color models _6.12kb_

## Issues

Expand Down
26 changes: 25 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "colorblender",
"version": "2.2.1",
"version": "2.3.1",
"description": "A powerful and fully typed color library.",
"repository": {
"type": "git",
Expand All @@ -27,6 +27,18 @@
"require": "./extensions/a11y.js",
"default": "./extensions/a11y.mjs"
},
"./extensions/ansi": {
"types": "./extensions/ansi.d.ts",
"import": "./extensions/ansi.mjs",
"require": "./extensions/ansi.js",
"default": "./extensions/ansi.mjs"
},
"./extensions/apple": {
"types": "./extensions/apple.d.ts",
"import": "./extensions/apple.mjs",
"require": "./extensions/apple.js",
"default": "./extensions/apple.mjs"
},
"./extensions/cmyk": {
"types": "./extensions/cmyk.d.ts",
"import": "./extensions/cmyk.mjs",
Expand All @@ -51,6 +63,12 @@
"require": "./extensions/hwb.js",
"default": "./extensions/hwb.mjs"
},
"./extensions/hks": {
"types": "./extensions/hks.d.ts",
"import": "./extensions/hks.mjs",
"require": "./extensions/hks.js",
"default": "./extensions/hks.mjs"
},
"./extensions/keyword": {
"types": "./extensions/keyword.d.ts",
"import": "./extensions/keyword.mjs",
Expand Down Expand Up @@ -81,6 +99,12 @@
"require": "./extensions/mix.js",
"default": "./extensions/mix.mjs"
},
"./extensions/ral": {
"types": "./extensions/ral.d.ts",
"import": "./extensions/ral.mjs",
"require": "./extensions/ral.js",
"default": "./extensions/ral.mjs"
},
"./extensions/xyz": {
"types": "./extensions/xyz.d.ts",
"import": "./extensions/xyz.mjs",
Expand Down
13 changes: 13 additions & 0 deletions src/colorblender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
HslColor,
HwbaColor,
HwbColor,
GrayColor,
} from './types';

import { brightness } from './helpers/analysis/brightness';
Expand All @@ -22,6 +23,7 @@ import { lighten } from './helpers/manipulation/lighten';
import { negate } from './helpers/manipulation/negate';
import { saturate } from './helpers/manipulation/saturate';
import { round, roundColor } from './helpers/utils';
import { rgbToGray } from './helpers/converters/gray';

export class Colorblender {
readonly _internalValid: boolean;
Expand Down Expand Up @@ -115,6 +117,17 @@ export class Colorblender {
return this._getColorFormat(rgbToHsv, raw) as HsvaColor;
}

/**
* @returns the color in the Gray format.
*/
public gray(raw = false): GrayColor {
return {
...(raw
? rgbToGray(this._internalRgb)
: roundColor(rgbToGray(this._internalRgb))),
};
}

/**
* @returns true if the color is valid, false otherwise.
*/
Expand Down
Loading

0 comments on commit 7efeeea

Please sign in to comment.