@zag-js/color-utils 2.0.0-next.3 → 2.0.0-next.4
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/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/defineProperty.js +11 -0
- package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/defineProperty.mjs +11 -0
- package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/toPrimitive.js +13 -0
- package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/toPrimitive.mjs +13 -0
- package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/toPropertyKey.js +8 -0
- package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/toPropertyKey.mjs +8 -0
- package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/typeof.js +15 -0
- package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/typeof.mjs +10 -0
- package/dist/area-gradient.d.mts +9 -11
- package/dist/area-gradient.d.ts +9 -11
- package/dist/area-gradient.js +58 -89
- package/dist/area-gradient.mjs +54 -77
- package/dist/color-format-gradient.d.mts +76 -78
- package/dist/color-format-gradient.d.ts +76 -78
- package/dist/color-format-gradient.js +118 -185
- package/dist/color-format-gradient.mjs +104 -152
- package/dist/color.d.mts +20 -23
- package/dist/color.d.ts +20 -23
- package/dist/color.js +57 -83
- package/dist/color.mjs +53 -60
- package/dist/gamut.d.mts +2 -5
- package/dist/gamut.d.ts +2 -5
- package/dist/gamut.js +12 -34
- package/dist/gamut.mjs +8 -11
- package/dist/hsb-color.d.mts +37 -40
- package/dist/hsb-color.d.ts +37 -40
- package/dist/hsb-color.js +164 -200
- package/dist/hsb-color.mjs +158 -175
- package/dist/hsl-color.d.mts +33 -36
- package/dist/hsl-color.d.ts +33 -36
- package/dist/hsl-color.js +139 -168
- package/dist/hsl-color.mjs +132 -142
- package/dist/index.d.mts +8 -7
- package/dist/index.d.ts +8 -7
- package/dist/index.js +23 -60
- package/dist/index.mjs +2 -28
- package/dist/native-color.d.mts +1 -3
- package/dist/native-color.d.ts +1 -3
- package/dist/native-color.js +16 -39
- package/dist/native-color.mjs +12 -16
- package/dist/oklab-color.d.mts +57 -60
- package/dist/oklab-color.d.ts +57 -60
- package/dist/oklab-color.js +363 -379
- package/dist/oklab-color.mjs +353 -350
- package/dist/oklab-math.d.mts +26 -28
- package/dist/oklab-math.d.ts +26 -28
- package/dist/oklab-math.js +123 -142
- package/dist/oklab-math.mjs +108 -108
- package/dist/parse-color.d.mts +3 -6
- package/dist/parse-color.d.ts +3 -6
- package/dist/parse-color.js +22 -48
- package/dist/parse-color.mjs +13 -20
- package/dist/rgb-color.d.mts +33 -36
- package/dist/rgb-color.d.ts +33 -36
- package/dist/rgb-color.js +182 -220
- package/dist/rgb-color.mjs +174 -193
- package/dist/types.d.mts +82 -84
- package/dist/types.d.ts +82 -84
- package/dist/types.js +4 -18
- package/dist/types.mjs +1 -0
- package/package.json +3 -3
- package/dist/chunk-QZ7TP4HQ.mjs +0 -7
|
@@ -1,164 +1,116 @@
|
|
|
1
|
-
import "./chunk-QZ7TP4HQ.mjs";
|
|
2
|
-
|
|
3
1
|
// src/color-format-gradient.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
return result;
|
|
2
|
+
const generateRGB_R = (orientation, dir, zValue) => {
|
|
3
|
+
const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`;
|
|
4
|
+
return {
|
|
5
|
+
areaStyles: { backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(${zValue},0,0),rgb(${zValue},255,0))` },
|
|
6
|
+
areaGradientStyles: {
|
|
7
|
+
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(${zValue},0,255),rgb(${zValue},255,255))`,
|
|
8
|
+
WebkitMaskImage: maskImage,
|
|
9
|
+
maskImage
|
|
10
|
+
}
|
|
11
|
+
};
|
|
17
12
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
return result;
|
|
13
|
+
const generateRGB_G = (orientation, dir, zValue) => {
|
|
14
|
+
const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`;
|
|
15
|
+
return {
|
|
16
|
+
areaStyles: { backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,${zValue},0),rgb(255,${zValue},0))` },
|
|
17
|
+
areaGradientStyles: {
|
|
18
|
+
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,${zValue},255),rgb(255,${zValue},255))`,
|
|
19
|
+
WebkitMaskImage: maskImage,
|
|
20
|
+
maskImage
|
|
21
|
+
}
|
|
22
|
+
};
|
|
31
23
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
return result;
|
|
24
|
+
const generateRGB_B = (orientation, dir, zValue) => {
|
|
25
|
+
const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`;
|
|
26
|
+
return {
|
|
27
|
+
areaStyles: { backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,0,${zValue}),rgb(255,0,${zValue}))` },
|
|
28
|
+
areaGradientStyles: {
|
|
29
|
+
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,255,${zValue}),rgb(255,255,${zValue}))`,
|
|
30
|
+
WebkitMaskImage: maskImage,
|
|
31
|
+
maskImage
|
|
32
|
+
}
|
|
33
|
+
};
|
|
45
34
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
return result;
|
|
35
|
+
const generateHSL_H = (orientation, dir, zValue) => {
|
|
36
|
+
return {
|
|
37
|
+
areaStyles: {},
|
|
38
|
+
areaGradientStyles: { background: [
|
|
39
|
+
`linear-gradient(to ${orientation[Number(dir)]}, hsla(0,0%,0%,1) 0%, hsla(0,0%,0%,0) 50%, hsla(0,0%,100%,0) 50%, hsla(0,0%,100%,1) 100%)`,
|
|
40
|
+
`linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,50%),hsla(0,0%,50%,0))`,
|
|
41
|
+
`hsl(${zValue}, 100%, 50%)`
|
|
42
|
+
].join(",") }
|
|
43
|
+
};
|
|
58
44
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
return result;
|
|
45
|
+
const generateHSL_S = (orientation, dir, alphaValue) => {
|
|
46
|
+
return {
|
|
47
|
+
areaStyles: {},
|
|
48
|
+
areaGradientStyles: { background: [
|
|
49
|
+
`linear-gradient(to ${orientation[Number(!dir)]}, hsla(0,0%,0%,${alphaValue}) 0%, hsla(0,0%,0%,0) 50%, hsla(0,0%,100%,0) 50%, hsla(0,0%,100%,${alphaValue}) 100%)`,
|
|
50
|
+
`linear-gradient(to ${orientation[Number(dir)]},hsla(0,100%,50%,${alphaValue}),hsla(60,100%,50%,${alphaValue}),hsla(120,100%,50%,${alphaValue}),hsla(180,100%,50%,${alphaValue}),hsla(240,100%,50%,${alphaValue}),hsla(300,100%,50%,${alphaValue}),hsla(359,100%,50%,${alphaValue}))`,
|
|
51
|
+
"hsl(0, 0%, 50%)"
|
|
52
|
+
].join(",") }
|
|
53
|
+
};
|
|
71
54
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
`linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,${zValue}%),hsla(0,0%,${zValue}%,0))`,
|
|
78
|
-
`linear-gradient(to ${orientation[Number(dir)]},hsl(0,100%,${zValue}%),hsl(60,100%,${zValue}%),hsl(120,100%,${zValue}%),hsl(180,100%,${zValue}%),hsl(240,100%,${zValue}%),hsl(300,100%,${zValue}%),hsl(360,100%,${zValue}%))`
|
|
79
|
-
].join(",")
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
return result;
|
|
55
|
+
const generateHSL_L = (orientation, dir, zValue) => {
|
|
56
|
+
return {
|
|
57
|
+
areaStyles: {},
|
|
58
|
+
areaGradientStyles: { backgroundImage: [`linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,${zValue}%),hsla(0,0%,${zValue}%,0))`, `linear-gradient(to ${orientation[Number(dir)]},hsl(0,100%,${zValue}%),hsl(60,100%,${zValue}%),hsl(120,100%,${zValue}%),hsl(180,100%,${zValue}%),hsl(240,100%,${zValue}%),hsl(300,100%,${zValue}%),hsl(360,100%,${zValue}%))`].join(",") }
|
|
59
|
+
};
|
|
83
60
|
};
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
return result;
|
|
61
|
+
const generateHSB_H = (orientation, dir, zValue) => {
|
|
62
|
+
return {
|
|
63
|
+
areaStyles: {},
|
|
64
|
+
areaGradientStyles: { background: [
|
|
65
|
+
`linear-gradient(to ${orientation[Number(dir)]},hsl(0,0%,0%),hsla(0,0%,0%,0))`,
|
|
66
|
+
`linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,100%),hsla(0,0%,100%,0))`,
|
|
67
|
+
`hsl(${zValue}, 100%, 50%)`
|
|
68
|
+
].join(",") }
|
|
69
|
+
};
|
|
96
70
|
};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
return result;
|
|
71
|
+
const generateHSB_S = (orientation, dir, alphaValue) => {
|
|
72
|
+
return {
|
|
73
|
+
areaStyles: {},
|
|
74
|
+
areaGradientStyles: { background: [
|
|
75
|
+
`linear-gradient(to ${orientation[Number(!dir)]},hsla(0,0%,0%,${alphaValue}),hsla(0,0%,0%,0))`,
|
|
76
|
+
`linear-gradient(to ${orientation[Number(dir)]},hsla(0,100%,50%,${alphaValue}),hsla(60,100%,50%,${alphaValue}),hsla(120,100%,50%,${alphaValue}),hsla(180,100%,50%,${alphaValue}),hsla(240,100%,50%,${alphaValue}),hsla(300,100%,50%,${alphaValue}),hsla(359,100%,50%,${alphaValue}))`,
|
|
77
|
+
`linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,0%),hsl(0,0%,100%))`
|
|
78
|
+
].join(",") }
|
|
79
|
+
};
|
|
109
80
|
};
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
return result;
|
|
81
|
+
const generateHSB_B = (orientation, dir, alphaValue) => {
|
|
82
|
+
return {
|
|
83
|
+
areaStyles: {},
|
|
84
|
+
areaGradientStyles: { background: [
|
|
85
|
+
`linear-gradient(to ${orientation[Number(!dir)]},hsla(0,0%,100%,${alphaValue}),hsla(0,0%,100%,0))`,
|
|
86
|
+
`linear-gradient(to ${orientation[Number(dir)]},hsla(0,100%,50%,${alphaValue}),hsla(60,100%,50%,${alphaValue}),hsla(120,100%,50%,${alphaValue}),hsla(180,100%,50%,${alphaValue}),hsla(240,100%,50%,${alphaValue}),hsla(300,100%,50%,${alphaValue}),hsla(359,100%,50%,${alphaValue}))`,
|
|
87
|
+
"#000"
|
|
88
|
+
].join(",") }
|
|
89
|
+
};
|
|
122
90
|
};
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
};
|
|
136
|
-
return result;
|
|
91
|
+
/** oklab: x = a, y = b, z = lightness (fixed L) */
|
|
92
|
+
const generateOKLAB_AB = (orientation, dir, L) => {
|
|
93
|
+
const l = L === 0 ? "none" : `${(L * 100).toFixed(2)}%`;
|
|
94
|
+
const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, black, transparent)`;
|
|
95
|
+
return {
|
|
96
|
+
areaStyles: { background: `linear-gradient(to ${orientation[Number(dir)]} in oklab, oklab(${l} -100% 100%), oklab(${l} 100% 100%))` },
|
|
97
|
+
areaGradientStyles: {
|
|
98
|
+
background: `linear-gradient(to ${orientation[Number(dir)]} in oklab, oklab(${l} -100% -100%), oklab(${l} 100% -100%))`,
|
|
99
|
+
maskImage,
|
|
100
|
+
WebkitMaskImage: maskImage
|
|
101
|
+
}
|
|
102
|
+
};
|
|
137
103
|
};
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
};
|
|
150
|
-
return result;
|
|
151
|
-
};
|
|
152
|
-
export {
|
|
153
|
-
generateHSB_B,
|
|
154
|
-
generateHSB_H,
|
|
155
|
-
generateHSB_S,
|
|
156
|
-
generateHSL_H,
|
|
157
|
-
generateHSL_L,
|
|
158
|
-
generateHSL_S,
|
|
159
|
-
generateOKLAB_AB,
|
|
160
|
-
generateOKLCH_LC,
|
|
161
|
-
generateRGB_B,
|
|
162
|
-
generateRGB_G,
|
|
163
|
-
generateRGB_R
|
|
104
|
+
/** oklch: x = lightness, y = chroma, z = hue (fixed H) */
|
|
105
|
+
const generateOKLCH_LC = (orientation, dir, H) => {
|
|
106
|
+
const maskImage = `linear-gradient(to ${orientation[Number(dir)]}, transparent, black)`;
|
|
107
|
+
return {
|
|
108
|
+
areaStyles: { background: `linear-gradient(to ${orientation[Number(!dir)]} in oklch, oklch(0 0.001 ${H}), oklch(1 0.001 ${H}))` },
|
|
109
|
+
areaGradientStyles: {
|
|
110
|
+
background: `linear-gradient(to ${orientation[Number(!dir)]} in oklch, oklch(0 0.5 ${H}), oklch(1 0.5 ${H}))`,
|
|
111
|
+
maskImage,
|
|
112
|
+
WebkitMaskImage: maskImage
|
|
113
|
+
}
|
|
114
|
+
};
|
|
164
115
|
};
|
|
116
|
+
export { generateHSB_B, generateHSB_H, generateHSB_S, generateHSL_H, generateHSL_L, generateHSL_S, generateOKLAB_AB, generateOKLCH_LC, generateRGB_B, generateRGB_G, generateRGB_R };
|
package/dist/color.d.mts
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export { Color };
|
|
1
|
+
import { Color2DAxes, ColorAxes, ColorChannel, ColorChannelRange, ColorFormat, ColorStringFormat, ColorType } from "./types.mjs";
|
|
2
|
+
export declare abstract class Color implements ColorType {
|
|
3
|
+
abstract toFormat(format: ColorFormat): ColorType;
|
|
4
|
+
abstract toJSON(): Record<string, number>;
|
|
5
|
+
abstract toString(format?: ColorStringFormat): string;
|
|
6
|
+
abstract clone(): ColorType;
|
|
7
|
+
abstract getChannelRange(channel: ColorChannel): ColorChannelRange;
|
|
8
|
+
abstract getFormat(): ColorFormat;
|
|
9
|
+
abstract getChannels(): [ColorChannel, ColorChannel, ColorChannel];
|
|
10
|
+
abstract formatChannelValue(channel: ColorChannel, locale: string): string;
|
|
11
|
+
toHexInt(): number;
|
|
12
|
+
getChannelValue(channel: ColorChannel): number;
|
|
13
|
+
getChannelValuePercent(channel: ColorChannel, valueToCheck?: number): number;
|
|
14
|
+
getChannelPercentValue(channel: ColorChannel, percentToCheck: number): number;
|
|
15
|
+
withChannelValue(channel: ColorChannel, value: number): ColorType;
|
|
16
|
+
getColorAxes(xyChannels: Color2DAxes): ColorAxes;
|
|
17
|
+
incrementChannel(channel: ColorChannel, stepSize: number): ColorType;
|
|
18
|
+
decrementChannel(channel: ColorChannel, stepSize: number): ColorType;
|
|
19
|
+
isEqual(color: ColorType): boolean;
|
|
20
|
+
}
|
package/dist/color.d.ts
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export { Color };
|
|
1
|
+
import { Color2DAxes, ColorAxes, ColorChannel, ColorChannelRange, ColorFormat, ColorStringFormat, ColorType } from "./types.js";
|
|
2
|
+
export declare abstract class Color implements ColorType {
|
|
3
|
+
abstract toFormat(format: ColorFormat): ColorType;
|
|
4
|
+
abstract toJSON(): Record<string, number>;
|
|
5
|
+
abstract toString(format?: ColorStringFormat): string;
|
|
6
|
+
abstract clone(): ColorType;
|
|
7
|
+
abstract getChannelRange(channel: ColorChannel): ColorChannelRange;
|
|
8
|
+
abstract getFormat(): ColorFormat;
|
|
9
|
+
abstract getChannels(): [ColorChannel, ColorChannel, ColorChannel];
|
|
10
|
+
abstract formatChannelValue(channel: ColorChannel, locale: string): string;
|
|
11
|
+
toHexInt(): number;
|
|
12
|
+
getChannelValue(channel: ColorChannel): number;
|
|
13
|
+
getChannelValuePercent(channel: ColorChannel, valueToCheck?: number): number;
|
|
14
|
+
getChannelPercentValue(channel: ColorChannel, percentToCheck: number): number;
|
|
15
|
+
withChannelValue(channel: ColorChannel, value: number): ColorType;
|
|
16
|
+
getColorAxes(xyChannels: Color2DAxes): ColorAxes;
|
|
17
|
+
incrementChannel(channel: ColorChannel, stepSize: number): ColorType;
|
|
18
|
+
decrementChannel(channel: ColorChannel, stepSize: number): ColorType;
|
|
19
|
+
isEqual(color: ColorType): boolean;
|
|
20
|
+
}
|
package/dist/color.js
CHANGED
|
@@ -1,87 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/color.ts
|
|
21
|
-
var color_exports = {};
|
|
22
|
-
__export(color_exports, {
|
|
23
|
-
Color: () => Color
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
24
4
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
5
|
+
let _zag_js_utils = require("@zag-js/utils");
|
|
6
|
+
// src/color.ts
|
|
7
|
+
const isEqualObject = (a, b) => {
|
|
8
|
+
if (Object.keys(a).length !== Object.keys(b).length) return false;
|
|
9
|
+
for (let key in a) if (a[key] !== b[key]) return false;
|
|
10
|
+
return true;
|
|
31
11
|
};
|
|
32
12
|
var Color = class {
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const isSame = isEqualObject(this.toJSON(), color.toJSON());
|
|
81
|
-
return isSame && this.getChannelValue("alpha") === color.getChannelValue("alpha");
|
|
82
|
-
}
|
|
13
|
+
toHexInt() {
|
|
14
|
+
return this.toFormat("rgba").toHexInt();
|
|
15
|
+
}
|
|
16
|
+
getChannelValue(channel) {
|
|
17
|
+
if (channel in this) return this[channel];
|
|
18
|
+
throw new Error("Unsupported color channel: " + channel);
|
|
19
|
+
}
|
|
20
|
+
getChannelValuePercent(channel, valueToCheck) {
|
|
21
|
+
const value = valueToCheck ?? this.getChannelValue(channel);
|
|
22
|
+
const { minValue, maxValue } = this.getChannelRange(channel);
|
|
23
|
+
return (0, _zag_js_utils.getValuePercent)(value, minValue, maxValue);
|
|
24
|
+
}
|
|
25
|
+
getChannelPercentValue(channel, percentToCheck) {
|
|
26
|
+
const { minValue, maxValue, step } = this.getChannelRange(channel);
|
|
27
|
+
const percentValue = (0, _zag_js_utils.getPercentValue)(percentToCheck, minValue, maxValue, step);
|
|
28
|
+
return (0, _zag_js_utils.snapValueToStep)(percentValue, minValue, maxValue, step);
|
|
29
|
+
}
|
|
30
|
+
withChannelValue(channel, value) {
|
|
31
|
+
const { minValue, maxValue } = this.getChannelRange(channel);
|
|
32
|
+
if (channel in this) {
|
|
33
|
+
let clone = this.clone();
|
|
34
|
+
clone[channel] = (0, _zag_js_utils.clampValue)(value, minValue, maxValue);
|
|
35
|
+
return clone;
|
|
36
|
+
}
|
|
37
|
+
throw new Error("Unsupported color channel: " + channel);
|
|
38
|
+
}
|
|
39
|
+
getColorAxes(xyChannels) {
|
|
40
|
+
let { xChannel, yChannel } = xyChannels;
|
|
41
|
+
let xCh = xChannel || this.getChannels().find((c) => c !== yChannel);
|
|
42
|
+
let yCh = yChannel || this.getChannels().find((c) => c !== xCh);
|
|
43
|
+
return {
|
|
44
|
+
xChannel: xCh,
|
|
45
|
+
yChannel: yCh,
|
|
46
|
+
zChannel: this.getChannels().find((c) => c !== xCh && c !== yCh)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
incrementChannel(channel, stepSize) {
|
|
50
|
+
const { minValue, maxValue, step } = this.getChannelRange(channel);
|
|
51
|
+
const value = (0, _zag_js_utils.snapValueToStep)((0, _zag_js_utils.clampValue)(this.getChannelValue(channel) + stepSize, minValue, maxValue), minValue, maxValue, step);
|
|
52
|
+
return this.withChannelValue(channel, value);
|
|
53
|
+
}
|
|
54
|
+
decrementChannel(channel, stepSize) {
|
|
55
|
+
return this.incrementChannel(channel, -stepSize);
|
|
56
|
+
}
|
|
57
|
+
isEqual(color) {
|
|
58
|
+
return isEqualObject(this.toJSON(), color.toJSON()) && this.getChannelValue("alpha") === color.getChannelValue("alpha");
|
|
59
|
+
}
|
|
83
60
|
};
|
|
84
|
-
|
|
85
|
-
0 && (module.exports = {
|
|
86
|
-
Color
|
|
87
|
-
});
|
|
61
|
+
exports.Color = Color;
|
package/dist/color.mjs
CHANGED
|
@@ -1,64 +1,57 @@
|
|
|
1
|
-
import "./chunk-QZ7TP4HQ.mjs";
|
|
2
|
-
|
|
3
|
-
// src/color.ts
|
|
4
1
|
import { clampValue, getPercentValue, getValuePercent, snapValueToStep } from "@zag-js/utils";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
// src/color.ts
|
|
3
|
+
const isEqualObject = (a, b) => {
|
|
4
|
+
if (Object.keys(a).length !== Object.keys(b).length) return false;
|
|
5
|
+
for (let key in a) if (a[key] !== b[key]) return false;
|
|
6
|
+
return true;
|
|
9
7
|
};
|
|
10
8
|
var Color = class {
|
|
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
|
-
const isSame = isEqualObject(this.toJSON(), color.toJSON());
|
|
59
|
-
return isSame && this.getChannelValue("alpha") === color.getChannelValue("alpha");
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
export {
|
|
63
|
-
Color
|
|
9
|
+
toHexInt() {
|
|
10
|
+
return this.toFormat("rgba").toHexInt();
|
|
11
|
+
}
|
|
12
|
+
getChannelValue(channel) {
|
|
13
|
+
if (channel in this) return this[channel];
|
|
14
|
+
throw new Error("Unsupported color channel: " + channel);
|
|
15
|
+
}
|
|
16
|
+
getChannelValuePercent(channel, valueToCheck) {
|
|
17
|
+
const value = valueToCheck ?? this.getChannelValue(channel);
|
|
18
|
+
const { minValue, maxValue } = this.getChannelRange(channel);
|
|
19
|
+
return getValuePercent(value, minValue, maxValue);
|
|
20
|
+
}
|
|
21
|
+
getChannelPercentValue(channel, percentToCheck) {
|
|
22
|
+
const { minValue, maxValue, step } = this.getChannelRange(channel);
|
|
23
|
+
const percentValue = getPercentValue(percentToCheck, minValue, maxValue, step);
|
|
24
|
+
return snapValueToStep(percentValue, minValue, maxValue, step);
|
|
25
|
+
}
|
|
26
|
+
withChannelValue(channel, value) {
|
|
27
|
+
const { minValue, maxValue } = this.getChannelRange(channel);
|
|
28
|
+
if (channel in this) {
|
|
29
|
+
let clone = this.clone();
|
|
30
|
+
clone[channel] = clampValue(value, minValue, maxValue);
|
|
31
|
+
return clone;
|
|
32
|
+
}
|
|
33
|
+
throw new Error("Unsupported color channel: " + channel);
|
|
34
|
+
}
|
|
35
|
+
getColorAxes(xyChannels) {
|
|
36
|
+
let { xChannel, yChannel } = xyChannels;
|
|
37
|
+
let xCh = xChannel || this.getChannels().find((c) => c !== yChannel);
|
|
38
|
+
let yCh = yChannel || this.getChannels().find((c) => c !== xCh);
|
|
39
|
+
return {
|
|
40
|
+
xChannel: xCh,
|
|
41
|
+
yChannel: yCh,
|
|
42
|
+
zChannel: this.getChannels().find((c) => c !== xCh && c !== yCh)
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
incrementChannel(channel, stepSize) {
|
|
46
|
+
const { minValue, maxValue, step } = this.getChannelRange(channel);
|
|
47
|
+
const value = snapValueToStep(clampValue(this.getChannelValue(channel) + stepSize, minValue, maxValue), minValue, maxValue, step);
|
|
48
|
+
return this.withChannelValue(channel, value);
|
|
49
|
+
}
|
|
50
|
+
decrementChannel(channel, stepSize) {
|
|
51
|
+
return this.incrementChannel(channel, -stepSize);
|
|
52
|
+
}
|
|
53
|
+
isEqual(color) {
|
|
54
|
+
return isEqualObject(this.toJSON(), color.toJSON()) && this.getChannelValue("alpha") === color.getChannelValue("alpha");
|
|
55
|
+
}
|
|
64
56
|
};
|
|
57
|
+
export { Color };
|
package/dist/gamut.d.mts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { ColorType } from
|
|
2
|
-
|
|
1
|
+
import { ColorType } from "./types.mjs";
|
|
3
2
|
/** Whether the color lies inside the sRGB gamut (checks in linear RGB space, no clamping). */
|
|
4
|
-
declare function isInSrgbGamut(color: ColorType): boolean;
|
|
5
|
-
|
|
6
|
-
export { isInSrgbGamut };
|
|
3
|
+
export declare function isInSrgbGamut(color: ColorType): boolean;
|