@thi.ng/color 5.1.11 → 5.2.1

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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2022-08-01T14:53:59Z
3
+ - **Last updated**: 2022-09-27T16:23:13Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ## [5.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/color@5.2.0) (2022-09-21)
13
+
14
+ #### 🚀 Features
15
+
16
+ - add WCAG2 contrast() fn ([a132107](https://github.com/thi-ng/umbrella/commit/a132107))
17
+
12
18
  ## [5.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/color@5.1.0) (2022-06-09)
13
19
 
14
20
  #### 🚀 Features
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  <!-- This file is generated - DO NOT EDIT! -->
2
2
 
3
- # ![color](https://media.thi.ng/umbrella/banners/thing-color.svg?f089ad05)
3
+ # ![color](https://media.thi.ng/umbrella/banners-20220914/thing-color.svg?a647740f)
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/@thi.ng/color.svg)](https://www.npmjs.com/package/@thi.ng/color)
6
6
  ![npm downloads](https://img.shields.io/npm/dm/@thi.ng/color.svg)
@@ -22,9 +22,9 @@ For the Clojure version, please visit: [thi.ng/color-clj](https://thi.ng/color-c
22
22
  - [Multi-stop gradients in any color space](#multi-stop-gradients-in-any-color-space)
23
23
  - [Cosine gradients](#cosine-gradients)
24
24
  - [RGB color transformations](#rgb-color-transformations)
25
- - [Status](#status)
26
- - [Support packages](#support-packages)
27
- - [Related packages](#related-packages)
25
+ - [Status](#status)
26
+ - [Support packages](#support-packages)
27
+ - [Related packages](#related-packages)
28
28
  - [Installation](#installation)
29
29
  - [Dependencies](#dependencies)
30
30
  - [Usage examples](#usage-examples)
@@ -563,17 +563,17 @@ including parametric preset transforms:
563
563
  Transformation matrices can be combined using matrix multiplication /
564
564
  concatenation (see `concat()`) for more efficient application.
565
565
 
566
- ### Status
566
+ ## Status
567
567
 
568
568
  **STABLE** - used in production
569
569
 
570
570
  [Search or submit any issues for this package](https://github.com/thi-ng/umbrella/issues?q=%5Bcolor%5D+in%3Atitle)
571
571
 
572
- ### Support packages
572
+ ## Support packages
573
573
 
574
- - [@thi.ng/color-palettes](https://github.com/thi-ng/umbrella/tree/develop/packages/color-palettes) - Collection of 176 image based color palettes
574
+ - [@thi.ng/color-palettes](https://github.com/thi-ng/umbrella/tree/develop/packages/color-palettes) - Collection of 190+ image based color palettes
575
575
 
576
- ### Related packages
576
+ ## Related packages
577
577
 
578
578
  - [@thi.ng/pixel](https://github.com/thi-ng/umbrella/tree/develop/packages/pixel) - Typedarray integer & float pixel buffers w/ customizable formats, blitting, drawing, convolution
579
579
  - [@thi.ng/vectors](https://github.com/thi-ng/umbrella/tree/develop/packages/vectors) - Optimized 2d/3d/4d and arbitrary length vector operations
@@ -601,7 +601,7 @@ node --experimental-repl-await
601
601
  > const color = await import("@thi.ng/color");
602
602
  ```
603
603
 
604
- Package sizes (gzipped, pre-treeshake): ESM: 17.47 KB
604
+ Package sizes (gzipped, pre-treeshake): ESM: 17.50 KB
605
605
 
606
606
  ## Dependencies
607
607
 
package/contrast.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ import type { MaybeColor } from "./api.js";
2
+ /**
3
+ * Computes the WCAG 2.0 contrast ratio of the two given colors (order is
4
+ * irrelevant). Contrast ratios can range from 1 to 21.
5
+ *
6
+ * @remarks
7
+ * For accessibility guideline conformance, the visual presentation of text must
8
+ * have a minimum contrast ratio of at least 4.5 (with some exceptions).
9
+ *
10
+ * Reference: https://www.w3.org/TR/WCAG20/#contrast-ratiodef
11
+ *
12
+ * @param a
13
+ * @param b
14
+ */
15
+ export declare const contrast: (a: MaybeColor, b: MaybeColor) => number;
16
+ //# sourceMappingURL=contrast.d.ts.map
package/contrast.js ADDED
@@ -0,0 +1,20 @@
1
+ import { luminanceRgb } from "./luminance-rgb.js";
2
+ import { rgb } from "./rgb/rgb.js";
3
+ /**
4
+ * Computes the WCAG 2.0 contrast ratio of the two given colors (order is
5
+ * irrelevant). Contrast ratios can range from 1 to 21.
6
+ *
7
+ * @remarks
8
+ * For accessibility guideline conformance, the visual presentation of text must
9
+ * have a minimum contrast ratio of at least 4.5 (with some exceptions).
10
+ *
11
+ * Reference: https://www.w3.org/TR/WCAG20/#contrast-ratiodef
12
+ *
13
+ * @param a
14
+ * @param b
15
+ */
16
+ export const contrast = (a, b) => {
17
+ const lumA = luminanceRgb(rgb(a)) + 0.05;
18
+ const lumB = luminanceRgb(rgb(b)) + 0.05;
19
+ return lumA > lumB ? lumA / lumB : lumB / lumA;
20
+ };
package/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export * from "./api/names.js";
5
5
  export * from "./api/ranges.js";
6
6
  export * from "./api/system.js";
7
7
  export * from "./color.js";
8
+ export * from "./contrast.js";
8
9
  export * from "./convert.js";
9
10
  export * from "./defcolor.js";
10
11
  export * from "./css/css.js";
package/index.js CHANGED
@@ -5,6 +5,7 @@ export * from "./api/names.js";
5
5
  export * from "./api/ranges.js";
6
6
  export * from "./api/system.js";
7
7
  export * from "./color.js";
8
+ export * from "./contrast.js";
8
9
  export * from "./convert.js";
9
10
  export * from "./defcolor.js";
10
11
  export * from "./css/css.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/color",
3
- "version": "5.1.11",
3
+ "version": "5.2.1",
4
4
  "description": "Array-based color types, CSS parsing, conversions, transformations, declarative theme generation, gradients, presets",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -36,27 +36,27 @@
36
36
  "tool:swatches": "tools:node-esm tools/index.ts"
37
37
  },
38
38
  "dependencies": {
39
- "@thi.ng/api": "^8.4.1",
40
- "@thi.ng/arrays": "^2.3.5",
41
- "@thi.ng/binary": "^3.3.4",
42
- "@thi.ng/checks": "^3.2.4",
43
- "@thi.ng/compare": "^2.1.11",
44
- "@thi.ng/compose": "^2.1.12",
45
- "@thi.ng/defmulti": "^2.1.13",
46
- "@thi.ng/errors": "^2.1.10",
47
- "@thi.ng/math": "^5.3.7",
48
- "@thi.ng/random": "^3.3.7",
49
- "@thi.ng/strings": "^3.3.11",
50
- "@thi.ng/transducers": "^8.3.13",
51
- "@thi.ng/vectors": "^7.5.14"
39
+ "@thi.ng/api": "^8.4.2",
40
+ "@thi.ng/arrays": "^2.3.6",
41
+ "@thi.ng/binary": "^3.3.5",
42
+ "@thi.ng/checks": "^3.2.5",
43
+ "@thi.ng/compare": "^2.1.12",
44
+ "@thi.ng/compose": "^2.1.13",
45
+ "@thi.ng/defmulti": "^2.1.14",
46
+ "@thi.ng/errors": "^2.2.0",
47
+ "@thi.ng/math": "^5.3.9",
48
+ "@thi.ng/random": "^3.3.8",
49
+ "@thi.ng/strings": "^3.3.12",
50
+ "@thi.ng/transducers": "^8.3.15",
51
+ "@thi.ng/vectors": "^7.5.16"
52
52
  },
53
53
  "devDependencies": {
54
- "@microsoft/api-extractor": "^7.25.0",
55
- "@thi.ng/testament": "^0.2.12",
54
+ "@microsoft/api-extractor": "^7.31.1",
55
+ "@thi.ng/testament": "^0.3.0",
56
56
  "rimraf": "^3.0.2",
57
57
  "tools": "^0.0.1",
58
58
  "typedoc": "^0.22.17",
59
- "typescript": "^4.7.4"
59
+ "typescript": "^4.8.3"
60
60
  },
61
61
  "keywords": [
62
62
  "color",
@@ -162,6 +162,9 @@
162
162
  "./color": {
163
163
  "default": "./color.js"
164
164
  },
165
+ "./contrast": {
166
+ "default": "./contrast.js"
167
+ },
165
168
  "./convert": {
166
169
  "default": "./convert.js"
167
170
  },
@@ -421,5 +424,5 @@
421
424
  "vectors"
422
425
  ]
423
426
  },
424
- "gitHead": "be8423e2019e95c14a096260a93b9762dde0c768\n"
427
+ "gitHead": "f4c59114f2d2dfafa9014626038a9ec5242b0606\n"
425
428
  }