@sardine/colour 2.4.0 → 3.0.0
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/dist/assertions.d.ts +4 -1
- package/dist/convertCSSRGBtoHex.d.ts +3 -0
- package/dist/convertCSSRGBtoRGB.d.ts +12 -0
- package/dist/convertRGBtoHSV.d.ts +16 -0
- package/dist/getContrastRatio.d.ts +3 -2
- package/dist/index.cjs +365 -267
- package/dist/index.d.ts +4 -5
- package/dist/index.min.js +1 -7
- package/dist/index.mjs +366 -268
- package/dist/isDarkColour.d.ts +2 -2
- package/dist/sortHexColours.d.ts +26 -0
- package/dist/types.d.ts +12 -1
- package/dist/util/index.d.ts +2 -12
- package/dist/util/regexers.d.ts +6 -9
- package/package.json +73 -57
package/dist/assertions.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { NamedCSSColour } from "./types";
|
|
|
2
2
|
/**
|
|
3
3
|
* Determines whether a string represents a valid CSS RGB or RGBA colour value.
|
|
4
4
|
*
|
|
5
|
-
* Captures the
|
|
5
|
+
* Captures the following CSS RGB formats:
|
|
6
6
|
* - `rgb(0,0,0)`
|
|
7
7
|
* - `rgba(0, 0, 0, 0.4)`
|
|
8
8
|
* - `rgba(0,0,0,50%)`
|
|
@@ -10,6 +10,9 @@ import type { NamedCSSColour } from "./types";
|
|
|
10
10
|
* - `rgba(0 0 0 / 0.4)`
|
|
11
11
|
* - `rgb(0 0 0 / 0.5)`
|
|
12
12
|
* - `rgb(0 0 0 / 50%)`
|
|
13
|
+
* - `rgb(50%, 25%, 100%)`
|
|
14
|
+
* - `rgba(50%, 25%, 100%, 0.8)`
|
|
15
|
+
* - `rgba(50%, 25%, 100%, 80%)`
|
|
13
16
|
*
|
|
14
17
|
* @param {string} colour - The string to test.
|
|
15
18
|
* @returns {boolean} `true` if the string represents a valid CSS RGB or RGBA colour value, `false` otherwise.
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import type { RGBColour } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Converts a CSS RGB/Alpha value to its numeric equivalent
|
|
4
|
+
* @param value - The value string (e.g., "50%", "127", "0.5")
|
|
5
|
+
* @param isAlpha - Whether this is an alpha channel value
|
|
6
|
+
* @returns The numeric value
|
|
7
|
+
*/
|
|
8
|
+
export declare function convertCssValueToNumber(value: string, isAlpha?: boolean): number;
|
|
9
|
+
export declare function convertCssRgbChannelValue(value?: string): number | undefined;
|
|
10
|
+
export declare function convertCssAlphaChannelValue(value?: string): number | undefined;
|
|
2
11
|
/**
|
|
3
12
|
* Converts CSS RGB colour format into RGB colour object.
|
|
4
13
|
* @param {string} colour - A CSS RGB colour in the format:
|
|
@@ -7,6 +16,9 @@ import type { RGBColour } from "./types";
|
|
|
7
16
|
* - `rgba(0,0,0,0.4)`
|
|
8
17
|
* - `rgb(0 0 0)`
|
|
9
18
|
* - `rgba(0 0 0 / 0.4)`
|
|
19
|
+
* - `rgb(50%, 25%, 100%)`
|
|
20
|
+
* - `rgba(50%, 25%, 100%, 0.8)`
|
|
21
|
+
* - `rgba(50%, 25%, 100%, 80%)`
|
|
10
22
|
*
|
|
11
23
|
* @returns {RGBColour} - RGB colour object.
|
|
12
24
|
*/
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HSVColour } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Converts an RGB colour to HSV.
|
|
4
|
+
* Conversion formula is based on the RGB to HSV conversion algorithm:
|
|
5
|
+
* https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB
|
|
6
|
+
*
|
|
7
|
+
* https://www.niwa.nu/2013/05/math-behind-colorspace-conversions-rgb-hsl/
|
|
8
|
+
* - Hue (h) is calculated based on the maximum RGB value.
|
|
9
|
+
* - Saturation (s) is the chroma divided by the maximum RGB value.
|
|
10
|
+
* - Value (v) is the maximum RGB value.
|
|
11
|
+
* @param r Red channel (0-255)
|
|
12
|
+
* @param g Green channel (0-255)
|
|
13
|
+
* @param b Blue channel (0-255)
|
|
14
|
+
* @returns HSVColour object with h (hue), s (saturation), v (value)
|
|
15
|
+
*/
|
|
16
|
+
export declare function convertRGBtoHSV(r: number, g: number, b: number): HSVColour;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { NamedCSSColour, WCAG } from "./types";
|
|
2
2
|
/**
|
|
3
3
|
* Calculates the contrast ratio between two colours.
|
|
4
|
-
*
|
|
5
|
-
* @param
|
|
4
|
+
* Accepts CSS RGB colours (including percentage values), named CSS colours, or hexadecimal colours.
|
|
5
|
+
* @param colour1 The first colour (e.g., `#ff0000`, `rgb(255,0,0)`, `rgb(100%, 0%, 0%)`, or `red`)
|
|
6
|
+
* @param colour2 The second colour (e.g., `#00ff00`, `rgb(0,255,0)`, `rgb(0%, 100%, 0%)`, or `lime`)
|
|
6
7
|
* @param standard The standard to evaluate the contrast ratio against, defaults to WCAG2.1
|
|
7
8
|
* @returns The contrast ratio between the two colours truncated to 3 decimal places
|
|
8
9
|
*/
|