@zag-js/color-utils 2.0.0-next.2 → 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.
Files changed (62) hide show
  1. package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/defineProperty.js +11 -0
  2. package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/defineProperty.mjs +11 -0
  3. package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/toPrimitive.js +13 -0
  4. package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/toPrimitive.mjs +13 -0
  5. package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/toPropertyKey.js +8 -0
  6. package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/toPropertyKey.mjs +8 -0
  7. package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/typeof.js +15 -0
  8. package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/typeof.mjs +10 -0
  9. package/dist/area-gradient.d.mts +9 -11
  10. package/dist/area-gradient.d.ts +9 -11
  11. package/dist/area-gradient.js +58 -89
  12. package/dist/area-gradient.mjs +54 -77
  13. package/dist/color-format-gradient.d.mts +76 -78
  14. package/dist/color-format-gradient.d.ts +76 -78
  15. package/dist/color-format-gradient.js +118 -185
  16. package/dist/color-format-gradient.mjs +104 -152
  17. package/dist/color.d.mts +20 -23
  18. package/dist/color.d.ts +20 -23
  19. package/dist/color.js +57 -83
  20. package/dist/color.mjs +53 -60
  21. package/dist/gamut.d.mts +2 -5
  22. package/dist/gamut.d.ts +2 -5
  23. package/dist/gamut.js +12 -34
  24. package/dist/gamut.mjs +8 -11
  25. package/dist/hsb-color.d.mts +37 -40
  26. package/dist/hsb-color.d.ts +37 -40
  27. package/dist/hsb-color.js +164 -200
  28. package/dist/hsb-color.mjs +158 -175
  29. package/dist/hsl-color.d.mts +33 -36
  30. package/dist/hsl-color.d.ts +33 -36
  31. package/dist/hsl-color.js +139 -168
  32. package/dist/hsl-color.mjs +132 -142
  33. package/dist/index.d.mts +8 -7
  34. package/dist/index.d.ts +8 -7
  35. package/dist/index.js +23 -60
  36. package/dist/index.mjs +2 -28
  37. package/dist/native-color.d.mts +1 -3
  38. package/dist/native-color.d.ts +1 -3
  39. package/dist/native-color.js +16 -39
  40. package/dist/native-color.mjs +12 -16
  41. package/dist/oklab-color.d.mts +57 -60
  42. package/dist/oklab-color.d.ts +57 -60
  43. package/dist/oklab-color.js +363 -379
  44. package/dist/oklab-color.mjs +353 -350
  45. package/dist/oklab-math.d.mts +26 -28
  46. package/dist/oklab-math.d.ts +26 -28
  47. package/dist/oklab-math.js +123 -142
  48. package/dist/oklab-math.mjs +108 -108
  49. package/dist/parse-color.d.mts +3 -6
  50. package/dist/parse-color.d.ts +3 -6
  51. package/dist/parse-color.js +22 -48
  52. package/dist/parse-color.mjs +13 -20
  53. package/dist/rgb-color.d.mts +33 -36
  54. package/dist/rgb-color.d.ts +33 -36
  55. package/dist/rgb-color.js +182 -220
  56. package/dist/rgb-color.mjs +174 -193
  57. package/dist/types.d.mts +82 -84
  58. package/dist/types.d.ts +82 -84
  59. package/dist/types.js +4 -18
  60. package/dist/types.mjs +1 -0
  61. package/package.json +3 -3
  62. 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
