@zag-js/color-picker 0.10.2 → 0.10.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/color-picker.anatomy.d.ts +3 -6
- package/dist/color-picker.anatomy.js +10 -33
- package/dist/color-picker.anatomy.mjs +19 -8
- package/dist/color-picker.connect.d.ts +4 -8
- package/dist/color-picker.connect.js +56 -436
- package/dist/color-picker.connect.mjs +368 -14
- package/dist/color-picker.dom.d.ts +27 -32
- package/dist/color-picker.dom.js +12 -34
- package/dist/color-picker.dom.mjs +33 -6
- package/dist/color-picker.machine.d.ts +3 -8
- package/dist/color-picker.machine.js +46 -163
- package/dist/color-picker.machine.mjs +335 -8
- package/dist/color-picker.types.d.ts +14 -16
- package/dist/index.d.ts +4 -8
- package/dist/index.js +8 -1085
- package/dist/index.mjs +3 -21
- package/dist/utils/generate-format-background.d.ts +9 -11
- package/dist/utils/generate-format-background.js +22 -53
- package/dist/utils/generate-format-background.mjs +120 -21
- package/dist/utils/get-channel-details.d.ts +3 -7
- package/dist/utils/get-channel-details.js +15 -37
- package/dist/utils/get-channel-details.mjs +53 -6
- package/dist/utils/get-channel-display-color.d.ts +3 -5
- package/dist/utils/get-channel-display-color.js +8 -30
- package/dist/utils/get-channel-display-color.mjs +22 -6
- package/dist/utils/get-channel-input-value.d.ts +5 -10
- package/dist/utils/get-channel-input-value.js +6 -30
- package/dist/utils/get-channel-input-value.mjs +21 -8
- package/dist/utils/get-color-area-gradient.d.ts +6 -10
- package/dist/utils/get-color-area-gradient.js +14 -158
- package/dist/utils/get-color-area-gradient.mjs +61 -7
- package/dist/utils/get-slider-background.d.ts +2 -8
- package/dist/utils/get-slider-background.js +6 -29
- package/dist/utils/get-slider-background.mjs +38 -5
- package/package.json +11 -16
- package/src/color-picker.connect.ts +1 -1
- package/src/color-picker.dom.ts +1 -1
- package/src/color-picker.types.ts +3 -1
- package/src/index.ts +2 -0
- package/src/utils/get-channel-details.ts +2 -2
- package/src/utils/get-channel-display-color.ts +1 -1
- package/src/utils/get-color-area-gradient.ts +1 -1
- package/dist/chunk-2ERX54SV.mjs +0 -25
- package/dist/chunk-3XH465XT.mjs +0 -42
- package/dist/chunk-5QSFKCT5.mjs +0 -393
- package/dist/chunk-75JXJMB5.mjs +0 -22
- package/dist/chunk-JNBNPPMF.mjs +0 -24
- package/dist/chunk-KLLIOTK6.mjs +0 -55
- package/dist/chunk-KO4TBUXB.mjs +0 -74
- package/dist/chunk-ML3WX6YS.mjs +0 -345
- package/dist/chunk-OY3B7NXA.mjs +0 -132
- package/dist/chunk-SPSDVZCT.mjs +0 -35
- package/dist/color-picker.types.js +0 -18
- package/dist/color-picker.types.mjs +0 -0
|
@@ -1,29 +1,7 @@
|
|
|
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);
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
19
4
|
|
|
20
|
-
// src/utils/get-channel-input-value.ts
|
|
21
|
-
var get_channel_input_value_exports = {};
|
|
22
|
-
__export(get_channel_input_value_exports, {
|
|
23
|
-
getChannelInputRange: () => getChannelInputRange,
|
|
24
|
-
getChannelInputValue: () => getChannelInputValue
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(get_channel_input_value_exports);
|
|
27
5
|
function getChannelInputValue(color, channel) {
|
|
28
6
|
switch (channel) {
|
|
29
7
|
case "hex":
|
|
@@ -43,8 +21,6 @@ function getChannelInputRange(color, channel) {
|
|
|
43
21
|
return color.getChannelRange(channel);
|
|
44
22
|
}
|
|
45
23
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
getChannelInputValue
|
|
50
|
-
});
|
|
24
|
+
|
|
25
|
+
exports.getChannelInputRange = getChannelInputRange;
|
|
26
|
+
exports.getChannelInputValue = getChannelInputValue;
|
|
@@ -1,8 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
function getChannelInputValue(color, channel) {
|
|
2
|
+
switch (channel) {
|
|
3
|
+
case "hex":
|
|
4
|
+
return color.toString("hex");
|
|
5
|
+
case "css":
|
|
6
|
+
return color.toString("css");
|
|
7
|
+
default:
|
|
8
|
+
return color.getChannelValue(channel).toString();
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function getChannelInputRange(color, channel) {
|
|
12
|
+
switch (channel) {
|
|
13
|
+
case "hex":
|
|
14
|
+
case "css":
|
|
15
|
+
return void 0;
|
|
16
|
+
default:
|
|
17
|
+
return color.getChannelRange(channel);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { getChannelInputRange, getChannelInputValue };
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ColorChannel } from
|
|
3
|
-
import { MachineContext } from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
areaStyles: _zag_js_types.JSX.CSSProperties;
|
|
8
|
-
areaGradientStyles: _zag_js_types.JSX.CSSProperties;
|
|
1
|
+
import { JSX } from '@zag-js/types';
|
|
2
|
+
import { type ColorChannel } from "@zag-js/color-utils";
|
|
3
|
+
import { MachineContext } from "../color-picker.types";
|
|
4
|
+
export declare function getColorAreaGradient(ctx: MachineContext, xChannel: ColorChannel, yChannel: ColorChannel): {
|
|
5
|
+
areaStyles: JSX.CSSProperties;
|
|
6
|
+
areaGradientStyles: JSX.CSSProperties;
|
|
9
7
|
};
|
|
10
|
-
|
|
11
|
-
export { getColorAreaGradient };
|
|
@@ -1,151 +1,9 @@
|
|
|
1
|
-
|
|
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);
|
|
1
|
+
'use strict';
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
var get_color_area_gradient_exports = {};
|
|
22
|
-
__export(get_color_area_gradient_exports, {
|
|
23
|
-
getColorAreaGradient: () => getColorAreaGradient
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(get_color_area_gradient_exports);
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
26
4
|
|
|
27
|
-
|
|
28
|
-
var generateRGB_R = (orientation, dir, zValue) => {
|
|
29
|
-
const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`;
|
|
30
|
-
const result = {
|
|
31
|
-
areaStyles: {
|
|
32
|
-
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(${zValue},0,0),rgb(${zValue},255,0))`
|
|
33
|
-
},
|
|
34
|
-
areaGradientStyles: {
|
|
35
|
-
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(${zValue},0,255),rgb(${zValue},255,255))`,
|
|
36
|
-
WebkitMaskImage: maskImage,
|
|
37
|
-
maskImage
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
return result;
|
|
41
|
-
};
|
|
42
|
-
var generateRGB_G = (orientation, dir, zValue) => {
|
|
43
|
-
const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`;
|
|
44
|
-
const result = {
|
|
45
|
-
areaStyles: {
|
|
46
|
-
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,${zValue},0),rgb(255,${zValue},0))`
|
|
47
|
-
},
|
|
48
|
-
areaGradientStyles: {
|
|
49
|
-
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,${zValue},255),rgb(255,${zValue},255))`,
|
|
50
|
-
WebkitMaskImage: maskImage,
|
|
51
|
-
maskImage
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
return result;
|
|
55
|
-
};
|
|
56
|
-
var generateRGB_B = (orientation, dir, zValue) => {
|
|
57
|
-
const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`;
|
|
58
|
-
const result = {
|
|
59
|
-
areaStyles: {
|
|
60
|
-
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,0,${zValue}),rgb(255,0,${zValue}))`
|
|
61
|
-
},
|
|
62
|
-
areaGradientStyles: {
|
|
63
|
-
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,255,${zValue}),rgb(255,255,${zValue}))`,
|
|
64
|
-
WebkitMaskImage: maskImage,
|
|
65
|
-
maskImage
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
return result;
|
|
69
|
-
};
|
|
70
|
-
var generateHSL_H = (orientation, dir, zValue) => {
|
|
71
|
-
const result = {
|
|
72
|
-
areaStyles: {},
|
|
73
|
-
areaGradientStyles: {
|
|
74
|
-
background: [
|
|
75
|
-
`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%)`,
|
|
76
|
-
`linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,50%),hsla(0,0%,50%,0))`,
|
|
77
|
-
`hsl(${zValue}, 100%, 50%)`
|
|
78
|
-
].join(",")
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
return result;
|
|
82
|
-
};
|
|
83
|
-
var generateHSL_S = (orientation, dir, alphaValue) => {
|
|
84
|
-
const result = {
|
|
85
|
-
areaStyles: {},
|
|
86
|
-
areaGradientStyles: {
|
|
87
|
-
background: [
|
|
88
|
-
`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%)`,
|
|
89
|
-
`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}))`,
|
|
90
|
-
"hsl(0, 0%, 50%)"
|
|
91
|
-
].join(",")
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
return result;
|
|
95
|
-
};
|
|
96
|
-
var generateHSL_L = (orientation, dir, zValue) => {
|
|
97
|
-
const result = {
|
|
98
|
-
areaStyles: {},
|
|
99
|
-
areaGradientStyles: {
|
|
100
|
-
backgroundImage: [
|
|
101
|
-
`linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,${zValue}%),hsla(0,0%,${zValue}%,0))`,
|
|
102
|
-
`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}%))`
|
|
103
|
-
].join(",")
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
return result;
|
|
107
|
-
};
|
|
108
|
-
var generateHSB_H = (orientation, dir, zValue) => {
|
|
109
|
-
const result = {
|
|
110
|
-
areaStyles: {},
|
|
111
|
-
areaGradientStyles: {
|
|
112
|
-
background: [
|
|
113
|
-
`linear-gradient(to ${orientation[Number(dir)]},hsl(0,0%,0%),hsla(0,0%,0%,0))`,
|
|
114
|
-
`linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,100%),hsla(0,0%,100%,0))`,
|
|
115
|
-
`hsl(${zValue}, 100%, 50%)`
|
|
116
|
-
].join(",")
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
return result;
|
|
120
|
-
};
|
|
121
|
-
var generateHSB_S = (orientation, dir, alphaValue) => {
|
|
122
|
-
const result = {
|
|
123
|
-
areaStyles: {},
|
|
124
|
-
areaGradientStyles: {
|
|
125
|
-
background: [
|
|
126
|
-
`linear-gradient(to ${orientation[Number(!dir)]},hsla(0,0%,0%,${alphaValue}),hsla(0,0%,0%,0))`,
|
|
127
|
-
`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}))`,
|
|
128
|
-
`linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,0%),hsl(0,0%,100%))`
|
|
129
|
-
].join(",")
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
return result;
|
|
133
|
-
};
|
|
134
|
-
var generateHSB_B = (orientation, dir, alphaValue) => {
|
|
135
|
-
const result = {
|
|
136
|
-
areaStyles: {},
|
|
137
|
-
areaGradientStyles: {
|
|
138
|
-
background: [
|
|
139
|
-
`linear-gradient(to ${orientation[Number(!dir)]},hsla(0,0%,100%,${alphaValue}),hsla(0,0%,100%,0))`,
|
|
140
|
-
`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}))`,
|
|
141
|
-
"#000"
|
|
142
|
-
].join(",")
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
return result;
|
|
146
|
-
};
|
|
5
|
+
const generateFormatBackground = require('./generate-format-background.js');
|
|
147
6
|
|
|
148
|
-
// src/utils/get-color-area-gradient.ts
|
|
149
7
|
function getColorAreaGradient(ctx, xChannel, yChannel) {
|
|
150
8
|
const value = ctx.valueAsColor;
|
|
151
9
|
const { zChannel } = value.getColorSpaceAxes({ xChannel, yChannel });
|
|
@@ -159,51 +17,49 @@ function getColorAreaGradient(ctx, xChannel, yChannel) {
|
|
|
159
17
|
switch (zChannel) {
|
|
160
18
|
case "red": {
|
|
161
19
|
dir = xChannel === "green";
|
|
162
|
-
background = generateRGB_R(orientation, dir, zValue);
|
|
20
|
+
background = generateFormatBackground.generateRGB_R(orientation, dir, zValue);
|
|
163
21
|
break;
|
|
164
22
|
}
|
|
165
23
|
case "green": {
|
|
166
24
|
dir = xChannel === "red";
|
|
167
|
-
background = generateRGB_G(orientation, dir, zValue);
|
|
25
|
+
background = generateFormatBackground.generateRGB_G(orientation, dir, zValue);
|
|
168
26
|
break;
|
|
169
27
|
}
|
|
170
28
|
case "blue": {
|
|
171
29
|
dir = xChannel === "red";
|
|
172
|
-
background = generateRGB_B(orientation, dir, zValue);
|
|
30
|
+
background = generateFormatBackground.generateRGB_B(orientation, dir, zValue);
|
|
173
31
|
break;
|
|
174
32
|
}
|
|
175
33
|
case "hue": {
|
|
176
34
|
dir = xChannel !== "saturation";
|
|
177
35
|
if (isHSL) {
|
|
178
|
-
background = generateHSL_H(orientation, dir, zValue);
|
|
36
|
+
background = generateFormatBackground.generateHSL_H(orientation, dir, zValue);
|
|
179
37
|
} else {
|
|
180
|
-
background = generateHSB_H(orientation, dir, zValue);
|
|
38
|
+
background = generateFormatBackground.generateHSB_H(orientation, dir, zValue);
|
|
181
39
|
}
|
|
182
40
|
break;
|
|
183
41
|
}
|
|
184
42
|
case "saturation": {
|
|
185
43
|
dir = xChannel === "hue";
|
|
186
44
|
if (isHSL) {
|
|
187
|
-
background = generateHSL_S(orientation, dir, alphaValue);
|
|
45
|
+
background = generateFormatBackground.generateHSL_S(orientation, dir, alphaValue);
|
|
188
46
|
} else {
|
|
189
|
-
background = generateHSB_S(orientation, dir, alphaValue);
|
|
47
|
+
background = generateFormatBackground.generateHSB_S(orientation, dir, alphaValue);
|
|
190
48
|
}
|
|
191
49
|
break;
|
|
192
50
|
}
|
|
193
51
|
case "brightness": {
|
|
194
52
|
dir = xChannel === "hue";
|
|
195
|
-
background = generateHSB_B(orientation, dir, alphaValue);
|
|
53
|
+
background = generateFormatBackground.generateHSB_B(orientation, dir, alphaValue);
|
|
196
54
|
break;
|
|
197
55
|
}
|
|
198
56
|
case "lightness": {
|
|
199
57
|
dir = xChannel === "hue";
|
|
200
|
-
background = generateHSL_L(orientation, dir, zValue);
|
|
58
|
+
background = generateFormatBackground.generateHSL_L(orientation, dir, zValue);
|
|
201
59
|
break;
|
|
202
60
|
}
|
|
203
61
|
}
|
|
204
62
|
return background;
|
|
205
63
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
getColorAreaGradient
|
|
209
|
-
});
|
|
64
|
+
|
|
65
|
+
exports.getColorAreaGradient = getColorAreaGradient;
|
|
@@ -1,7 +1,61 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
1
|
+
import { generateHSL_L, generateHSB_B, generateHSL_S, generateHSB_S, generateHSL_H, generateHSB_H, generateRGB_B, generateRGB_G, generateRGB_R } from './generate-format-background.mjs';
|
|
2
|
+
|
|
3
|
+
function getColorAreaGradient(ctx, xChannel, yChannel) {
|
|
4
|
+
const value = ctx.valueAsColor;
|
|
5
|
+
const { zChannel } = value.getColorSpaceAxes({ xChannel, yChannel });
|
|
6
|
+
const zValue = value.getChannelValue(zChannel);
|
|
7
|
+
const { minValue: zMin, maxValue: zMax } = value.getChannelRange(zChannel);
|
|
8
|
+
const orientation = ["top", ctx.dir === "rtl" ? "left" : "right"];
|
|
9
|
+
let dir = false;
|
|
10
|
+
let background = { areaStyles: {}, areaGradientStyles: {} };
|
|
11
|
+
let alphaValue = (zValue - zMin) / (zMax - zMin);
|
|
12
|
+
let isHSL = value.getColorSpace() === "hsl";
|
|
13
|
+
switch (zChannel) {
|
|
14
|
+
case "red": {
|
|
15
|
+
dir = xChannel === "green";
|
|
16
|
+
background = generateRGB_R(orientation, dir, zValue);
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
case "green": {
|
|
20
|
+
dir = xChannel === "red";
|
|
21
|
+
background = generateRGB_G(orientation, dir, zValue);
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
case "blue": {
|
|
25
|
+
dir = xChannel === "red";
|
|
26
|
+
background = generateRGB_B(orientation, dir, zValue);
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
case "hue": {
|
|
30
|
+
dir = xChannel !== "saturation";
|
|
31
|
+
if (isHSL) {
|
|
32
|
+
background = generateHSL_H(orientation, dir, zValue);
|
|
33
|
+
} else {
|
|
34
|
+
background = generateHSB_H(orientation, dir, zValue);
|
|
35
|
+
}
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
case "saturation": {
|
|
39
|
+
dir = xChannel === "hue";
|
|
40
|
+
if (isHSL) {
|
|
41
|
+
background = generateHSL_S(orientation, dir, alphaValue);
|
|
42
|
+
} else {
|
|
43
|
+
background = generateHSB_S(orientation, dir, alphaValue);
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case "brightness": {
|
|
48
|
+
dir = xChannel === "hue";
|
|
49
|
+
background = generateHSB_B(orientation, dir, alphaValue);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
case "lightness": {
|
|
53
|
+
dir = xChannel === "hue";
|
|
54
|
+
background = generateHSL_L(orientation, dir, zValue);
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return background;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export { getColorAreaGradient };
|
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import '@zag-js/core';
|
|
4
|
-
import '@zag-js/types';
|
|
5
|
-
|
|
6
|
-
declare const getSliderBgImage: (ctx: MachineContext, props: Required<ColorChannelProps>) => string;
|
|
7
|
-
|
|
8
|
-
export { getSliderBgImage };
|
|
1
|
+
import { ColorChannelProps, MachineContext } from "../color-picker.types";
|
|
2
|
+
export declare const getSliderBgImage: (ctx: MachineContext, props: Required<ColorChannelProps>) => string;
|
|
@@ -1,28 +1,7 @@
|
|
|
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);
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
19
4
|
|
|
20
|
-
// src/utils/get-slider-background.ts
|
|
21
|
-
var get_slider_background_exports = {};
|
|
22
|
-
__export(get_slider_background_exports, {
|
|
23
|
-
getSliderBgImage: () => getSliderBgImage
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(get_slider_background_exports);
|
|
26
5
|
function getSliderBgDirection(orientation, dir) {
|
|
27
6
|
if (orientation === "vertical") {
|
|
28
7
|
return "top";
|
|
@@ -32,7 +11,7 @@ function getSliderBgDirection(orientation, dir) {
|
|
|
32
11
|
return "left";
|
|
33
12
|
}
|
|
34
13
|
}
|
|
35
|
-
|
|
14
|
+
const getSliderBgImage = (ctx, props) => {
|
|
36
15
|
const { channel } = props;
|
|
37
16
|
const dir = getSliderBgDirection(props.orientation, ctx.dir);
|
|
38
17
|
const value = ctx.valueAsColor;
|
|
@@ -60,7 +39,5 @@ var getSliderBgImage = (ctx, props) => {
|
|
|
60
39
|
throw new Error("Unknown color channel: " + channel);
|
|
61
40
|
}
|
|
62
41
|
};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
getSliderBgImage
|
|
66
|
-
});
|
|
42
|
+
|
|
43
|
+
exports.getSliderBgImage = getSliderBgImage;
|
|
@@ -1,6 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
function getSliderBgDirection(orientation, dir) {
|
|
2
|
+
if (orientation === "vertical") {
|
|
3
|
+
return "top";
|
|
4
|
+
} else if (dir === "ltr") {
|
|
5
|
+
return "right";
|
|
6
|
+
} else {
|
|
7
|
+
return "left";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
const getSliderBgImage = (ctx, props) => {
|
|
11
|
+
const { channel } = props;
|
|
12
|
+
const dir = getSliderBgDirection(props.orientation, ctx.dir);
|
|
13
|
+
const value = ctx.valueAsColor;
|
|
14
|
+
const { minValue, maxValue } = ctx.valueAsColor.getChannelRange(channel);
|
|
15
|
+
switch (channel) {
|
|
16
|
+
case "hue":
|
|
17
|
+
return `linear-gradient(to ${dir}, rgb(255, 0, 0) 0%, rgb(255, 255, 0) 17%, rgb(0, 255, 0) 33%, rgb(0, 255, 255) 50%, rgb(0, 0, 255) 67%, rgb(255, 0, 255) 83%, rgb(255, 0, 0) 100%)`;
|
|
18
|
+
case "lightness": {
|
|
19
|
+
let start = ctx.valueAsColor.withChannelValue(channel, minValue).toString("css");
|
|
20
|
+
let middle = value.withChannelValue(channel, (maxValue - minValue) / 2).toString("css");
|
|
21
|
+
let end = value.withChannelValue(channel, maxValue).toString("css");
|
|
22
|
+
return `linear-gradient(to ${dir}, ${start}, ${middle}, ${end})`;
|
|
23
|
+
}
|
|
24
|
+
case "saturation":
|
|
25
|
+
case "brightness":
|
|
26
|
+
case "red":
|
|
27
|
+
case "green":
|
|
28
|
+
case "blue":
|
|
29
|
+
case "alpha": {
|
|
30
|
+
let start = value.withChannelValue(channel, minValue).toString("css");
|
|
31
|
+
let end = value.withChannelValue(channel, maxValue).toString("css");
|
|
32
|
+
return `linear-gradient(to ${dir}, ${start}, ${end})`;
|
|
33
|
+
}
|
|
34
|
+
default:
|
|
35
|
+
throw new Error("Unknown color channel: " + channel);
|
|
36
|
+
}
|
|
6
37
|
};
|
|
38
|
+
|
|
39
|
+
export { getSliderBgImage };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/color-picker",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.4",
|
|
4
4
|
"description": "Core logic for the color-picker widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -28,15 +28,15 @@
|
|
|
28
28
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@zag-js/core": "0.10.
|
|
32
|
-
"@zag-js/anatomy": "0.10.
|
|
33
|
-
"@zag-js/dom-query": "0.10.
|
|
34
|
-
"@zag-js/dom-event": "0.10.
|
|
35
|
-
"@zag-js/utils": "0.10.
|
|
36
|
-
"@zag-js/color-utils": "0.10.
|
|
37
|
-
"@zag-js/numeric-range": "0.10.
|
|
38
|
-
"@zag-js/text-selection": "0.10.
|
|
39
|
-
"@zag-js/types": "0.10.
|
|
31
|
+
"@zag-js/core": "0.10.4",
|
|
32
|
+
"@zag-js/anatomy": "0.10.4",
|
|
33
|
+
"@zag-js/dom-query": "0.10.4",
|
|
34
|
+
"@zag-js/dom-event": "0.10.4",
|
|
35
|
+
"@zag-js/utils": "0.10.4",
|
|
36
|
+
"@zag-js/color-utils": "0.10.4",
|
|
37
|
+
"@zag-js/numeric-range": "0.10.4",
|
|
38
|
+
"@zag-js/text-selection": "0.10.4",
|
|
39
|
+
"@zag-js/types": "0.10.4"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"clean-package": "2.2.0"
|
|
@@ -53,13 +53,8 @@
|
|
|
53
53
|
"./package.json": "./package.json"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
|
-
"build
|
|
57
|
-
"start": "pnpm build --watch",
|
|
58
|
-
"build": "tsup src --dts",
|
|
59
|
-
"test": "jest --config ../../../jest.config.js --rootDir . --passWithNoTests",
|
|
56
|
+
"build": "vite build -c ../../../vite.config.ts",
|
|
60
57
|
"lint": "eslint src --ext .ts,.tsx",
|
|
61
|
-
"test-ci": "pnpm test --ci --runInBand",
|
|
62
|
-
"test-watch": "pnpm test --watch -u",
|
|
63
58
|
"typecheck": "tsc --noEmit"
|
|
64
59
|
}
|
|
65
60
|
}
|
package/src/color-picker.dom.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ColorChannel } from "@zag-js/color-utils"
|
|
1
|
+
import { type ColorChannel } from "@zag-js/color-utils"
|
|
2
2
|
import { getRelativePoint, type Point } from "@zag-js/dom-event"
|
|
3
3
|
import { createScope, queryAll } from "@zag-js/dom-query"
|
|
4
4
|
import type { MachineContext as Ctx } from "./color-picker.types"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Color, ColorAxes, ColorChannel } from "@zag-js/color-utils"
|
|
1
|
+
import { Color, type ColorAxes, type ColorChannel, type ColorFormat } from "@zag-js/color-utils"
|
|
2
2
|
import type { StateMachine as S } from "@zag-js/core"
|
|
3
3
|
import type { CommonProperties, Context, Orientation, RequiredBy } from "@zag-js/types"
|
|
4
4
|
|
|
@@ -111,3 +111,5 @@ export type MachineState = {
|
|
|
111
111
|
export type State = S.State<MachineContext, MachineState>
|
|
112
112
|
|
|
113
113
|
export type Send = S.Send<S.AnyEventObject>
|
|
114
|
+
|
|
115
|
+
export type { Color, ColorChannel, ColorFormat }
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,9 @@ export { anatomy } from "./color-picker.anatomy"
|
|
|
2
2
|
export { connect } from "./color-picker.connect"
|
|
3
3
|
export { machine } from "./color-picker.machine"
|
|
4
4
|
export type {
|
|
5
|
+
Color,
|
|
5
6
|
ColorAreaProps,
|
|
7
|
+
ColorChannel,
|
|
6
8
|
ColorChannelProps,
|
|
7
9
|
ColorSwatchProps,
|
|
8
10
|
UserDefinedContext as Context,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Color, ColorChannel } from "@zag-js/color-utils"
|
|
2
|
-
import {
|
|
1
|
+
import { Color, type ColorChannel } from "@zag-js/color-utils"
|
|
2
|
+
import { getPercentValue, snapValueToStep } from "@zag-js/numeric-range"
|
|
3
3
|
|
|
4
4
|
export function getChannelDetails(color: Color, xChannel: ColorChannel, yChannel: ColorChannel) {
|
|
5
5
|
const channels = color.getColorSpaceAxes({ xChannel, yChannel })
|
package/dist/chunk-2ERX54SV.mjs
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// src/utils/get-channel-input-value.ts
|
|
2
|
-
function getChannelInputValue(color, channel) {
|
|
3
|
-
switch (channel) {
|
|
4
|
-
case "hex":
|
|
5
|
-
return color.toString("hex");
|
|
6
|
-
case "css":
|
|
7
|
-
return color.toString("css");
|
|
8
|
-
default:
|
|
9
|
-
return color.getChannelValue(channel).toString();
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
function getChannelInputRange(color, channel) {
|
|
13
|
-
switch (channel) {
|
|
14
|
-
case "hex":
|
|
15
|
-
case "css":
|
|
16
|
-
return void 0;
|
|
17
|
-
default:
|
|
18
|
-
return color.getChannelRange(channel);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export {
|
|
23
|
-
getChannelInputValue,
|
|
24
|
-
getChannelInputRange
|
|
25
|
-
};
|
package/dist/chunk-3XH465XT.mjs
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
// src/utils/get-slider-background.ts
|
|
2
|
-
function getSliderBgDirection(orientation, dir) {
|
|
3
|
-
if (orientation === "vertical") {
|
|
4
|
-
return "top";
|
|
5
|
-
} else if (dir === "ltr") {
|
|
6
|
-
return "right";
|
|
7
|
-
} else {
|
|
8
|
-
return "left";
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
var getSliderBgImage = (ctx, props) => {
|
|
12
|
-
const { channel } = props;
|
|
13
|
-
const dir = getSliderBgDirection(props.orientation, ctx.dir);
|
|
14
|
-
const value = ctx.valueAsColor;
|
|
15
|
-
const { minValue, maxValue } = ctx.valueAsColor.getChannelRange(channel);
|
|
16
|
-
switch (channel) {
|
|
17
|
-
case "hue":
|
|
18
|
-
return `linear-gradient(to ${dir}, rgb(255, 0, 0) 0%, rgb(255, 255, 0) 17%, rgb(0, 255, 0) 33%, rgb(0, 255, 255) 50%, rgb(0, 0, 255) 67%, rgb(255, 0, 255) 83%, rgb(255, 0, 0) 100%)`;
|
|
19
|
-
case "lightness": {
|
|
20
|
-
let start = ctx.valueAsColor.withChannelValue(channel, minValue).toString("css");
|
|
21
|
-
let middle = value.withChannelValue(channel, (maxValue - minValue) / 2).toString("css");
|
|
22
|
-
let end = value.withChannelValue(channel, maxValue).toString("css");
|
|
23
|
-
return `linear-gradient(to ${dir}, ${start}, ${middle}, ${end})`;
|
|
24
|
-
}
|
|
25
|
-
case "saturation":
|
|
26
|
-
case "brightness":
|
|
27
|
-
case "red":
|
|
28
|
-
case "green":
|
|
29
|
-
case "blue":
|
|
30
|
-
case "alpha": {
|
|
31
|
-
let start = value.withChannelValue(channel, minValue).toString("css");
|
|
32
|
-
let end = value.withChannelValue(channel, maxValue).toString("css");
|
|
33
|
-
return `linear-gradient(to ${dir}, ${start}, ${end})`;
|
|
34
|
-
}
|
|
35
|
-
default:
|
|
36
|
-
throw new Error("Unknown color channel: " + channel);
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export {
|
|
41
|
-
getSliderBgImage
|
|
42
|
-
};
|