Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

color-helpers: uniform TypeScript setup #1190

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/color-helpers/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Unreleased (patch)

- Small fixes in type definitions
- Use higher precision color conversion matrices.

### 3.0.2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
export declare function binarySearchGamut(startOKLCH: Color, toDestination: (x: Color) => Color, fromDestination: (x: Color) => Color): Color;
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/calculations/contrast.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
export declare function contrast(RGB1: Color, RGB2: Color): number;
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/calculations/delta-EOK.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* @description Calculate deltaE OK which is the simple root sum of squares
* @param {number[]} reference - Array of OKLab values: L as 0..1, a and b as -1..1
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/calculations/map-gamut.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
export declare function mapGamut(startOKLCH: Color, toDestination: (x: Color) => Color, fromDestination: (x: Color) => Color): Color;
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/conversions/d50-to-d65.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* Bradford chromatic adaptation from D50 to D65
*
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/conversions/d65-to-d50.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* Bradford chromatic adaptation from D65 to D50
* @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/conversions/gam-2020.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* Convert an array of linear-light rec2020 RGB in the range 0.0-1.0
* to gamma corrected form ITU-R BT.2020-2 p.4
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/conversions/gam-a98rgb.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* Convert an array of linear-light a98-rgb in the range 0.0-1.0
* to gamma corrected form. Negative values are also now accepted
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/conversions/gam-p3.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* Convert an array of linear-light display-p3 RGB in the range 0.0-1.0
* to gamma corrected form
Expand Down
3 changes: 2 additions & 1 deletion packages/color-helpers/dist/conversions/gam-pro-photo.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* Convert an array of linear-light prophoto-rgb in the range 0.0-1.0
* to gamma corrected form.
Expand All @@ -9,3 +9,4 @@ import type { Color } from 'types/color';
* @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang).
*/
export declare function gam_ProPhoto(RGB: Color): Color;
export declare function foo(): void;
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/conversions/gam-srgb.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* Convert an array of linear-light sRGB values in the range 0.0-1.0 to gamma corrected form
* Extended transfer function:
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/conversions/hsl-to-srgb.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* @param {number} hue - Hue as degrees 0..360
* @param {number} sat - Saturation as percentage 0..100
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/conversions/hwb-to-srgb.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* @param {number} hue - Hue as degrees 0..360
* @param {number} white - Whiteness as percentage 0..100
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/conversions/lab-to-lch.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
*
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/conversions/lab-to-xyz.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
export declare function Lab_to_XYZ(Lab: Color): Color;
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/conversions/lch-to-lab.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* Convert an array of linear-light rec2020 values to CIE XYZ
* using D65 (no chromatic adaptation)
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/conversions/lin-2020.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* Convert an array of rec2020 RGB values in the range 0.0 - 1.0
* to linear light (un-companded) form.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* Convert an array of linear-light a98-rgb values to CIE XYZ
* http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/conversions/lin-a98rgb.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* Convert an array of a98-rgb values in the range 0.0 - 1.0
* to linear light (un-companded) form. Negative values are also now accepted
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/conversions/lin-p3-to-xyz.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* Convert an array of linear-light display-p3 values to CIE XYZ
* using D65 (no chromatic adaptation)
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/conversions/lin-p3.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* Convert an array of display-p3 RGB values in the range 0.0 - 1.0
* to linear light (un-companded) form.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* Convert an array of linear-light prophoto-rgb values to CIE XYZ
* using D50 (so no chromatic adaptation needed afterwards)
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/conversions/lin-pro-photo.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* Convert an array of prophoto-rgb values where in-gamut Colors are in the
* range [0.0 - 1.0] to linear light (un-companded) form. Transfer curve is
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* Convert an array of linear-light sRGB values to CIE XYZ
* using sRGB's own white, D65 (no chromatic adaptation)
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/conversions/lin-srgb.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* Convert an array of of sRGB values where in-gamut values are in the range
* [0 - 1] to linear light (un-companded) form.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* CMYK is an array of four values in the range [0.0, 1.0] the output is an
* array of [RGB] also in the [0.0, 1.0] range because the naive algorithm
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
*
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/conversions/oklab-to-xyz.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
export declare function OKLab_to_XYZ(OKLab: Color): Color;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
*
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/conversions/srgb-to-hsl.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* Convert an array of gamma-corrected sRGB values in the 0.0 to 1.0 range to HSL.
*
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/conversions/srgb-to-hwb.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* Convert an array of gamma-corrected sRGB values in the 0.0 to 1.0 range to HWB.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* Convert an array of gamma-corrected sRGB values in the 0.0 to 1.0 range
* to linear-light sRGB, then to CIE XYZ and return luminance (the Y value)
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/conversions/xyz-to-lab.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
export declare function XYZ_to_Lab(XYZ: Color): Color;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* Convert XYZ to linear-light rec2020
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* Convert XYZ to linear-light a98-rgb
*
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/conversions/xyz-to-lin-p3.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* Convert XYZ to linear-light P3
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* Convert XYZ to linear-light prophoto-rgb
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
*
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/conversions/xyz-to-oklab.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
*
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/conversions/xyz-to-uv.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* Convert an array of three XYZ values to u*,v* chromaticity coordinates
*
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/conversions/xyz-to-xy.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* Convert an array of three XYZ values to x,y chromaticity coordinates
*
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/conversions/xyz/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../../types/color';
/**
* @param {Color} color [r, g, b]
* - Red as number 0..1;
Expand Down
5 changes: 3 additions & 2 deletions packages/color-helpers/dist/index.cjs

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions packages/color-helpers/dist/index.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/color-helpers/dist/named-colors/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
export declare const namedColors: Record<string, Color>;
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/utils/clip.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
*
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/dist/utils/in-gamut.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
/**
* @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
*
Expand Down
1 change: 1 addition & 0 deletions packages/color-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"types": "dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs",
"default": "./dist/index.mjs"
Expand Down
10 changes: 5 additions & 5 deletions packages/color-helpers/src/calculations/binary-search-gamut.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { clip } from 'utils/clip';
import { OKLCH_to_OKLab } from 'conversions/oklch-to-oklab';
import { deltaEOK } from 'calculations/delta-EOK';
import type { Color } from 'types/color';
import { inGamut } from 'utils';
import { clip } from '../utils/clip';
import { OKLCH_to_OKLab } from '../conversions/oklch-to-oklab';
import { deltaEOK } from './delta-EOK';
import type { Color } from '../types/color';
import { inGamut } from '../utils';

const JND = 0.02;
const EPSILON = 0.00001;
Expand Down
4 changes: 2 additions & 2 deletions packages/color-helpers/src/calculations/contrast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
* @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/utilities.js
* @see https://www.w3.org/TR/WCAG21/#dfn-contrast-ratio
*/
import { sRGB_to_luminance } from 'conversions/srgb-to-luminance';
import type { Color } from 'types/color';
import { sRGB_to_luminance } from '../conversions/srgb-to-luminance';
import type { Color } from '../types/color';