- var generateRGB_R = (orientation, dir, zValue) => {
5
- const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`;
6
- const result = {
7
- areaStyles: {
8
- backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(${zValue},0,0),rgb(${zValue},255,0))`
9
- },
10
- areaGradientStyles: {
11
- backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(${zValue},0,255),rgb(${zValue},255,255))`,
12
- WebkitMaskImage: maskImage,
13
- maskImage
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
- var generateRGB_G = (orientation, dir, zValue) => {
19
- const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`;
20
- const result = {
21
- areaStyles: {
22
- backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,${zValue},0),rgb(255,${zValue},0))`
23
- },
24
- areaGradientStyles: {
25
- backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,${zValue},255),rgb(255,${zValue},255))`,
26
- WebkitMaskImage: maskImage,
27
- maskImage
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
- var generateRGB_B = (orientation, dir, zValue) => {
33
- const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`;
34
- const result = {
35
- areaStyles: {
36
- backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,0,${zValue}),rgb(255,0,${zValue}))`
37
- },
38
- areaGradientStyles: {
39
- backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,255,${zValue}),rgb(255,255,${zValue}))`,
40
- WebkitMaskImage: maskImage,
41
- maskImage
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
- var generateHSL_H = (orientation, dir, zValue) => {
47
- const result = {
48
- areaStyles: {},
49
- areaGradientStyles: {
50
- background: [
51
- `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%)`,
52
- `linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,50%),hsla(0,0%,50%,0))`,
53
- `hsl(${zValue}, 100%, 50%)`
54
- ].join(",")
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
- var generateHSL_S = (orientation, dir, alphaValue) => {
60
- const result = {
61
- areaStyles: {},
62
- areaGradientStyles: {
63
- background: [
64
- `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%)`,
65
- `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}))`,
66
- "hsl(0, 0%, 50%)"
67
- ].join(",")
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
- var generateHSL_L = (orientation, dir, zValue) => {
73
- const result = {
74
- areaStyles: {},
75
- areaGradientStyles: {
76
- backgroundImage: [
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
- var generateHSB_H = (orientation, dir, zValue) => {
85
- const result = {
86
- areaStyles: {},
87
- areaGradientStyles: {
88
- background: [
89
- `linear-gradient(to ${orientation[Number(dir)]},hsl(0,0%,0%),hsla(0,0%,0%,0))`,
90
- `linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,100%),hsla(0,0%,100%,0))`,
91
- `hsl(${zValue}, 100%, 50%)`
92
- ].join(",")
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
- var generateHSB_S = (orientation, dir, alphaValue) => {
98
- const result = {
99
- areaStyles: {},
100
- areaGradientStyles: {
101
- background: [
102
- `linear-gradient(to ${orientation[Number(!dir)]},hsla(0,0%,0%,${alphaValue}),hsla(0,0%,0%,0))`,
103
- `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}))`,
104
- `linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,0%),hsl(0,0%,100%))`
105
- ].join(",")
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
- var generateHSB_B = (orientation, dir, alphaValue) => {
111
- const result = {
112
- areaStyles: {},
113
- areaGradientStyles: {
114
- background: [
115
- `linear-gradient(to ${orientation[Number(!dir)]},hsla(0,0%,100%,${alphaValue}),hsla(0,0%,100%,0))`,
116
- `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}))`,
117
- "#000"
118
- ].join(",")
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
- var generateOKLAB_AB = (orientation, dir, L) => {
124
- const l = L === 0 ? "none" : `${(L * 100).toFixed(2)}%`;
125
- const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, black, transparent)`;
126
- const result = {
127
- areaStyles: {
128
- background: `linear-gradient(to ${orientation[Number(dir)]} in oklab, oklab(${l} -100% 100%), oklab(${l} 100% 100%))`
129
- },
130
- areaGradientStyles: {
131
- background: `linear-gradient(to ${orientation[Number(dir)]} in oklab, oklab(${l} -100% -100%), oklab(${l} 100% -100%))`,
132
- maskImage,
133
- WebkitMaskImage: maskImage
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
- var generateOKLCH_LC = (orientation, dir, H) => {
139
- const maskImage = `linear-gradient(to ${orientation[Number(dir)]}, transparent, black)`;
140
- const result = {
141
- areaStyles: {
142
- background: `linear-gradient(to ${orientation[Number(!dir)]} in oklch, oklch(0 0.001 ${H}), oklch(1 0.001 ${H}))`
143
- },
144
- areaGradientStyles: {
145
- background: `linear-gradient(to ${orientation[Number(!dir)]} in oklch, oklch(0 0.5 ${H}), oklch(1 0.5 ${H}))`,
146
- maskImage,
147
- WebkitMaskImage: maskImage
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 { ColorType, ColorFormat, ColorStringFormat, ColorChannel, ColorChannelRange, Color2DAxes, ColorAxes } from './types.mjs';
2
-
3
- declare abstract class Color implements ColorType {
4
- abstract toFormat(format: ColorFormat): ColorType;
5
- abstract toJSON(): Record<string, number>;
6
- abstract toString(format?: ColorStringFormat): string;
7
- abstract clone(): ColorType;
8
- abstract getChannelRange(channel: ColorChannel): ColorChannelRange;
9
- abstract getFormat(): ColorFormat;
10
- abstract getChannels(): [ColorChannel, ColorChannel, ColorChannel];
11
- abstract formatChannelValue(channel: ColorChannel, locale: string): string;
12
- toHexInt(): number;
13
- getChannelValue(channel: ColorChannel): number;
14
- getChannelValuePercent(channel: ColorChannel, valueToCheck?: number): number;
15
- getChannelPercentValue(channel: ColorChannel, percentToCheck: number): number;
16
- withChannelValue(channel: ColorChannel, value: number): ColorType;
17
- getColorAxes(xyChannels: Color2DAxes): ColorAxes;
18
- incrementChannel(channel: ColorChannel, stepSize: number): ColorType;
19
- decrementChannel(channel: ColorChannel, stepSize: number): ColorType;
20
- isEqual(color: ColorType): boolean;
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 { ColorType, ColorFormat, ColorStringFormat, ColorChannel, ColorChannelRange, Color2DAxes, ColorAxes } from './types.js';
2
-
3
- declare abstract class Color implements ColorType {
4
- abstract toFormat(format: ColorFormat): ColorType;
5
- abstract toJSON(): Record<string, number>;
6
- abstract toString(format?: ColorStringFormat): string;
7
- abstract clone(): ColorType;
8
- abstract getChannelRange(channel: ColorChannel): ColorChannelRange;
9
- abstract getFormat(): ColorFormat;
10
- abstract getChannels(): [ColorChannel, ColorChannel, ColorChannel];
11
- abstract formatChannelValue(channel: ColorChannel, locale: string): string;
12
- toHexInt(): number;
13
- getChannelValue(channel: ColorChannel): number;
14
- getChannelValuePercent(channel: ColorChannel, valueToCheck?: number): number;
15
- getChannelPercentValue(channel: ColorChannel, percentToCheck: number): number;
16
- withChannelValue(channel: ColorChannel, value: number): ColorType;
17
- getColorAxes(xyChannels: Color2DAxes): ColorAxes;
18
- incrementChannel(channel: ColorChannel, stepSize: number): ColorType;
19
- decrementChannel(channel: ColorChannel, stepSize: number): ColorType;
20
- isEqual(color: ColorType): boolean;
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
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
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
- module.exports = __toCommonJS(color_exports);
26
- var import_utils = require("@zag-js/utils");
27
- var isEqualObject = (a, b) => {
28
- if (Object.keys(a).length !== Object.keys(b).length) return false;
29
- for (let key in a) if (a[key] !== b[key]) return false;
30
- return true;
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
- toHexInt() {
34
- return this.toFormat("rgba").toHexInt();
35
- }
36
- getChannelValue(channel) {
37
- if (channel in this) return this[channel];
38
- throw new Error("Unsupported color channel: " + channel);
39
- }
40
- getChannelValuePercent(channel, valueToCheck) {
41
- const value = valueToCheck ?? this.getChannelValue(channel);
42
- const { minValue, maxValue } = this.getChannelRange(channel);
43
- return (0, import_utils.getValuePercent)(value, minValue, maxValue);
44
- }
45
- getChannelPercentValue(channel, percentToCheck) {
46
- const { minValue, maxValue, step } = this.getChannelRange(channel);
47
- const percentValue = (0, import_utils.getPercentValue)(percentToCheck, minValue, maxValue, step);
48
- return (0, import_utils.snapValueToStep)(percentValue, minValue, maxValue, step);
49
- }
50
- withChannelValue(channel, value) {
51
- const { minValue, maxValue } = this.getChannelRange(channel);
52
- if (channel in this) {
53
- let clone = this.clone();
54
- clone[channel] = (0, import_utils.clampValue)(value, minValue, maxValue);
55
- return clone;
56
- }
57
- throw new Error("Unsupported color channel: " + channel);
58
- }
59
- getColorAxes(xyChannels) {
60
- let { xChannel, yChannel } = xyChannels;
61
- let xCh = xChannel || this.getChannels().find((c) => c !== yChannel);
62
- let yCh = yChannel || this.getChannels().find((c) => c !== xCh);
63
- let zCh = this.getChannels().find((c) => c !== xCh && c !== yCh);
64
- return { xChannel: xCh, yChannel: yCh, zChannel: zCh };
65
- }
66
- incrementChannel(channel, stepSize) {
67
- const { minValue, maxValue, step } = this.getChannelRange(channel);
68
- const value = (0, import_utils.snapValueToStep)(
69
- (0, import_utils.clampValue)(this.getChannelValue(channel) + stepSize, minValue, maxValue),
70
- minValue,
71
- maxValue,
72
- step
73
- );
74
- return this.withChannelValue(channel, value);
75
- }
76
- decrementChannel(channel, stepSize) {
77
- return this.incrementChannel(channel, -stepSize);
78
- }
79
- isEqual(color) {
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
- // Annotate the CommonJS export names for ESM import in node:
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
- var isEqualObject = (a, b) => {
6
- if (Object.keys(a).length !== Object.keys(b).length) return false;
7
- for (let key in a) if (a[key] !== b[key]) return false;
8
- return true;
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
- toHexInt() {
12
- return this.toFormat("rgba").toHexInt();
13
- }
14
- getChannelValue(channel) {
15
- if (channel in this) return this[channel];
16
- throw new Error("Unsupported color channel: " + channel);
17
- }
18
- getChannelValuePercent(channel, valueToCheck) {
19
- const value = valueToCheck ?? this.getChannelValue(channel);
20
- const { minValue, maxValue } = this.getChannelRange(channel);
21
- return getValuePercent(value, minValue, maxValue);
22
- }
23
- getChannelPercentValue(channel, percentToCheck) {
24
- const { minValue, maxValue, step } = this.getChannelRange(channel);
25
- const percentValue = getPercentValue(percentToCheck, minValue, maxValue, step);
26
- return snapValueToStep(percentValue, minValue, maxValue, step);
27
- }
28
- withChannelValue(channel, value) {
29
- const { minValue, maxValue } = this.getChannelRange(channel);
30
- if (channel in this) {
31
- let clone = this.clone();
32
- clone[channel] = clampValue(value, minValue, maxValue);
33
- return clone;
34
- }
35
- throw new Error("Unsupported color channel: " + channel);
36
- }
37
- getColorAxes(xyChannels) {
38
- let { xChannel, yChannel } = xyChannels;
39
- let xCh = xChannel || this.getChannels().find((c) => c !== yChannel);
40
- let yCh = yChannel || this.getChannels().find((c) => c !== xCh);
41
- let zCh = this.getChannels().find((c) => c !== xCh && c !== yCh);
42
- return { xChannel: xCh, yChannel: yCh, zChannel: zCh };
43
- }
44
- incrementChannel(channel, stepSize) {
45
- const { minValue, maxValue, step } = this.getChannelRange(channel);
46
- const value = snapValueToStep(
47
- clampValue(this.getChannelValue(channel) + stepSize, minValue, maxValue),
48
- minValue,
49
- maxValue,
50
- step
51
- );
52
- return this.withChannelValue(channel, value);
53
- }
54
- decrementChannel(channel, stepSize) {
55
- return this.incrementChannel(channel, -stepSize);
56
- }
57
- isEqual(color) {
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 './types.mjs';
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;