@sardine/colour 2.4.0 → 4.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/convertHextoCSSRGB.d.ts +1 -1
- package/dist/convertHextoRGB.d.ts +2 -2
- package/dist/convertRGBtoHSV.d.ts +16 -0
- package/dist/getContrastRatio.d.ts +3 -2
- package/dist/getContrastRatioFromHex.d.ts +1 -1
- package/dist/getContrastRatioFromNamedCSSColour.d.ts +1 -1
- package/dist/getSRGBLuminanceFromHex.d.ts +1 -1
- package/dist/index.cjs +1011 -575
- package/dist/index.d.ts +4 -5
- package/dist/index.min.js +1 -7
- package/dist/index.mjs +1011 -610
- package/dist/isDarkColour.d.ts +2 -2
- package/dist/pickHexColourContrast.d.ts +1 -1
- 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/isDarkColour.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { NamedCSSColour, WCAG } from "./types";
|
|
2
2
|
/**
|
|
3
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.
|
|
4
|
+
* It accepts CSS RGB colours (including percentage values), named CSS or hexadecimal.
|
|
5
5
|
*
|
|
6
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
|
|
7
|
+
* @param {string | NamedCSSColour} colour - A colour value, ie: `hotpink`, `#333222`, `rgb(12,34,45)`, or `rgb(50%, 25%, 100%)`
|
|
8
8
|
* @param {"WCAG2.1" | "WCAG3.0"} standard - Evaluate agains "WCAG2.1" or "WCAG3.0"
|
|
9
9
|
* @returns {boolean} Returns `true`, `false` or `undefined` if name is not a valid CSS named colour
|
|
10
10
|
*/
|
|
@@ -4,5 +4,5 @@ type ColorArgs = {
|
|
|
4
4
|
optionOneColour: string;
|
|
5
5
|
optionTwoColour: string;
|
|
6
6
|
};
|
|
7
|
-
export declare const pickHexColourContrast: ({ backgroundColour, optionOneColour, optionTwoColour }: ColorArgs, standard: WCAG) => string;
|
|
7
|
+
export declare const pickHexColourContrast: ({ backgroundColour, optionOneColour, optionTwoColour }: ColorArgs, standard: WCAG) => string | null;
|
|
8
8
|
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper to parse hex and get HSV + alpha
|
|
3
|
+
* @param hex Hex color string
|
|
4
|
+
* @returns Object with hue, saturation, value, and alpha
|
|
5
|
+
*/
|
|
6
|
+
export declare function getColorInfo(hex: string): {
|
|
7
|
+
h: number;
|
|
8
|
+
s: number;
|
|
9
|
+
v: number;
|
|
10
|
+
a: number;
|
|
11
|
+
} | null;
|
|
12
|
+
/**
|
|
13
|
+
* Helper to get custom order for greyscale values
|
|
14
|
+
* @param v HSV value (brightness) from 0 to 1
|
|
15
|
+
* @returns Order priority: 0 for grey/other, 1 for black, 2 for white
|
|
16
|
+
*/
|
|
17
|
+
export declare function getGreyscaleOrder(v: number): number;
|
|
18
|
+
/**
|
|
19
|
+
* Sorts an array of hex colours by hue, then by saturation.
|
|
20
|
+
* Colours with 0% saturation (greyscale) are shifted to the end.
|
|
21
|
+
* Fully transparent colours (alpha = 0) are placed at the very end.
|
|
22
|
+
* Accepts hex colours in #RRGGBB or #RRGGBBAA format.
|
|
23
|
+
* @param hexColours Array of hex colour strings
|
|
24
|
+
* @returns Sorted array of hex colour strings
|
|
25
|
+
*/
|
|
26
|
+
export declare function sortHexColours(hexColours: string[]): string[];
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The HSV colour model represents colours by describing the Hue, Saturation, and Value channels.
|
|
3
|
+
*/
|
|
4
|
+
export interface HSVColour {
|
|
5
|
+
/** A number between 0 and 360 to describe the Hue channel */
|
|
6
|
+
h: number;
|
|
7
|
+
/** A number between 0 and 1 to describe the Saturation channel */
|
|
8
|
+
s: number;
|
|
9
|
+
/** A number between 0 and 1 to describe the Value channel */
|
|
10
|
+
v: number;
|
|
11
|
+
}
|
|
1
12
|
/**
|
|
2
13
|
* The RGB colour model represents a broad array of colours by describing the Red, Green and Blue channels.
|
|
3
14
|
*/
|
|
@@ -48,5 +59,5 @@ export type WCAG = "WCAG2.1" | "WCAG3.0";
|
|
|
48
59
|
/**
|
|
49
60
|
* Named list from https://developer.mozilla.org/en-US/docs/Web/CSS/named-color
|
|
50
61
|
*/
|
|
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";
|
|
62
|
+
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" | "orange" | "orangered" | "orchid" | "palegoldenrod" | "palegreen" | "paleturquoise" | "palevioletred" | "papayawhip" | "peachpuff" | "peru" | "pink" | "plum" | "powderblue" | "purple" | "rebeccapurple" | "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
63
|
export type NamedCSSColours = Array<[NamedCSSColour, string]>;
|
package/dist/util/index.d.ts
CHANGED
|
@@ -15,15 +15,7 @@ export declare function deltaHue_d({ C1, C2, h1_d, h2_d }: HueHelper): number;
|
|
|
15
15
|
* @param HueHelper param
|
|
16
16
|
*/
|
|
17
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
18
|
export declare const toRadians: (n: number) => number;
|
|
23
|
-
/**
|
|
24
|
-
* Calculates a recurring square root
|
|
25
|
-
* @param n Input number
|
|
26
|
-
*/
|
|
27
19
|
export declare const bigSquare: (n: number) => number;
|
|
28
20
|
/**
|
|
29
21
|
* Normalise black and white colorimetry as specified in IEC 61966-2-1
|
|
@@ -31,10 +23,6 @@ export declare const bigSquare: (n: number) => number;
|
|
|
31
23
|
* @param rgbValue number to be normalised
|
|
32
24
|
*/
|
|
33
25
|
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
26
|
export declare function constrainLab(n: number): number;
|
|
39
27
|
/**
|
|
40
28
|
* Clamps a number between two values
|
|
@@ -44,3 +32,5 @@ export declare function constrainLab(n: number): number;
|
|
|
44
32
|
* @returns {number} - A clamped value
|
|
45
33
|
*/
|
|
46
34
|
export declare function clamp(value: number, min: number, max: number): number;
|
|
35
|
+
/** MDN reference for CSS named colours — shared to avoid duplicating the URL string in the bundle */
|
|
36
|
+
export declare const NAMED_CSS_COLOUR_URL = "https://developer.mozilla.org/en-US/docs/Web/CSS/named-color";
|
package/dist/util/regexers.d.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
export declare const
|
|
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;
|
|
1
|
+
/** Any valid hexadecimal colour: 3, 4, 6, or 8 hex digits after `#` */
|
|
2
|
+
export declare const hexAnyRegex: RegExp;
|
|
9
3
|
/**
|
|
10
|
-
* Captures the
|
|
4
|
+
* Captures the following CSS RGB formats:
|
|
11
5
|
* - `rgb(0,0,0)`
|
|
12
6
|
* - `rgba(0, 0, 0, 0.4)`
|
|
13
7
|
* - `rgba(0,0,0,50%)`
|
|
@@ -15,5 +9,8 @@ export declare const shortAlphaHexRegex: RegExp;
|
|
|
15
9
|
* - `rgba(0 0 0 / 0.4)`
|
|
16
10
|
* - `rgb(0 0 0 / 0.5)`
|
|
17
11
|
* - `rgb(0 0 0 / 50%)`
|
|
12
|
+
* - `rgb(50%, 25%, 100%)`
|
|
13
|
+
* - `rgba(50%, 25%, 100%, 0.8)`
|
|
14
|
+
* - `rgba(50%, 25%, 100%, 80%)`
|
|
18
15
|
*/
|
|
19
16
|
export declare const cssRGBARegex: RegExp;
|
package/package.json
CHANGED
|
@@ -1,59 +1,75 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
2
|
+
"name": "@sardine/colour",
|
|
3
|
+
"version": "4.0.0",
|
|
4
|
+
"description": "It does things to colours",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"unpkg": "./dist/index.min.js",
|
|
10
|
+
"sideEffects": false,
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"require": "./dist/index.cjs",
|
|
15
|
+
"import": "./dist/index.mjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "npx vite build",
|
|
20
|
+
"test": "npx vitest run --coverage",
|
|
21
|
+
"types:emit": "npx tsc -p tsconfig.emit.json",
|
|
22
|
+
"types:check": "npx tsc --noEmit",
|
|
23
|
+
"static": "npx biome ci src",
|
|
24
|
+
"size": "size-limit"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/sardinedev/colour.git"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"keywords": [
|
|
37
|
+
"color",
|
|
38
|
+
"colour"
|
|
39
|
+
],
|
|
40
|
+
"author": "Hugo Nogueira",
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/sardinedev/colour/issues"
|
|
44
|
+
},
|
|
45
|
+
"homepage": "https://github.com/sardinedev/colour#readme",
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">= 20"
|
|
48
|
+
},
|
|
49
|
+
"size-limit": [
|
|
50
|
+
{
|
|
51
|
+
"name": "ESM build",
|
|
52
|
+
"path": "dist/index.mjs",
|
|
53
|
+
"brotli": false
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"name": "CJS build",
|
|
57
|
+
"path": "dist/index.cjs",
|
|
58
|
+
"brotli": false
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@biomejs/biome": "2.4.10",
|
|
63
|
+
"@changesets/cli": "^2.27.1",
|
|
64
|
+
"@size-limit/preset-small-lib": "^12.0.0",
|
|
65
|
+
"@tsconfig/node24": "^24.0.0",
|
|
66
|
+
"@tsconfig/strictest": "^2.0.5",
|
|
67
|
+
"@types/node": "^24.10.13",
|
|
68
|
+
"@vitest/coverage-v8": "^4.0.0",
|
|
69
|
+
"lefthook": "^2.0.0",
|
|
70
|
+
"size-limit": "^12.0.0",
|
|
71
|
+
"typescript": "^5.4.5",
|
|
72
|
+
"vite": "^8.0.0",
|
|
73
|
+
"vitest": "^4.0.0"
|
|
74
|
+
}
|
|
59
75
|
}
|