From 2b9a477af15ed3cf4c7b6841b2b147bbc05d6ff6 Mon Sep 17 00:00:00 2001 From: Vlad Shilov Date: Wed, 28 Apr 2021 22:57:35 +0300 Subject: [PATCH] Add `mix` to the docs --- README.md | 50 ++++++++++++++++++++++++++++++++++++++++++---- src/plugins/mix.ts | 2 +- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b30e7cd..ab24662 100644 --- a/README.md +++ b/README.md @@ -378,6 +378,27 @@ colord("hsl(0, 50%, 100%)").lighten(0.5).toHslString(); // "hsl(0, 50%, 50%)" +
+ mix(color2, ratio = 0.5) (mix plugin) + +Produces a mixture of two colors and returns the result of mixing them (new Colord instance). + +In contrast to other libraries that perform RGB values mixing, Colord mixes colors through LCH color space — same way the new CSS [`color-mix` function](https://drafts.csswg.org/css-color-5/#funcdef-color-mix) works. This approach produces better results and doesn't have the drawbacks the legacy way has. + +```js +import { colord, extend } from "colord"; +import mixPlugin from "colord/plugins/mix"; + +extend([mixPlugin]); + +colord("#ffffff").mix("#000000").toHex(); // "#777777" +colord("#800080").mix("#dda0dd").toHex(); // "#af5cae" +colord("#cd853f").mix("#eee8aa", 0.6).toHex(); // "#dfc279" +colord("#008080").mix("#808000", 0.35).toHex(); // "#14865f" +``` + +
+ ### Color analysis
@@ -546,7 +567,7 @@ colord({ h: 0, w: 100, b: 0, a: 1 }).toHex(); // "#ffffff"
- lab (CIE LAB color space) 0.78 KB + lab (CIE LAB color space) 0.9 KB Adds support of [CIE LAB](https://en.wikipedia.org/wiki/CIELAB_color_space) color model. The conversion logic is ported from [CSS Color Module Level 4 Specification](https://www.w3.org/TR/css-color-4/#color-conversion-code). @@ -563,7 +584,7 @@ colord("#ffffff").toLab(); // { l: 100, a: 0, b: 0, alpha: 1 }
- lch (CIE LCH color space) 1 KB + lch (CIE LCH color space) 1.2 KB Adds support of [CIE LCH](https://lea.verou.me/2020/04/lch-colors-in-css-what-why-and-how/) color space. The conversion logic is ported from [CSS Color Module Level 4 Specification](https://www.w3.org/TR/css-color-4/#color-conversion-code). @@ -582,6 +603,27 @@ colord("#646464").alpha(0.5).toLchString(); // "lch(42.37% 0 0 / 0.5)"
+
+ mix (Color mixing) 0.97 KB + +A plugin adding a color mixing utility. + +In contrast to other libraries that perform RGB values mixing, Colord mixes colors through LCH color space — same way the new CSS [`color-mix` function](https://drafts.csswg.org/css-color-5/#funcdef-color-mix) works. This approach produces better results and doesn't have the drawbacks the legacy way has. + +```js +import { colord, extend } from "colord"; +import mixPlugin from "colord/plugins/mix"; + +extend([mixPlugin]); + +colord("#ffffff").mix("#000000").toHex(); // "#777777" +colord("#800080").mix("#dda0dd").toHex(); // "#af5cae" +colord("#cd853f").mix("#eee8aa", 0.6).toHex(); // "#dfc279" +colord("#008080").mix("#808000", 0.35).toHex(); // "#14865f" +``` + +
+
names (CSS color keywords) 1.29 KB @@ -602,7 +644,7 @@ colord("rgba(0, 0, 0, 0)").toName(); // "transparent"
- xyz (CIE XYZ color space) 0.6 KB + xyz (CIE XYZ color space) 0.7 KB Adds support of [CIE XYZ](https://www.sttmedia.com/colormodel-xyz) color model. The conversion logic is ported from [CSS Color Module Level 4 Specification](https://www.w3.org/TR/css-color-4/#color-conversion-code). @@ -653,5 +695,5 @@ const bar: RgbColor = { r: 0, g: 0, v: 0 }; // ERROR - [x] [HWB](https://drafts.csswg.org/css-color/#the-hwb-notation) color space (via plugin) - [x] [LAB](https://www.w3.org/TR/css-color-4/#resolving-lab-lch-values) color space (via plugin) - [x] [LCH](https://lea.verou.me/2020/04/lch-colors-in-css-what-why-and-how/) color space (via plugin) +- [x] Mix colors (via plugin) - [ ] CMYK color space (via plugin) -- [ ] Mix colors (via plugin) diff --git a/src/plugins/mix.ts b/src/plugins/mix.ts index cf83a12..dc9f525 100644 --- a/src/plugins/mix.ts +++ b/src/plugins/mix.ts @@ -15,7 +15,7 @@ declare module "../colord" { } /** - * A plugin adding color a mixing utility. + * A plugin adding a color mixing utility. * The logic is ported from new `color-mix` function in CSS. * https://www.w3.org/TR/css-color-5/#colormix */