export function contrast(RGB1: Color, RGB2: Color): number {
const L1 = sRGB_to_luminance(RGB1);
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/src/calculations/delta-EOK.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';

/**
* @description Calculate deltaE OK which is the simple root sum of squares
Expand Down
4 changes: 2 additions & 2 deletions packages/color-helpers/src/calculations/map-gamut.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { binarySearchGamut } from 'calculations/binary-search-gamut';
import type { Color } from 'types/color';
import { binarySearchGamut } from '../calculations/binary-search-gamut';
import type { Color } from '../types/color';

export function mapGamut(startOKLCH: Color, toDestination: (x: Color) => Color, fromDestination: (x: Color) => Color): Color {
return binarySearchGamut(startOKLCH, toDestination, fromDestination);
Expand Down
4 changes: 2 additions & 2 deletions packages/color-helpers/src/conversions/d50-to-d65.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Color } from 'types/color';
import { multiplyMatrices } from 'calculations/multiply-matrices';
import type { Color } from '../types/color';
import { multiplyMatrices } from '../calculations/multiply-matrices';

/**
* Bradford chromatic adaptation from D50 to D65
Expand Down
4 changes: 2 additions & 2 deletions packages/color-helpers/src/conversions/d65-to-d50.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Color } from 'types/color';
import { multiplyMatrices } from 'calculations/multiply-matrices';
import type { Color } from '../types/color';
import { multiplyMatrices } from '../calculations/multiply-matrices';

/**
* Bradford chromatic adaptation from D65 to D50
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/src/conversions/gam-2020.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';

/**
* Convert an array of linear-light rec2020 RGB in the range 0.0-1.0
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/src/conversions/gam-a98rgb.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';

/**
* Convert an array of linear-light a98-rgb in the range 0.0-1.0
Expand Down
4 changes: 2 additions & 2 deletions packages/color-helpers/src/conversions/gam-p3.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Color } from 'types/color';
import { gam_sRGB } from 'conversions/gam-srgb';
import type { Color } from '../types/color';
import { gam_sRGB } from '../conversions/gam-srgb';

/**
* Convert an array of linear-light display-p3 RGB in the range 0.0-1.0
Expand Down
4 changes: 3 additions & 1 deletion packages/color-helpers/src/conversions/gam-pro-photo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';

/**
* Convert an array of linear-light prophoto-rgb in the range 0.0-1.0
Expand All @@ -23,3 +23,5 @@ export function gam_ProPhoto(RGB: Color): Color {
return 16 * val;
}) as Color;
}

export function foo() { }
2 changes: 1 addition & 1 deletion packages/color-helpers/src/conversions/gam-srgb.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';

/**
* Convert an array of linear-light sRGB values in the range 0.0-1.0 to gamma corrected form
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/src/conversions/hsl-to-srgb.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';

/**
* @param {number} hue - Hue as degrees 0..360
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/src/conversions/hwb-to-srgb.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';
import { HSL_to_sRGB } from './hsl-to-srgb';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/color-helpers/src/conversions/lab-to-lch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Color } from 'types/color';
import type { Color } from '../types/color';

/**
* @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
Expand Down
Loading