@sardine/colour 2.1.0 → 2.1.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.
@@ -0,0 +1,12 @@
1
+ import type { LabColour } from "./types";
2
+ /**
3
+ * Mesures the colour difference between two colours in the Lab space
4
+ *
5
+ * Math taken from:
6
+ *
7
+ * https://en.wikipedia.org/wiki/Color_difference#CIEDE2000
8
+ * http://www2.ece.rochester.edu/~gsharma/ciede2000/ciede2000noteCRNA.pdf
9
+ * @param colour1 First colour to be compared
10
+ * @param colour2 First colour to be compared
11
+ */
12
+ export declare function ciede2000(colour1: LabColour, colour2: LabColour): number;
@@ -0,0 +1,14 @@
1
+ import type { RGBColour } from "./types";
2
+ /**
3
+ * Calculate the distance between two RGB colours using the CIEDE2000 colour-difference formula.
4
+ *
5
+ * The CIEDE2000 colour-difference formula is a standard method for calculating the perceptual difference
6
+ * between two colours in the CIELAB colour space. It takes into account human visual perception and the
7
+ * non-linearities in how we perceive colour differences.
8
+ *
9
+ * @param colour1 - The first colour to compare.
10
+ * @param colour2 - The second colour to compare.
11
+ * @returns The distance between the two colours. Smaller numbers (minimum 0) mean the colours are more similar,
12
+ * larger numbers (typically not exceeding 100 for visible colours) indicate more dissimilar colours.
13
+ */
14
+ export declare const RGBdistance: (colour1: RGBColour, colour2: RGBColour) => number;
@@ -0,0 +1,31 @@
1
+ import type { NamedCSSColour } from "./types";
2
+ /**
3
+ * Determines whether a string represents a valid CSS RGB or RGBA colour value.
4
+ *
5
+ * Captures the folowing CSS RGB formats:
6
+ * - `rgb(0,0,0)`
7
+ * - `rgba(0, 0, 0, 0.4)`
8
+ * - `rgba(0,0,0,50%)`
9
+ * - `rgb(0 0 0)`
10
+ * - `rgba(0 0 0 / 0.4)`
11
+ * - `rgb(0 0 0 / 0.5)`
12
+ * - `rgb(0 0 0 / 50%)`
13
+ *
14
+ * @param {string} colour - The string to test.
15
+ * @returns {boolean} `true` if the string represents a valid CSS RGB or RGBA colour value, `false` otherwise.
16
+ */
17
+ export declare function isCSSRGBColour(colour: string): boolean;
18
+ /**
19
+ * Determines whether a string represents a valid hexadecimal colour value.
20
+ *
21
+ * @param {string} colour - The string to test.
22
+ * @returns {boolean} True if the string represents a valid hexadecimal colour value, false otherwise.
23
+ */
24
+ export declare function isHexColour(colour: string): boolean;
25
+ /**
26
+ * Determines whether a string represents a valid named CSS colour.
27
+ *
28
+ * @param {NamedCSSColour} colour - The string to test.
29
+ * @returns {boolean} `true` if the string represents a valid named CSS colour, `false` otherwise.
30
+ */
31
+ export declare function isNamedCSSColour(colour: NamedCSSColour): colour is NamedCSSColour;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Converts CSS RGB colour format into Hexadecimal.
3
+ * @param {string} colour - A CSS RGB colour in the format:
4
+ *
5
+ * - `rgb(0,0,0)`
6
+ * - `rgba(0,0,0,0.4)`
7
+ * - `rgb(0 0 0)`
8
+ * - `rgba(0 0 0 / 0.4)`
9
+ *
10
+ * @returns {string} - An hexadecimal string
11
+ */
12
+ export declare function convertCSSRGBtoHex(colour: string): string;
@@ -0,0 +1,13 @@
1
+ import type { RGBColour } from "./types";
2
+ /**
3
+ * Converts CSS RGB colour format into RGB colour object.
4
+ * @param {string} colour - A CSS RGB colour in the format:
5
+ *
6
+ * - `rgb(0,0,0)`
7
+ * - `rgba(0,0,0,0.4)`
8
+ * - `rgb(0 0 0)`
9
+ * - `rgba(0 0 0 / 0.4)`
10
+ *
11
+ * @returns {RGBColour} - RGB colour object.
12
+ */
13
+ export declare function convertCSSRGBtoRGB(colour: string): RGBColour;
@@ -0,0 +1,8 @@
1
+ import type { NamedCSSColour } from "./types";
2
+ /**
3
+ * Converts a hexadecimal colour value to a named CSS colour.
4
+ *
5
+ * @param {string} colour - The hexadecimal colour value to convert.
6
+ * @returns {NamedCSSColour | undefined} The named CSS colour that corresponds to the given hexadecimal colour value, or undefined if no named CSS colour matches the given value.
7
+ */
8
+ export declare function convertHextoNamedCSSColour(colour: string): NamedCSSColour | undefined;
@@ -0,0 +1,13 @@
1
+ import type { RGBColour } from "./types";
2
+ /**
3
+ * Converts an hexadecimal colour into RGB colour object.
4
+ * @param {string} hex - An hexadecimal colour in the format:
5
+ *
6
+ * - `#000`
7
+ * - `#102030`
8
+ * - `#ffff`
9
+ * - `#102030ff`
10
+ *
11
+ * @returns {RGBColour} - RGB colour object.
12
+ */
13
+ export declare function convertHextoRGB(hex: string): RGBColour;
@@ -0,0 +1,10 @@
1
+ import type { NamedCSSColour } from "./types";
2
+ /**
3
+ * Converts a named CSS Colour in an hexadecimal one.
4
+ *
5
+ * List of colours sourced here:
6
+ * https://developer.mozilla.org/en-US/docs/Web/CSS/named-color
7
+ * @param {NamedCSSColour} name - A named CSS colour
8
+ * @returns {string} - An hexadecimal string
9
+ */
10
+ export declare function convertNamedCSSColourtoHex(name: NamedCSSColour): string | undefined;
@@ -0,0 +1,8 @@
1
+ import type { NamedCSSColour, RGBColour } from "./types";
2
+ /**
3
+ * Converts a named CSS colour to an RGB colour object.
4
+ *
5
+ * @param {NamedCSSColour} colour - The named CSS colour to convert.
6
+ * @returns {RGBColour | undefined} An RGB colour object representing the named CSS colour, or undefined if the named CSS colour is not recognized.
7
+ */
8
+ export declare function convertNamedCSSColourtoRGB(colour: NamedCSSColour): RGBColour | undefined;
@@ -0,0 +1,8 @@
1
+ import type { RGBColour } from "./types";
2
+ /**
3
+ * Converts an RGB colour object to a CSS RGB colour string.
4
+ *
5
+ * @param {RGBColour} colour - The RGB colour object to convert.
6
+ * @returns {string} The CSS RGB colour string in the format `rgb(R G B)` or `rgb(R G B / A)` if the alpha channel is present.
7
+ */
8
+ export declare function convertRGBtoCSSRGB({ R, G, B, A }: RGBColour): string;
@@ -0,0 +1,12 @@
1
+ import type { RGBColour } from "./types";
2
+ /**
3
+ * Converts a colour in the RGB format to Hexadecimal.
4
+ * It accepts an option Alpha channel `A`
5
+ * @param {RGBColour} colour - An object representing RGB Colour.
6
+ * @param {number} colour.R - A number between 0 and 255 to describe the Red colour channel
7
+ * @param {number} colour.G - A number between 0 and 255 to describe the Green colour channel
8
+ * @param {number} colour.B - A number between 0 and 255 to describe the Blue colour channel
9
+ * @param {number} colour.A - An optional number between 0 and 1 to describe the Alpha colour channel
10
+ * @returns - An hexadecimal string
11
+ */
12
+ export declare function convertRGBtoHex({ R, G, B, A }: RGBColour): string;
@@ -0,0 +1,8 @@
1
+ import type { LabColour, RGBColour } from "./types";
2
+ /**
3
+ * Indirectly converts RGB to Lab.
4
+ * First converts RGB to XYZ, then converts XYZ to Lab.
5
+ * @param {RGBColour} colour sRGB colour
6
+ * @return {LabColour} Lab colour
7
+ */
8
+ export declare function convertRGBtoLab(colour: RGBColour): LabColour;
@@ -0,0 +1,8 @@
1
+ import type { NamedCSSColour, RGBColour } from "./types";
2
+ /**
3
+ * Converts an RGB colour object to a named CSS colour.
4
+ *
5
+ * @param {RGBColour} colour - The RGB colour object to convert.
6
+ * @returns {NamedCSSColour | undefined} The named CSS colour that corresponds to the given RGB colour, or undefined if no named CSS colour matches the given colour.
7
+ */
8
+ export declare function convertRGBtoNamedCSSColour(colour: RGBColour): NamedCSSColour | undefined;
@@ -0,0 +1,8 @@
1
+ import type { RGBColour, XYZColour } from "./types";
2
+ /**
3
+ * Converts sRGB colour space to XYZ.
4
+ * Math comes from https://en.wikipedia.org/wiki/SRGB#The_reverse_transformation
5
+ * @param {RGBColour} colour sRGB colour
6
+ * @return {XYZColour} XYZ colour
7
+ */
8
+ export declare function convertRGBtoXYZ(colour: RGBColour): XYZColour;
@@ -0,0 +1,8 @@
1
+ import type { LabColour, XYZColour } from "./types";
2
+ /**
3
+ * Converts XYZ colour space to Lab
4
+ * Math comes from https://en.wikipedia.org/wiki/CIELAB_color_space#From_CIEXYZ_to_CIELAB[11]
5
+ * @param colour XYZ colour
6
+ * @return {LabColour} Lab colour
7
+ */
8
+ export declare function convertXYZtoLab(colour: XYZColour): LabColour;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Finds the nearest CSS RGB colour in a palette to a given CSS RGB colour.
3
+ *
4
+ * @param {string} colour - The CSS RGB colour to find the nearest match for. Alpha channel is ignored.
5
+ * @param {string[]} palette - An array of CSS RGB colours to search for the nearest match.
6
+ * @returns {string} The CSS RGB colour in the palette that is closest to the given colour.
7
+ * If the palette has fewer than 2 colours, or if it is undefined or null, the original colour is returned.
8
+ * The CSS RGB colour string is in the format `rgb(R G B)`.
9
+ */
10
+ export declare function findNearestCSSRGBColour(colour: string, palette: string[]): string;
@@ -0,0 +1,9 @@
1
+ import type { NamedCSSColour } from "./types";
2
+ /**
3
+ * Finds the nearest colour in a palette to a given colour.
4
+ *
5
+ * @param {string | NamedCSSColour} colour - The colour to match. It can be a hexadecimal colour, a CSS RGB colour, or a named CSS colour.
6
+ * @param {string[] | NamedCSSColour[]} palette - The palette of colours to search.
7
+ * @returns {string} The nearest colour in the palette to the given colour.
8
+ */
9
+ export declare function findNearestColour(colour: string | NamedCSSColour, palette: string[] | NamedCSSColour[]): string | NamedCSSColour | undefined;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Finds the nearest hexadecimal colour in a palette to the given hex colour.
3
+ *
4
+ * @param {string} colour - The hexadecimal colour to find the nearest match for.
5
+ * @param {string[]} palette - An array of hexadecimal colours to search for the nearest match in.
6
+ * @returns {string} The hexadecimal colour in the palette that is closest to the given colour.
7
+ * If the palette has fewer than 2 colours, or if it is undefined or null, the original colour is returned.
8
+ */
9
+ export declare function findNearestHexColour(colour: string, palette: string[]): string;
@@ -0,0 +1,2 @@
1
+ import type { NamedCSSColour } from "./types";
2
+ export declare function findNearestNamedCSSColour(colour: NamedCSSColour, palette: NamedCSSColour[]): NamedCSSColour;
@@ -0,0 +1,10 @@
1
+ import type { RGBColour } from "./types";
2
+ /**
3
+ * Finds the nearest RGB colour in a palette to the given RGB colour.
4
+ *
5
+ * @param {RGBColour} colour - The RGB colour to find the nearest match for.
6
+ * @param {RGBColour[]} palette - An array of RGB colours to search for the nearest match in.
7
+ * @returns {RGBColour} The RGB colour in the palette that is closest to the given colour.
8
+ * If the palette has fewer than 2 colours, or if it is undefined or null, the original colour is returned.
9
+ */
10
+ export declare function findNearestRGBColour(colour: RGBColour, palette: RGBColour[]): RGBColour;
@@ -0,0 +1,13 @@
1
+ import type { WCAG } from "./types";
2
+ /**
3
+ * Returns the relative luminance of a colour in the sRGB space.
4
+ *
5
+ * The calculations are compatible with WCAG 3.0 as it aligns with the sRGB spec
6
+ * and difference to WCAG 2.1 is minimal in a 8 bit channel.
7
+ *
8
+ * https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
9
+ *
10
+ * https://www.w3.org/WAI/GL/wiki/Relative_luminance
11
+ * @param colour an hexadecimal colour
12
+ */
13
+ export declare function getSRGBLuminanceFromHex(colour: string, standard?: WCAG): number;
@@ -0,0 +1,13 @@
1
+ import type { RGBColour, WCAG } from "./types";
2
+ /**
3
+ * Returns the relative luminance of a colour in the sRGB space.
4
+ *
5
+ * The calculations are compatible with WCAG 3.0 as it aligns with the sRGB spec
6
+ * and difference to WCAG 2.1 is minimal in a 8 bit channel.
7
+ *
8
+ * https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
9
+ *
10
+ * https://www.w3.org/WAI/GL/wiki/Relative_luminance
11
+ * @param colour an hexadecimal colour
12
+ */
13
+ export declare function getSRGBLuminanceFromRGB({ R, G, B }: RGBColour, standard?: WCAG): number;
@@ -0,0 +1,27 @@
1
+ export { RGBdistance } from "./RGBdistance";
2
+ export { ciede2000 } from "./CIEDE2000";
3
+ export { convertCSSRGBtoHex } from "./convertCSSRGBtoHex";
4
+ export { convertCSSRGBtoRGB } from "./convertCSSRGBtoRGB";
5
+ export { convertHextoNamedCSSColour } from "./convertHextoNamedCSSColour";
6
+ export { convertHextoRGB } from "./convertHextoRGB";
7
+ export { convertNamedCSSColourtoHex } from "./convertNamedCSSColourtoHex";
8
+ export { convertNamedCSSColourtoRGB } from "./convertNamedCSSColourtoRGB";
9
+ export { convertRGBtoCSSRGB } from "./convertRGBtoCSSRGB";
10
+ export { convertRGBtoHex } from "./convertRGBtoHex";
11
+ export { convertRGBtoLab } from "./convertRGBtoLab";
12
+ export { convertRGBtoNamedCSSColour } from "./convertRGBtoNamedCSSColour";
13
+ export { convertRGBtoXYZ } from "./convertRGBtoXYZ";
14
+ export { convertXYZtoLab } from "./convertXYZtoLab";
15
+ export { findNearestCSSRGBColour } from "./findNearestCSSRGBColour";
16
+ export { findNearestColour } from "./findNearestColour";
17
+ export { findNearestHexColour } from "./findNearestHexColour";
18
+ export { findNearestNamedCSSColour } from "./findNearestNamedCSSColour";
19
+ export { findNearestRGBColour } from "./findNearestRGBColour";
20
+ export { getSRGBLuminanceFromHex } from "./getSRGBLuminanceFromHex";
21
+ export { getSRGBLuminanceFromRGB } from "./getSRGBLuminanceFromRGB";
22
+ export { isCSSNamedDarkColour } from "./isCSSNameDarkColour";
23
+ export { isCSSRGBColour } from "./assertions";
24
+ export { isCSSRGBDarkColour } from "./isCSSRGBDarkColour";
25
+ export { isDarkColour } from "./isDarkColour";
26
+ export { isHexDarkColour } from "./isHexDarkColour";
27
+ export { pickHexColourContrast } from "./pickHexColourContrast";
@@ -0,0 +1,8 @@
1
+ import type { NamedCSSColour, WCAG } from "./types";
2
+ /**
3
+ * Evaluates if a named CSS colour is dark by measuring the contrast ratio against black and white
4
+ * @param {string} name - A named CSS colour, ie: `hotpink`
5
+ * @param {"WCAG2.1" | "WCAG3.0"} standard - Evaluate agains "WCAG2.1" or "WCAG3.0"
6
+ * @returns { boolean } Returns `true`, `false` or `undefined` if name is not a valid CSS named colour
7
+ */
8
+ export declare function isCSSNamedDarkColour(name: NamedCSSColour, standard: WCAG): boolean;
@@ -0,0 +1,2 @@
1
+ import type { WCAG } from "./types";
2
+ export declare function isCSSRGBDarkColour(colour: string, standard: WCAG): boolean;
@@ -0,0 +1,11 @@
1
+ import type { NamedCSSColour, WCAG } from "./types";
2
+ /**
3
+ * Evaluates if a colour is dark by measuring the contrast ratio against black and white.
4
+ * It accepts CSS RGB colours, named CSS or hexadecimal.
5
+ *
6
+ * If you know in advance the type of colour you want to evaluate consider using `isCSSNamedDarkColour`, `isCSSRGBDarkColour` or `isHexDarkColour` as they are smaller functions
7
+ * @param {string | NamedCSSColour} colour - A colour value, ie: `hotpink`, `#333222` or `rgb(12,34,45)`
8
+ * @param {"WCAG2.1" | "WCAG3.0"} standard - Evaluate agains "WCAG2.1" or "WCAG3.0"
9
+ * @returns {boolean} Returns `true`, `false` or `undefined` if name is not a valid CSS named colour
10
+ */
11
+ export declare function isDarkColour(colour: string | NamedCSSColour, standard: WCAG): boolean;
@@ -0,0 +1,8 @@
1
+ import type { WCAG } from "./types";
2
+ /**
3
+ * Evaluates if a colour is dark by measuring the contrast ratio against black and white
4
+ * @param {string} colour - A colour in the hexadecimal format
5
+ * @param {"WCAG2.1" | "WCAG3.0"} standard - Evaluate agains "WCAG2.1" or "WCAG3.0"
6
+ * @returns {boolean} Returns either `true` or `false`
7
+ */
8
+ export declare function isHexDarkColour(colour: string, standard: WCAG): boolean;
@@ -0,0 +1,8 @@
1
+ import type { WCAG } from "./types";
2
+ type ColorArgs = {
3
+ backgroundColour: string;
4
+ optionOneColour: string;
5
+ optionTwoColour: string;
6
+ };
7
+ export declare const pickHexColourContrast: ({ backgroundColour, optionOneColour, optionTwoColour }: ColorArgs, standard: WCAG) => string;
8
+ export {};
@@ -0,0 +1,52 @@
1
+ /**
2
+ * The RGB colour model represents a broad array of colours by describing the Red, Green and Blue channels.
3
+ */
4
+ export interface RGBColour {
5
+ /** A number between 0 and 255 to describe the Red colour channel */
6
+ R: number;
7
+ /** A number between 0 and 255 to describe the Green colour channel */
8
+ G: number;
9
+ /** A number between 0 and 255 to describe the Blue colour channel */
10
+ B: number;
11
+ /** A optional number between 0 and 1 to describe the Alpha colour channel */
12
+ A?: number | undefined;
13
+ }
14
+ /**
15
+ * L*a*b* space is three-dimensional and covers the entire range of human colour perception
16
+ */
17
+ export interface LabColour {
18
+ /** A number between 0 and 100 to describe the colour's lightness. (0 - black, 100 - white) */
19
+ L: number;
20
+ /** A number between -128 and 127 to describe the green–red opponent colours, with negative values toward green and positive values toward red */
21
+ a: number;
22
+ /** A number between -128 and 127 to describe blue–yellow opponents, with negative numbers toward blue and positive toward yellow */
23
+ b: number;
24
+ }
25
+ /**
26
+ * The CIE XYZ colour space is a device independent colour representation
27
+ */
28
+ export interface XYZColour {
29
+ /** X is a mix of response curves chosen to be nonnegative */
30
+ X: number;
31
+ /** Y as luminance */
32
+ Y: number;
33
+ /** Z is quasi-equal to blue */
34
+ Z: number;
35
+ }
36
+ export interface HueHelper {
37
+ /** Chroma for colour 1 */
38
+ C1: number;
39
+ /** Chroma for colour 2 */
40
+ C2: number;
41
+ /** Derivative of colour 1 Hue */
42
+ h1_d: number;
43
+ /** Derivative of colour 2 Hue */
44
+ h2_d: number;
45
+ }
46
+ export type ColourSpace = "sRGB";
47
+ export type WCAG = "WCAG2.1" | "WCAG3.0";
48
+ /**
49
+ * Named list from https://developer.mozilla.org/en-US/docs/Web/CSS/named-color
50
+ */
51
+ export type NamedCSSColour = "aliceblue" | "antiquewhite" | "aqua" | "aquamarine" | "azure" | "beige" | "bisque" | "black" | "blanchedalmond" | "blue" | "blueviolet" | "brown" | "burlywood" | "cadetblue" | "chartreuse" | "chocolate" | "coral" | "cornflowerblue" | "cornsilk" | "crimson" | "cyan" | "darkblue" | "darkcyan" | "darkgoldenrod" | "darkgray" | "darkgreen" | "darkgrey" | "darkkhaki" | "darkmagenta" | "darkolivegreen" | "darkorange" | "darkorchid" | "darkred" | "darksalmon" | "darkseagreen" | "darkslateblue" | "darkslategray" | "darkslategrey" | "darkturquoise" | "darkviolet" | "deeppink" | "deepskyblue" | "dimgray" | "dimgrey" | "dodgerblue" | "firebrick" | "floralwhite" | "forestgreen" | "fuchsia" | "gainsboro" | "ghostwhite" | "gold" | "goldenrod" | "gray" | "green" | "greenyellow" | "grey" | "honeydew" | "hotpink" | "indianred" | "indigo" | "ivory" | "khaki" | "lavender" | "lavenderblush" | "lawngreen" | "lemonchiffon" | "lightblue" | "lightcoral" | "lightcyan" | "lightgoldenrodyellow" | "lightgray" | "lightgreen" | "lightgrey" | "lightpink" | "lightsalmon" | "lightseagreen" | "lightskyblue" | "lightslategray" | "lightslategrey" | "lightsteelblue" | "lightyellow" | "lime" | "limegreen" | "linen" | "magenta" | "maroon" | "mediumaquamarine" | "mediumblue" | "mediumorchid" | "mediumpurple" | "mediumseagreen" | "mediumslateblue" | "mediumspringgreen" | "mediumturquoise" | "mediumvioletred" | "midnightblue" | "mintcream" | "mistyrose" | "moccasin" | "navajowhite" | "navy" | "oldlace" | "olive" | "olivedrab" | "orangered" | "orchid" | "palegoldenrod" | "palegreen" | "paleturquoise" | "palevioletred" | "papayawhip" | "peachpuff" | "peru" | "pink" | "plum" | "powderblue" | "purple" | "red" | "rosybrown" | "royalblue" | "saddlebrown" | "salmon" | "sandybrown" | "seagreen" | "seashell" | "sienna" | "silver" | "skyblue" | "slateblue" | "slategray" | "slategrey" | "snow" | "springgreen" | "steelblue" | "tan" | "teal" | "thistle" | "tomato" | "transparent" | "turquoise" | "violet" | "wheat" | "white" | "whitesmoke" | "yellow" | "yellowgreen";
52
+ export type NamedCSSColours = Array<[NamedCSSColour, string]>;
@@ -0,0 +1,46 @@
1
+ import type { HueHelper } from "../types";
2
+ /**
3
+ * Calculates the Hue derivative
4
+ * @param x A numeric expression representing the cartesian x-coordinate.
5
+ * @param y A numeric expression representing the cartesian y-coordinate.
6
+ */
7
+ export declare function hue_d(x: number, y: number): number;
8
+ /**
9
+ * Calculates the difference between two Hue derivatives
10
+ * @param HueHelper param
11
+ */
12
+ export declare function deltaHue_d({ C1, C2, h1_d, h2_d }: HueHelper): number;
13
+ /**
14
+ * Calculates the mean between two Hue derivatives
15
+ * @param HueHelper param
16
+ */
17
+ export declare function meanHue_d({ C1, C2, h1_d, h2_d }: HueHelper): number;
18
+ /**
19
+ * Converts a number in degrees to radians
20
+ * @param n Number in degrees to be converted
21
+ */
22
+ export declare const toRadians: (n: number) => number;
23
+ /**
24
+ * Calculates a recurring square root
25
+ * @param n Input number
26
+ */
27
+ export declare const bigSquare: (n: number) => number;
28
+ /**
29
+ * Normalise black and white colorimetry as specified in IEC 61966-2-1
30
+ * It takes a RGB channel in the range [0 - 255] and returns a value between 0 and 1
31
+ * @param rgbValue number to be normalised
32
+ */
33
+ export declare function linearRGB(rgbValue: number, WCAG21?: boolean): number;
34
+ /**
35
+ * The division of the f function domain into two parts was done to prevent an infinite slope at n = 0
36
+ * @param n Number to be constrained
37
+ */
38
+ export declare function constrainLab(n: number): number;
39
+ /**
40
+ * Clamps a number between two values
41
+ * @param {number} value - The value to be clamped
42
+ * @param {number} min - The minimum value
43
+ * @param {number} max - The maximum value
44
+ * @returns {number} - A clamped value
45
+ */
46
+ export declare function clamp(value: number, min: number, max: number): number;
@@ -0,0 +1,5 @@
1
+ import type { NamedCSSColour } from "../types";
2
+ /**
3
+ * Named list from https://developer.mozilla.org/en-US/docs/Web/CSS/named-color
4
+ */
5
+ export declare const namedCSSColours: Map<NamedCSSColour, string>;
@@ -0,0 +1,19 @@
1
+ /** Six digit Hexadecimal colour, ie: #12FF21 */
2
+ export declare const hexRegex: RegExp;
3
+ /** Eight digit Hexadecimal colour, ie: #12FF21BE */
4
+ export declare const hexAlphaRegex: RegExp;
5
+ /** Three digit Hexadecimal colour, ie: #FFF */
6
+ export declare const shortHexRegex: RegExp;
7
+ /** Four digit Hexadecimal colour, ie: #FFF4 */
8
+ export declare const shortAlphaHexRegex: RegExp;
9
+ /**
10
+ * Captures the folowing CSS RGB formats:
11
+ * - `rgb(0,0,0)`
12
+ * - `rgba(0, 0, 0, 0.4)`
13
+ * - `rgba(0,0,0,50%)`
14
+ * - `rgb(0 0 0)`
15
+ * - `rgba(0 0 0 / 0.4)`
16
+ * - `rgb(0 0 0 / 0.5)`
17
+ * - `rgb(0 0 0 / 50%)`
18
+ */
19
+ export declare const cssRGBARegex: RegExp;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sardine/colour",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "It does things to colours",
5
5
  "type": "module",
6
6
  "module": "./dist/index.mjs",