@tempots/std 0.27.0 → 0.28.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/color-D7FAmkht.cjs +1 -0
- package/color-SZxckS9U.js +522 -0
- package/color-adjust.cjs +1 -0
- package/color-adjust.d.ts +148 -0
- package/color-adjust.js +47 -0
- package/color-contrast.cjs +1 -0
- package/color-contrast.d.ts +96 -0
- package/color-contrast.js +22 -0
- package/color-distance.cjs +1 -0
- package/color-distance.d.ts +41 -0
- package/color-distance.js +25 -0
- package/color-harmony.cjs +1 -0
- package/color-harmony.d.ts +81 -0
- package/color-harmony.js +35 -0
- package/color-hsl.cjs +1 -0
- package/color-hsl.d.ts +81 -0
- package/color-hsl.js +10 -0
- package/color-hsv.cjs +1 -0
- package/color-hsv.d.ts +116 -0
- package/color-hsv.js +12 -0
- package/color-hwb.cjs +1 -0
- package/color-hwb.d.ts +88 -0
- package/color-hwb.js +10 -0
- package/color-lab.cjs +1 -0
- package/color-lab.d.ts +161 -0
- package/color-lab.js +15 -0
- package/color-mix.cjs +1 -0
- package/color-mix.d.ts +50 -0
- package/color-mix.js +101 -0
- package/color-named.cjs +1 -0
- package/color-named.d.ts +8 -0
- package/color-named.js +153 -0
- package/color-oklab.cjs +1 -0
- package/color-oklab.d.ts +141 -0
- package/color-oklab.js +15 -0
- package/color-rgb.cjs +1 -0
- package/color-rgb.d.ts +119 -0
- package/color-rgb.js +14 -0
- package/color-utils.cjs +1 -0
- package/color-utils.d.ts +57 -0
- package/color-utils.js +54 -0
- package/color.cjs +1 -0
- package/color.d.ts +466 -0
- package/color.js +33 -0
- package/index.cjs +1 -1
- package/index.d.ts +14 -0
- package/index.js +367 -263
- package/package.json +99 -1
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { Color } from './color';
|
|
2
|
+
/**
|
|
3
|
+
* Increases the lightness of a color by the given amount.
|
|
4
|
+
*
|
|
5
|
+
* Operates in OKLCH space and returns the result in the
|
|
6
|
+
* same color space as the input.
|
|
7
|
+
*
|
|
8
|
+
* @param c - The color to lighten.
|
|
9
|
+
* @param amount - A value between 0 and 1 indicating how
|
|
10
|
+
* much to increase lightness.
|
|
11
|
+
* @returns The lightened color in the original color space.
|
|
12
|
+
* @public
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const light = lighten(rgb8a(100, 50, 50, 1), 0.2)
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare const lighten: (c: Color, amount: number) => Color;
|
|
19
|
+
/**
|
|
20
|
+
* Decreases the lightness of a color by the given amount.
|
|
21
|
+
*
|
|
22
|
+
* Operates in OKLCH space and returns the result in the
|
|
23
|
+
* same color space as the input.
|
|
24
|
+
*
|
|
25
|
+
* @param c - The color to darken.
|
|
26
|
+
* @param amount - A value between 0 and 1 indicating how
|
|
27
|
+
* much to decrease lightness.
|
|
28
|
+
* @returns The darkened color in the original color space.
|
|
29
|
+
* @public
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const dark = darken(rgb8a(200, 150, 150, 1), 0.2)
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare const darken: (c: Color, amount: number) => Color;
|
|
36
|
+
/**
|
|
37
|
+
* Increases the chroma (saturation) of a color by the
|
|
38
|
+
* given amount.
|
|
39
|
+
*
|
|
40
|
+
* Operates in OKLCH space. The amount is scaled by 0.4 to
|
|
41
|
+
* map the 0–1 input range to the typical OKLCH chroma
|
|
42
|
+
* range.
|
|
43
|
+
*
|
|
44
|
+
* @param c - The color to saturate.
|
|
45
|
+
* @param amount - A value between 0 and 1 indicating how
|
|
46
|
+
* much to increase chroma.
|
|
47
|
+
* @returns The saturated color in the original color space.
|
|
48
|
+
* @public
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* const vivid = saturate(rgb8a(100, 100, 100, 1), 0.5)
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare const saturate: (c: Color, amount: number) => Color;
|
|
55
|
+
/**
|
|
56
|
+
* Decreases the chroma (saturation) of a color by the
|
|
57
|
+
* given amount.
|
|
58
|
+
*
|
|
59
|
+
* Operates in OKLCH space. The amount is scaled by 0.4 to
|
|
60
|
+
* map the 0–1 input range to the typical OKLCH chroma
|
|
61
|
+
* range.
|
|
62
|
+
*
|
|
63
|
+
* @param c - The color to desaturate.
|
|
64
|
+
* @param amount - A value between 0 and 1 indicating how
|
|
65
|
+
* much to decrease chroma.
|
|
66
|
+
* @returns The desaturated color in the original color
|
|
67
|
+
* space.
|
|
68
|
+
* @public
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* const muted = desaturate(rgb8a(255, 0, 0, 1), 0.5)
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare const desaturate: (c: Color, amount: number) => Color;
|
|
75
|
+
/**
|
|
76
|
+
* Increases the opacity (alpha) of a color by the given
|
|
77
|
+
* amount.
|
|
78
|
+
*
|
|
79
|
+
* No color space conversion is performed — the alpha
|
|
80
|
+
* channel is adjusted directly.
|
|
81
|
+
*
|
|
82
|
+
* @param c - The color to make more opaque.
|
|
83
|
+
* @param amount - A value between 0 and 1 indicating how
|
|
84
|
+
* much to increase alpha.
|
|
85
|
+
* @returns The color with increased opacity, in the same
|
|
86
|
+
* color space.
|
|
87
|
+
* @public
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* const opaque = opacify(rgb8a(100, 50, 50, 0.5), 0.3)
|
|
91
|
+
* // alpha is now 0.8
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export declare const opacify: (c: Color, amount: number) => Color;
|
|
95
|
+
/**
|
|
96
|
+
* Decreases the opacity (alpha) of a color by the given
|
|
97
|
+
* amount.
|
|
98
|
+
*
|
|
99
|
+
* No color space conversion is performed — the alpha
|
|
100
|
+
* channel is adjusted directly.
|
|
101
|
+
*
|
|
102
|
+
* @param c - The color to make more transparent.
|
|
103
|
+
* @param amount - A value between 0 and 1 indicating how
|
|
104
|
+
* much to decrease alpha.
|
|
105
|
+
* @returns The color with decreased opacity, in the same
|
|
106
|
+
* color space.
|
|
107
|
+
* @public
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* const faded = transparentize(rgb8a(100, 50, 50, 1), 0.3)
|
|
111
|
+
* // alpha is now 0.7
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export declare const transparentize: (c: Color, amount: number) => Color;
|
|
115
|
+
/**
|
|
116
|
+
* Inverts the RGB channels of a color while preserving
|
|
117
|
+
* alpha.
|
|
118
|
+
*
|
|
119
|
+
* Converts to RGB8 space, inverts each channel
|
|
120
|
+
* (`255 - value`), and converts back to the original
|
|
121
|
+
* color space.
|
|
122
|
+
*
|
|
123
|
+
* @param c - The color to invert.
|
|
124
|
+
* @returns The inverted color in the original color space.
|
|
125
|
+
* @public
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* const inv = invert(rgb8a(255, 0, 0, 1))
|
|
129
|
+
* // result is cyan: rgb8a(0, 255, 255, 1)
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export declare const invert: (c: Color) => Color;
|
|
133
|
+
/**
|
|
134
|
+
* Converts a color to grayscale by removing all chroma.
|
|
135
|
+
*
|
|
136
|
+
* Operates in OKLCH space by setting chroma to 0 while
|
|
137
|
+
* preserving lightness and hue. Returns the result in the
|
|
138
|
+
* same color space as the input.
|
|
139
|
+
*
|
|
140
|
+
* @param c - The color to convert to grayscale.
|
|
141
|
+
* @returns The grayscale color in the original color space.
|
|
142
|
+
* @public
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* const gray = grayscale(rgb8a(255, 0, 0, 1))
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
export declare const grayscale: (c: Color) => Color;
|
package/color-adjust.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { clamp as e } from "./number.js";
|
|
2
|
+
import { m as s, R as c, a4 as l } from "./color-SZxckS9U.js";
|
|
3
|
+
const i = (a, n) => {
|
|
4
|
+
const o = a.space, t = s(a, "oklch"), r = c(e(t.l + n, 0, 1), t.c, t.h, t.alpha);
|
|
5
|
+
return s(r, o);
|
|
6
|
+
}, u = (a, n) => {
|
|
7
|
+
const o = a.space, t = s(a, "oklch"), r = c(e(t.l - n, 0, 1), t.c, t.h, t.alpha);
|
|
8
|
+
return s(r, o);
|
|
9
|
+
}, d = (a, n) => {
|
|
10
|
+
const o = a.space, t = s(a, "oklch"), r = c(
|
|
11
|
+
t.l,
|
|
12
|
+
Math.max(0, t.c + n * 0.4),
|
|
13
|
+
t.h,
|
|
14
|
+
t.alpha
|
|
15
|
+
);
|
|
16
|
+
return s(r, o);
|
|
17
|
+
}, g = (a, n) => {
|
|
18
|
+
const o = a.space, t = s(a, "oklch"), r = c(
|
|
19
|
+
t.l,
|
|
20
|
+
Math.max(0, t.c - n * 0.4),
|
|
21
|
+
t.h,
|
|
22
|
+
t.alpha
|
|
23
|
+
);
|
|
24
|
+
return s(r, o);
|
|
25
|
+
}, k = (a, n) => ({
|
|
26
|
+
...a,
|
|
27
|
+
alpha: e(a.alpha + n, 0, 1)
|
|
28
|
+
}), m = (a, n) => ({
|
|
29
|
+
...a,
|
|
30
|
+
alpha: e(a.alpha - n, 0, 1)
|
|
31
|
+
}), j = (a) => {
|
|
32
|
+
const n = a.space, o = s(a, "rgb8"), t = l(255 - o.r, 255 - o.g, 255 - o.b, o.alpha);
|
|
33
|
+
return s(t, n);
|
|
34
|
+
}, b = (a) => {
|
|
35
|
+
const n = a.space, o = s(a, "oklch"), t = c(o.l, 0, o.h, o.alpha);
|
|
36
|
+
return s(t, n);
|
|
37
|
+
};
|
|
38
|
+
export {
|
|
39
|
+
u as darken,
|
|
40
|
+
g as desaturate,
|
|
41
|
+
b as grayscale,
|
|
42
|
+
j as invert,
|
|
43
|
+
i as lighten,
|
|
44
|
+
k as opacify,
|
|
45
|
+
d as saturate,
|
|
46
|
+
m as transparentize
|
|
47
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./color-D7FAmkht.cjs"),a=t=>t<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4),l=t=>{const o=e.convertColor(t,"rgb8"),n=a(o.r/255),r=a(o.g/255),s=a(o.b/255);return .2126*n+.7152*r+.0722*s},c=(t,o)=>{const n=l(t),r=l(o),s=Math.max(n,r),g=Math.min(n,r);return(s+.05)/(g+.05)},i=(t,o=e.rgb8a(0,0,0),n=e.rgb8a(255,255,255))=>{const r=c(t,o),s=c(t,n);return r>=s?o:n},b={AA:4.5,AAA:7,"AA-large":3,"AAA-large":4.5},A=(t,o,n)=>c(t,o)>=b[n];exports.contrastColor=i;exports.contrastRatio=c;exports.luminance=l;exports.meetsContrast=A;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Color } from './color';
|
|
2
|
+
/**
|
|
3
|
+
* WCAG contrast level thresholds.
|
|
4
|
+
*
|
|
5
|
+
* - `'AA'` — 4.5:1 for normal text
|
|
6
|
+
* - `'AAA'` — 7:1 for normal text
|
|
7
|
+
* - `'AA-large'` — 3:1 for large text
|
|
8
|
+
* - `'AAA-large'` — 4.5:1 for large text
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export type ContrastLevel = 'AA' | 'AAA' | 'AA-large' | 'AAA-large';
|
|
13
|
+
/**
|
|
14
|
+
* Computes the WCAG relative luminance of a color.
|
|
15
|
+
*
|
|
16
|
+
* Converts the color to sRGB, linearizes each channel,
|
|
17
|
+
* and returns the weighted sum per the WCAG 2.x formula.
|
|
18
|
+
*
|
|
19
|
+
* @param c - The color to measure
|
|
20
|
+
* @returns A number between 0 (darkest) and 1 (lightest)
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* luminance(rgb8a(255, 255, 255)) // 1
|
|
25
|
+
* luminance(rgb8a(0, 0, 0)) // 0
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export declare const luminance: (c: Color) => number;
|
|
31
|
+
/**
|
|
32
|
+
* Computes the WCAG contrast ratio between two colors.
|
|
33
|
+
*
|
|
34
|
+
* The ratio ranges from 1:1 (identical) to 21:1
|
|
35
|
+
* (black vs white).
|
|
36
|
+
*
|
|
37
|
+
* @param a - The first color
|
|
38
|
+
* @param b - The second color
|
|
39
|
+
* @returns A number between 1 and 21
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* contrastRatio(
|
|
44
|
+
* rgb8a(0, 0, 0),
|
|
45
|
+
* rgb8a(255, 255, 255)
|
|
46
|
+
* ) // 21
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
export declare const contrastRatio: (a: Color, b: Color) => number;
|
|
52
|
+
/**
|
|
53
|
+
* Picks whichever of two candidates has better contrast
|
|
54
|
+
* against a reference color.
|
|
55
|
+
*
|
|
56
|
+
* Useful for choosing a readable foreground color for
|
|
57
|
+
* a given background.
|
|
58
|
+
*
|
|
59
|
+
* @param c - The reference color (e.g. a background)
|
|
60
|
+
* @param dark - The dark candidate (defaults to black)
|
|
61
|
+
* @param light - The light candidate (defaults to white)
|
|
62
|
+
* @returns The candidate with the higher contrast ratio
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* // Returns white for a dark background
|
|
67
|
+
* contrastColor(rgb8a(30, 30, 30))
|
|
68
|
+
*
|
|
69
|
+
* // Returns black for a light background
|
|
70
|
+
* contrastColor(rgb8a(220, 220, 220))
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
export declare const contrastColor: (c: Color, dark?: Color, light?: Color) => Color;
|
|
76
|
+
/**
|
|
77
|
+
* Checks whether two colors meet a WCAG contrast level.
|
|
78
|
+
*
|
|
79
|
+
* @param a - The first color
|
|
80
|
+
* @param b - The second color
|
|
81
|
+
* @param level - The WCAG level to test against
|
|
82
|
+
* @returns `true` if the contrast ratio meets or exceeds
|
|
83
|
+
* the threshold for the given level
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* meetsContrast(
|
|
88
|
+
* rgb8a(0, 0, 0),
|
|
89
|
+
* rgb8a(255, 255, 255),
|
|
90
|
+
* 'AAA'
|
|
91
|
+
* ) // true
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* @public
|
|
95
|
+
*/
|
|
96
|
+
export declare const meetsContrast: (a: Color, b: Color, level: ContrastLevel) => boolean;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { a4 as e, m as g } from "./color-SZxckS9U.js";
|
|
2
|
+
const a = (t) => t <= 0.04045 ? t / 12.92 : Math.pow((t + 0.055) / 1.055, 2.4), l = (t) => {
|
|
3
|
+
const o = g(t, "rgb8"), n = a(o.r / 255), r = a(o.g / 255), s = a(o.b / 255);
|
|
4
|
+
return 0.2126 * n + 0.7152 * r + 0.0722 * s;
|
|
5
|
+
}, c = (t, o) => {
|
|
6
|
+
const n = l(t), r = l(o), s = Math.max(n, r), A = Math.min(n, r);
|
|
7
|
+
return (s + 0.05) / (A + 0.05);
|
|
8
|
+
}, m = (t, o = e(0, 0, 0), n = e(255, 255, 255)) => {
|
|
9
|
+
const r = c(t, o), s = c(t, n);
|
|
10
|
+
return r >= s ? o : n;
|
|
11
|
+
}, b = {
|
|
12
|
+
AA: 4.5,
|
|
13
|
+
AAA: 7,
|
|
14
|
+
"AA-large": 3,
|
|
15
|
+
"AAA-large": 4.5
|
|
16
|
+
}, h = (t, o, n) => c(t, o) >= b[n];
|
|
17
|
+
export {
|
|
18
|
+
m as contrastColor,
|
|
19
|
+
c as contrastRatio,
|
|
20
|
+
l as luminance,
|
|
21
|
+
h as meetsContrast
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("./color-D7FAmkht.cjs"),r=l=>l*Math.PI/180,F=(l,q)=>{const n=d.convertColor(l,"lab"),c=d.convertColor(q,"lab"),h=n.l-c.l,e=n.a-c.a,a=n.b-c.b;return Math.sqrt(h*h+e*e+a*a)},J=(l,q)=>{const n=d.convertColor(l,"lab"),c=d.convertColor(q,"lab"),h=n.l,e=n.a,a=n.b,v=c.l,m=c.a,M=c.b,T=Math.sqrt(e*e+a*a),H=Math.sqrt(m*m+M*M),I=(T+H)/2,g=Math.pow(I,7),w=.5*(1-Math.sqrt(g/(g+Math.pow(25,7)))),f=e*(1+w),L=m*(1+w),i=Math.sqrt(f*f+a*a),p=Math.sqrt(L*L+M*M);let t=Math.atan2(a,f)*180/Math.PI;t<0&&(t+=360);let o=Math.atan2(M,L)*180/Math.PI;o<0&&(o+=360);const R=v-h,y=p-i;let b;i*p===0?b=0:Math.abs(o-t)<=180?b=o-t:o-t>180?b=o-t-360:b=o-t+360;const j=2*Math.sqrt(i*p)*Math.sin(r(b/2)),x=(h+v)/2,_=(i+p)/2;let s;i*p===0?s=t+o:Math.abs(t-o)<=180?s=(t+o)/2:t+o<360?s=(t+o+360)/2:s=(t+o-360)/2;const G=1-.17*Math.cos(r(s-30))+.24*Math.cos(r(2*s))+.32*Math.cos(r(3*s+6))-.2*Math.cos(r(4*s-63)),C=x-50,O=1+.015*C*C/Math.sqrt(20+C*C),k=1+.045*_,z=1+.015*_*G,A=30*Math.exp(-((s-275)/25*((s-275)/25))),D=Math.pow(_,7),B=2*Math.sqrt(D/(D+Math.pow(25,7))),E=-Math.sin(r(2*A))*B,P=R/O,S=y/k,u=j/z;return Math.sqrt(P*P+S*S+u*u+E*S*u)};exports.colorDistance=J;exports.colorDistanceSimple=F;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Color } from './color';
|
|
2
|
+
/**
|
|
3
|
+
* Computes the CIE76 color distance (Euclidean distance in
|
|
4
|
+
* CIELAB space) between two colors.
|
|
5
|
+
*
|
|
6
|
+
* @param a - The first color.
|
|
7
|
+
* @param b - The second color.
|
|
8
|
+
* @returns The Euclidean distance in LAB space.
|
|
9
|
+
* @public
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { rgb8a } from './color'
|
|
13
|
+
* colorDistanceSimple(
|
|
14
|
+
* rgb8a(255, 0, 0),
|
|
15
|
+
* rgb8a(0, 255, 0)
|
|
16
|
+
* ) // ~170.56
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const colorDistanceSimple: (a: Color, b: Color) => number;
|
|
20
|
+
/**
|
|
21
|
+
* Computes the CIEDE2000 color distance between two colors.
|
|
22
|
+
*
|
|
23
|
+
* This is the most perceptually uniform color difference metric
|
|
24
|
+
* standardized by the CIE. It accounts for lightness, chroma,
|
|
25
|
+
* and hue weighting as well as interactive effects between
|
|
26
|
+
* chroma and hue differences.
|
|
27
|
+
*
|
|
28
|
+
* @param a - The first color.
|
|
29
|
+
* @param b - The second color.
|
|
30
|
+
* @returns The CIEDE2000 deltaE value.
|
|
31
|
+
* @public
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { rgb8a } from './color'
|
|
35
|
+
* colorDistance(
|
|
36
|
+
* rgb8a(255, 0, 0),
|
|
37
|
+
* rgb8a(0, 255, 0)
|
|
38
|
+
* ) // ~86.61
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare const colorDistance: (a: Color, b: Color) => number;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { m } from "./color-SZxckS9U.js";
|
|
2
|
+
const h = (M) => M * Math.PI / 180, K = (M, d) => {
|
|
3
|
+
const n = m(M, "lab"), c = m(d, "lab"), l = n.l - c.l, e = n.a - c.a, o = n.b - c.b;
|
|
4
|
+
return Math.sqrt(l * l + e * e + o * o);
|
|
5
|
+
}, N = (M, d) => {
|
|
6
|
+
const n = m(M, "lab"), c = m(d, "lab"), l = n.l, e = n.a, o = n.b, H = c.l, q = c.a, r = c.b, x = Math.sqrt(e * e + o * o), D = Math.sqrt(q * q + r * r), R = (x + D) / 2, I = Math.pow(R, 7), P = 0.5 * (1 - Math.sqrt(I / (I + Math.pow(25, 7)))), f = e * (1 + P), L = q * (1 + P), p = Math.sqrt(f * f + o * o), b = Math.sqrt(L * L + r * r);
|
|
7
|
+
let t = Math.atan2(o, f) * 180 / Math.PI;
|
|
8
|
+
t < 0 && (t += 360);
|
|
9
|
+
let s = Math.atan2(r, L) * 180 / Math.PI;
|
|
10
|
+
s < 0 && (s += 360);
|
|
11
|
+
const g = H - l, v = b - p;
|
|
12
|
+
let i;
|
|
13
|
+
p * b === 0 ? i = 0 : Math.abs(s - t) <= 180 ? i = s - t : s - t > 180 ? i = s - t - 360 : i = s - t + 360;
|
|
14
|
+
const G = 2 * Math.sqrt(p * b) * Math.sin(h(i / 2)), j = (l + H) / 2, _ = (p + b) / 2;
|
|
15
|
+
let a;
|
|
16
|
+
p * b === 0 ? a = t + s : Math.abs(t - s) <= 180 ? a = (t + s) / 2 : t + s < 360 ? a = (t + s + 360) / 2 : a = (t + s - 360) / 2;
|
|
17
|
+
const k = 1 - 0.17 * Math.cos(h(a - 30)) + 0.24 * Math.cos(h(2 * a)) + 0.32 * Math.cos(h(3 * a + 6)) - 0.2 * Math.cos(h(4 * a - 63)), C = j - 50, y = 1 + 0.015 * C * C / Math.sqrt(20 + C * C), z = 1 + 0.045 * _, A = 1 + 0.015 * _ * k, B = 30 * Math.exp(-((a - 275) / 25 * ((a - 275) / 25))), T = Math.pow(_, 7), E = 2 * Math.sqrt(T / (T + Math.pow(25, 7))), F = -Math.sin(h(2 * B)) * E, u = g / y, w = v / z, S = G / A;
|
|
18
|
+
return Math.sqrt(
|
|
19
|
+
u * u + w * w + S * S + F * w * S
|
|
20
|
+
);
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
N as colorDistance,
|
|
24
|
+
K as colorDistanceSimple
|
|
25
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./number.cjs"),n=require("./color-D7FAmkht.cjs"),t=(o,e)=>{const a=o.space,r=n.convertColor(o,"oklch"),l=n.oklcha(r.l,r.c,s.wrapCircular(r.h+e,360),r.alpha);return n.convertColor(l,a)},c=o=>t(o,180),i=(o,e=30)=>[o,t(o,e),t(o,-e)],u=o=>[o,t(o,120),t(o,240)],m=o=>[o,t(o,150),t(o,210)],p=o=>[o,t(o,90),t(o,180),t(o,270)];exports.analogous=i;exports.complement=c;exports.splitComplementary=m;exports.tetradic=p;exports.triadic=u;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Color } from './color';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the complementary color by rotating the hue
|
|
4
|
+
* 180 degrees in OKLCH space.
|
|
5
|
+
*
|
|
6
|
+
* @param c - Any color value
|
|
7
|
+
* @returns The complementary color in the same color
|
|
8
|
+
* space as the input
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const red = rgba(1, 0, 0, 1)
|
|
12
|
+
* const cyan = complement(red)
|
|
13
|
+
* ```
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export declare const complement: (c: Color) => Color;
|
|
17
|
+
/**
|
|
18
|
+
* Returns an analogous color scheme consisting of the
|
|
19
|
+
* original color and two neighbors at the given angle
|
|
20
|
+
* offset.
|
|
21
|
+
*
|
|
22
|
+
* @param c - Any color value
|
|
23
|
+
* @param angle - The hue offset in degrees (default 30)
|
|
24
|
+
* @returns A triple of [original, +angle, -angle] in
|
|
25
|
+
* the same color space as the input
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const red = rgba(1, 0, 0, 1)
|
|
29
|
+
* const [base, warm, cool] = analogous(red)
|
|
30
|
+
* ```
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export declare const analogous: (c: Color, angle?: number) => [Color, Color, Color];
|
|
34
|
+
/**
|
|
35
|
+
* Returns a triadic color scheme consisting of the
|
|
36
|
+
* original color and two colors evenly spaced at 120
|
|
37
|
+
* degree intervals.
|
|
38
|
+
*
|
|
39
|
+
* @param c - Any color value
|
|
40
|
+
* @returns A triple of [original, +120, +240] in the
|
|
41
|
+
* same color space as the input
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* const red = rgba(1, 0, 0, 1)
|
|
45
|
+
* const [a, b, c] = triadic(red)
|
|
46
|
+
* ```
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
export declare const triadic: (c: Color) => [Color, Color, Color];
|
|
50
|
+
/**
|
|
51
|
+
* Returns a split-complementary color scheme consisting
|
|
52
|
+
* of the original color and two colors adjacent to its
|
|
53
|
+
* complement at 150 and 210 degree offsets.
|
|
54
|
+
*
|
|
55
|
+
* @param c - Any color value
|
|
56
|
+
* @returns A triple of [original, +150, +210] in the
|
|
57
|
+
* same color space as the input
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* const red = rgba(1, 0, 0, 1)
|
|
61
|
+
* const [base, left, right] = splitComplementary(red)
|
|
62
|
+
* ```
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
65
|
+
export declare const splitComplementary: (c: Color) => [Color, Color, Color];
|
|
66
|
+
/**
|
|
67
|
+
* Returns a tetradic (rectangular) color scheme
|
|
68
|
+
* consisting of the original color and three colors
|
|
69
|
+
* evenly spaced at 90 degree intervals.
|
|
70
|
+
*
|
|
71
|
+
* @param c - Any color value
|
|
72
|
+
* @returns A quadruple of [original, +90, +180, +270]
|
|
73
|
+
* in the same color space as the input
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* const red = rgba(1, 0, 0, 1)
|
|
77
|
+
* const [a, b, c, d] = tetradic(red)
|
|
78
|
+
* ```
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
export declare const tetradic: (c: Color) => [Color, Color, Color, Color];
|
package/color-harmony.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { wrapCircular as l } from "./number.js";
|
|
2
|
+
import { m as n, R as i } from "./color-SZxckS9U.js";
|
|
3
|
+
const t = (o, r) => {
|
|
4
|
+
const s = o.space, a = n(o, "oklch"), e = i(
|
|
5
|
+
a.l,
|
|
6
|
+
a.c,
|
|
7
|
+
l(a.h + r, 360),
|
|
8
|
+
a.alpha
|
|
9
|
+
);
|
|
10
|
+
return n(e, s);
|
|
11
|
+
}, c = (o) => t(o, 180), h = (o, r = 30) => [
|
|
12
|
+
o,
|
|
13
|
+
t(o, r),
|
|
14
|
+
t(o, -r)
|
|
15
|
+
], u = (o) => [
|
|
16
|
+
o,
|
|
17
|
+
t(o, 120),
|
|
18
|
+
t(o, 240)
|
|
19
|
+
], d = (o) => [
|
|
20
|
+
o,
|
|
21
|
+
t(o, 150),
|
|
22
|
+
t(o, 210)
|
|
23
|
+
], k = (o) => [
|
|
24
|
+
o,
|
|
25
|
+
t(o, 90),
|
|
26
|
+
t(o, 180),
|
|
27
|
+
t(o, 270)
|
|
28
|
+
];
|
|
29
|
+
export {
|
|
30
|
+
h as analogous,
|
|
31
|
+
c as complement,
|
|
32
|
+
d as splitComplementary,
|
|
33
|
+
k as tetradic,
|
|
34
|
+
u as triadic
|
|
35
|
+
};
|
package/color-hsl.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./error.cjs");require("./number.cjs");const r=require("./color-D7FAmkht.cjs");exports.canParseHsl=r.canParseHsl;exports.hslaToHslString=r.hslaToHslString;exports.hslaToRgb8a=r.hslaToRgb8a;exports.parseHsl=r.parseHsl;exports.rgb8aToHsla=r.rgb8aToHsla;
|
package/color-hsl.d.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { RGB8A, HSLA } from './color';
|
|
2
|
+
/**
|
|
3
|
+
* Returns `true` if the string can be parsed as an `hsl()` or `hsla()` color.
|
|
4
|
+
*
|
|
5
|
+
* Supports both legacy comma-separated and modern space-separated syntax.
|
|
6
|
+
*
|
|
7
|
+
* @param s - The string to test.
|
|
8
|
+
* @returns `true` if the string is a valid HSL functional notation.
|
|
9
|
+
* @public
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* canParseHsl('hsl(0, 100%, 50%)') // true
|
|
13
|
+
* canParseHsl('hsl(120 50% 50% / 0.5)') // true
|
|
14
|
+
* canParseHsl('#ff0000') // false
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare const canParseHsl: (s: string) => boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Parses an `hsl()` or `hsla()` color string into an HSLA color.
|
|
20
|
+
*
|
|
21
|
+
* Supports both legacy comma-separated and modern space-separated syntax.
|
|
22
|
+
*
|
|
23
|
+
* @param s - The string to parse.
|
|
24
|
+
* @returns An HSLA color.
|
|
25
|
+
* @throws ParsingError if the string is not a valid HSL color.
|
|
26
|
+
* @public
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* parseHsl('hsl(0, 100%, 50%)') // hsla(0, 100, 50)
|
|
30
|
+
* parseHsl('hsla(120, 50%, 75%, 0.8)') // hsla(120, 50, 75, 0.8)
|
|
31
|
+
* parseHsl('hsl(240 100% 50% / 50%)') // hsla(240, 100, 50, 0.5)
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare const parseHsl: (s: string) => HSLA;
|
|
35
|
+
/**
|
|
36
|
+
* Converts an RGB8A color to an HSLA color using the standard min/max/delta
|
|
37
|
+
* algorithm.
|
|
38
|
+
*
|
|
39
|
+
* @param c - The RGB8A color to convert.
|
|
40
|
+
* @returns The equivalent HSLA color.
|
|
41
|
+
* @public
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* rgb8aToHsla(rgb8a(255, 0, 0)) // hsla(0, 100, 50)
|
|
45
|
+
* rgb8aToHsla(rgb8a(0, 128, 0)) // hsla(120, 100, ~25.1)
|
|
46
|
+
* rgb8aToHsla(rgb8a(0, 0, 0)) // hsla(0, 0, 0)
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare const rgb8aToHsla: (c: RGB8A) => HSLA;
|
|
50
|
+
/**
|
|
51
|
+
* Converts an HSLA color to an RGB8A color using sector-based hue-to-RGB
|
|
52
|
+
* conversion.
|
|
53
|
+
*
|
|
54
|
+
* @param c - The HSLA color to convert.
|
|
55
|
+
* @returns The equivalent RGB8A color.
|
|
56
|
+
* @public
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* hslaToRgb8a(hsla(0, 100, 50)) // rgb8a(255, 0, 0)
|
|
60
|
+
* hslaToRgb8a(hsla(120, 100, 50)) // rgb8a(0, 255, 0)
|
|
61
|
+
* hslaToRgb8a(hsla(240, 100, 50)) // rgb8a(0, 0, 255)
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare const hslaToRgb8a: (c: HSLA) => RGB8A;
|
|
65
|
+
/**
|
|
66
|
+
* Serializes an HSLA color to an `hsl()` or `hsla()` CSS string.
|
|
67
|
+
*
|
|
68
|
+
* Produces `hsl(h, s%, l%)` when alpha is 1, or `hsla(h, s%, l%, alpha)`
|
|
69
|
+
* otherwise. Hue, saturation, and lightness are rounded to two decimal
|
|
70
|
+
* places for readability.
|
|
71
|
+
*
|
|
72
|
+
* @param c - The HSLA color to serialize.
|
|
73
|
+
* @returns A CSS color string.
|
|
74
|
+
* @public
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* hslaToHslString(hsla(0, 100, 50)) // 'hsl(0, 100%, 50%)'
|
|
78
|
+
* hslaToHslString(hsla(120, 50, 75, 0.5)) // 'hsla(120, 50%, 75%, 0.5)'
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare const hslaToHslString: (c: HSLA) => string;
|
package/color-hsl.js
ADDED
package/color-hsv.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./error.cjs");require("./number.cjs");const s=require("./color-D7FAmkht.cjs");exports.canParseHsv=s.canParseHsv;exports.hslaToHsva=s.hslaToHsva;exports.hsvaToHsla=s.hsvaToHsla;exports.hsvaToHsvString=s.hsvaToHsvString;exports.hsvaToRgb8a=s.hsvaToRgb8a;exports.parseHsv=s.parseHsv;exports.rgb8aToHsva=s.rgb8aToHsva;
|