@zag-js/color-picker 0.0.0-dev-20230414151834
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/LICENSE +21 -0
- package/README.md +19 -0
- package/dist/chunk-2ERX54SV.mjs +25 -0
- package/dist/chunk-3XH465XT.mjs +42 -0
- package/dist/chunk-75JXJMB5.mjs +22 -0
- package/dist/chunk-ACSV4TXB.mjs +35 -0
- package/dist/chunk-J3XCPS5T.mjs +365 -0
- package/dist/chunk-JNBNPPMF.mjs +24 -0
- package/dist/chunk-KLLIOTK6.mjs +55 -0
- package/dist/chunk-KO4TBUXB.mjs +74 -0
- package/dist/chunk-OY3B7NXA.mjs +132 -0
- package/dist/chunk-ZBNUATFY.mjs +344 -0
- package/dist/color-picker.anatomy.d.ts +6 -0
- package/dist/color-picker.anatomy.js +47 -0
- package/dist/color-picker.anatomy.mjs +8 -0
- package/dist/color-picker.connect.d.ts +27 -0
- package/dist/color-picker.connect.js +731 -0
- package/dist/color-picker.connect.mjs +14 -0
- package/dist/color-picker.dom.d.ts +62 -0
- package/dist/color-picker.dom.js +59 -0
- package/dist/color-picker.dom.mjs +6 -0
- package/dist/color-picker.machine.d.ts +8 -0
- package/dist/color-picker.machine.js +456 -0
- package/dist/color-picker.machine.mjs +9 -0
- package/dist/color-picker.types.d.ts +88 -0
- package/dist/color-picker.types.js +18 -0
- package/dist/color-picker.types.mjs +0 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +1066 -0
- package/dist/index.mjs +18 -0
- package/dist/utils/generate-format-background.d.ts +68 -0
- package/dist/utils/generate-format-background.js +164 -0
- package/dist/utils/generate-format-background.mjs +22 -0
- package/dist/utils/get-channel-details.d.ts +23 -0
- package/dist/utils/get-channel-details.js +79 -0
- package/dist/utils/get-channel-details.mjs +6 -0
- package/dist/utils/get-channel-display-color.d.ts +5 -0
- package/dist/utils/get-channel-display-color.js +48 -0
- package/dist/utils/get-channel-display-color.mjs +6 -0
- package/dist/utils/get-channel-input-value.d.ts +10 -0
- package/dist/utils/get-channel-input-value.js +50 -0
- package/dist/utils/get-channel-input-value.mjs +8 -0
- package/dist/utils/get-color-area-gradient.d.ts +11 -0
- package/dist/utils/get-color-area-gradient.js +209 -0
- package/dist/utils/get-color-area-gradient.mjs +7 -0
- package/dist/utils/get-slider-background.d.ts +8 -0
- package/dist/utils/get-slider-background.js +66 -0
- package/dist/utils/get-slider-background.mjs +6 -0
- package/package.json +65 -0
|
@@ -0,0 +1,731 @@
|
|
|
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-picker.connect.ts
|
|
21
|
+
var color_picker_connect_exports = {};
|
|
22
|
+
__export(color_picker_connect_exports, {
|
|
23
|
+
connect: () => connect
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(color_picker_connect_exports);
|
|
26
|
+
var import_color_utils2 = require("@zag-js/color-utils");
|
|
27
|
+
var import_dom_event2 = require("@zag-js/dom-event");
|
|
28
|
+
var import_dom_query2 = require("@zag-js/dom-query");
|
|
29
|
+
|
|
30
|
+
// src/color-picker.anatomy.ts
|
|
31
|
+
var import_anatomy = require("@zag-js/anatomy");
|
|
32
|
+
var anatomy = (0, import_anatomy.createAnatomy)("color-picker", [
|
|
33
|
+
"area",
|
|
34
|
+
"areaThumb",
|
|
35
|
+
"areaGradient",
|
|
36
|
+
"channelSliderTrack",
|
|
37
|
+
"channelSliderTrackBg",
|
|
38
|
+
"channelSliderThumb",
|
|
39
|
+
"channelInput",
|
|
40
|
+
"swatch",
|
|
41
|
+
"swatchBg",
|
|
42
|
+
"content",
|
|
43
|
+
"label",
|
|
44
|
+
"eyeDropTrigger"
|
|
45
|
+
]);
|
|
46
|
+
var parts = anatomy.build();
|
|
47
|
+
|
|
48
|
+
// src/color-picker.dom.ts
|
|
49
|
+
var import_dom_event = require("@zag-js/dom-event");
|
|
50
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
51
|
+
var dom = (0, import_dom_query.createScope)({
|
|
52
|
+
getAreaId: (ctx) => `color-picker:${ctx.id}:area`,
|
|
53
|
+
getAreaGradientId: (ctx) => `color-picker:${ctx.id}:area-gradient`,
|
|
54
|
+
getAreaThumbId: (ctx) => `color-picker:${ctx.id}:area-thumb`,
|
|
55
|
+
getChannelSliderTrackId: (ctx, channel) => `color-picker:${ctx.id}:slider-track:${channel}`,
|
|
56
|
+
getChannelInputId: (ctx, channel) => `color-picker:${ctx.id}:input:${channel}`,
|
|
57
|
+
getContentId: (ctx) => `color-picker:${ctx.id}:content`,
|
|
58
|
+
getChannelSliderThumbId: (ctx, channel) => `color-picker:${ctx.id}:thumb:${channel}`,
|
|
59
|
+
getContentEl: (ctx) => dom.queryById(ctx, dom.getContentId(ctx)),
|
|
60
|
+
getAreaThumbEl: (ctx) => dom.queryById(ctx, dom.getAreaThumbId(ctx)),
|
|
61
|
+
getChannelSliderThumbEl: (ctx, channel) => dom.queryById(ctx, dom.getChannelSliderThumbId(ctx, channel)),
|
|
62
|
+
getChannelInputEl: (ctx, channel) => dom.queryById(ctx, dom.getChannelInputId(ctx, channel)),
|
|
63
|
+
getAreaEl: (ctx) => dom.queryById(ctx, dom.getAreaId(ctx)),
|
|
64
|
+
getAreaValueFromPoint(ctx, point) {
|
|
65
|
+
const areaEl = dom.getAreaEl(ctx);
|
|
66
|
+
return (0, import_dom_event.getRelativePointPercent)(point, areaEl);
|
|
67
|
+
},
|
|
68
|
+
getChannelSliderTrackEl: (ctx, channel) => {
|
|
69
|
+
return dom.queryById(ctx, dom.getChannelSliderTrackId(ctx, channel));
|
|
70
|
+
},
|
|
71
|
+
getChannelSliderValueFromPoint(ctx, point, channel) {
|
|
72
|
+
const areaEl = dom.getChannelSliderTrackEl(ctx, channel);
|
|
73
|
+
return (0, import_dom_event.getRelativePointPercent)(point, areaEl);
|
|
74
|
+
},
|
|
75
|
+
getChannelInputEls: (ctx) => {
|
|
76
|
+
return (0, import_dom_query.queryAll)(dom.getContentEl(ctx), "input[data-channel]");
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// src/utils/get-channel-details.ts
|
|
81
|
+
var import_numeric_range = require("@zag-js/numeric-range");
|
|
82
|
+
function getChannelDetails(color, xChannel, yChannel) {
|
|
83
|
+
const channels = color.getColorSpaceAxes({ xChannel, yChannel });
|
|
84
|
+
const xChannelRange = color.getChannelRange(channels.xChannel);
|
|
85
|
+
const yChannelRange = color.getChannelRange(channels.yChannel);
|
|
86
|
+
const { minValue: minValueX, maxValue: maxValueX, step: stepX, pageSize: pageSizeX } = xChannelRange;
|
|
87
|
+
const { minValue: minValueY, maxValue: maxValueY, step: stepY, pageSize: pageSizeY } = yChannelRange;
|
|
88
|
+
const xValue = color.getChannelValue(channels.xChannel);
|
|
89
|
+
const yValue = color.getChannelValue(channels.yChannel);
|
|
90
|
+
return {
|
|
91
|
+
channels,
|
|
92
|
+
xChannelStep: stepX,
|
|
93
|
+
yChannelStep: stepY,
|
|
94
|
+
xChannelPageStep: pageSizeX,
|
|
95
|
+
yChannelPageStep: pageSizeY,
|
|
96
|
+
xValue,
|
|
97
|
+
yValue,
|
|
98
|
+
getThumbPosition() {
|
|
99
|
+
let x = (xValue - minValueX) / (maxValueX - minValueX);
|
|
100
|
+
let y = 1 - (yValue - minValueY) / (maxValueY - minValueY);
|
|
101
|
+
return { x, y };
|
|
102
|
+
},
|
|
103
|
+
incrementX(stepSize) {
|
|
104
|
+
return xValue + stepSize > maxValueX ? maxValueX : (0, import_numeric_range.snapValueToStep)(xValue + stepSize, minValueX, maxValueX, stepX);
|
|
105
|
+
},
|
|
106
|
+
incrementY(stepSize) {
|
|
107
|
+
return yValue + stepSize > maxValueY ? maxValueY : (0, import_numeric_range.snapValueToStep)(yValue + stepSize, minValueY, maxValueY, stepY);
|
|
108
|
+
},
|
|
109
|
+
decrementX(stepSize) {
|
|
110
|
+
return (0, import_numeric_range.snapValueToStep)(xValue - stepSize, minValueX, maxValueX, stepX);
|
|
111
|
+
},
|
|
112
|
+
decrementY(stepSize) {
|
|
113
|
+
return (0, import_numeric_range.snapValueToStep)(yValue - stepSize, minValueY, maxValueY, stepY);
|
|
114
|
+
},
|
|
115
|
+
getColorFromPoint(x, y) {
|
|
116
|
+
let newXValue = (0, import_numeric_range.getPercentValue)(x, minValueX, maxValueX, stepX);
|
|
117
|
+
let newYValue = (0, import_numeric_range.getPercentValue)(1 - y, minValueY, maxValueY, stepY);
|
|
118
|
+
let newColor;
|
|
119
|
+
if (newXValue !== xValue) {
|
|
120
|
+
newXValue = (0, import_numeric_range.snapValueToStep)(newXValue, minValueX, maxValueX, stepX);
|
|
121
|
+
newColor = color.withChannelValue(channels.xChannel, newXValue);
|
|
122
|
+
}
|
|
123
|
+
if (newYValue !== yValue) {
|
|
124
|
+
newYValue = (0, import_numeric_range.snapValueToStep)(newYValue, minValueY, maxValueY, stepY);
|
|
125
|
+
newColor = (newColor || color).withChannelValue(channels.yChannel, newYValue);
|
|
126
|
+
}
|
|
127
|
+
return newColor;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// src/utils/get-channel-display-color.ts
|
|
133
|
+
var import_color_utils = require("@zag-js/color-utils");
|
|
134
|
+
function getChannelDisplayColor(color, channel) {
|
|
135
|
+
switch (channel) {
|
|
136
|
+
case "hue":
|
|
137
|
+
return (0, import_color_utils.parseColor)(`hsl(${color.getChannelValue("hue")}, 100%, 50%)`);
|
|
138
|
+
case "lightness":
|
|
139
|
+
case "brightness":
|
|
140
|
+
case "saturation":
|
|
141
|
+
case "red":
|
|
142
|
+
case "green":
|
|
143
|
+
case "blue":
|
|
144
|
+
return color.withChannelValue("alpha", 1);
|
|
145
|
+
case "alpha": {
|
|
146
|
+
return color;
|
|
147
|
+
}
|
|
148
|
+
default:
|
|
149
|
+
throw new Error("Unknown color channel: " + channel);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// src/utils/get-channel-input-value.ts
|
|
154
|
+
function getChannelInputValue(color, channel) {
|
|
155
|
+
switch (channel) {
|
|
156
|
+
case "hex":
|
|
157
|
+
return color.toString("hex");
|
|
158
|
+
case "css":
|
|
159
|
+
return color.toString("css");
|
|
160
|
+
default:
|
|
161
|
+
return color.getChannelValue(channel).toString();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function getChannelInputRange(color, channel) {
|
|
165
|
+
switch (channel) {
|
|
166
|
+
case "hex":
|
|
167
|
+
case "css":
|
|
168
|
+
return void 0;
|
|
169
|
+
default:
|
|
170
|
+
return color.getChannelRange(channel);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// src/utils/generate-format-background.ts
|
|
175
|
+
var generateRGB_R = (orientation, dir, zValue) => {
|
|
176
|
+
const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`;
|
|
177
|
+
const result = {
|
|
178
|
+
areaStyles: {
|
|
179
|
+
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(${zValue},0,0),rgb(${zValue},255,0))`
|
|
180
|
+
},
|
|
181
|
+
areaGradientStyles: {
|
|
182
|
+
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(${zValue},0,255),rgb(${zValue},255,255))`,
|
|
183
|
+
WebkitMaskImage: maskImage,
|
|
184
|
+
maskImage
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
return result;
|
|
188
|
+
};
|
|
189
|
+
var generateRGB_G = (orientation, dir, zValue) => {
|
|
190
|
+
const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`;
|
|
191
|
+
const result = {
|
|
192
|
+
areaStyles: {
|
|
193
|
+
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,${zValue},0),rgb(255,${zValue},0))`
|
|
194
|
+
},
|
|
195
|
+
areaGradientStyles: {
|
|
196
|
+
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,${zValue},255),rgb(255,${zValue},255))`,
|
|
197
|
+
WebkitMaskImage: maskImage,
|
|
198
|
+
maskImage
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
return result;
|
|
202
|
+
};
|
|
203
|
+
var generateRGB_B = (orientation, dir, zValue) => {
|
|
204
|
+
const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`;
|
|
205
|
+
const result = {
|
|
206
|
+
areaStyles: {
|
|
207
|
+
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,0,${zValue}),rgb(255,0,${zValue}))`
|
|
208
|
+
},
|
|
209
|
+
areaGradientStyles: {
|
|
210
|
+
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,255,${zValue}),rgb(255,255,${zValue}))`,
|
|
211
|
+
WebkitMaskImage: maskImage,
|
|
212
|
+
maskImage
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
return result;
|
|
216
|
+
};
|
|
217
|
+
var generateHSL_H = (orientation, dir, zValue) => {
|
|
218
|
+
const result = {
|
|
219
|
+
areaStyles: {},
|
|
220
|
+
areaGradientStyles: {
|
|
221
|
+
background: [
|
|
222
|
+
`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%)`,
|
|
223
|
+
`linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,50%),hsla(0,0%,50%,0))`,
|
|
224
|
+
`hsl(${zValue}, 100%, 50%)`
|
|
225
|
+
].join(",")
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
return result;
|
|
229
|
+
};
|
|
230
|
+
var generateHSL_S = (orientation, dir, alphaValue) => {
|
|
231
|
+
const result = {
|
|
232
|
+
areaStyles: {},
|
|
233
|
+
areaGradientStyles: {
|
|
234
|
+
background: [
|
|
235
|
+
`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%)`,
|
|
236
|
+
`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}))`,
|
|
237
|
+
"hsl(0, 0%, 50%)"
|
|
238
|
+
].join(",")
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
return result;
|
|
242
|
+
};
|
|
243
|
+
var generateHSL_L = (orientation, dir, zValue) => {
|
|
244
|
+
const result = {
|
|
245
|
+
areaStyles: {},
|
|
246
|
+
areaGradientStyles: {
|
|
247
|
+
backgroundImage: [
|
|
248
|
+
`linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,${zValue}%),hsla(0,0%,${zValue}%,0))`,
|
|
249
|
+
`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}%))`
|
|
250
|
+
].join(",")
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
return result;
|
|
254
|
+
};
|
|
255
|
+
var generateHSB_H = (orientation, dir, zValue) => {
|
|
256
|
+
const result = {
|
|
257
|
+
areaStyles: {},
|
|
258
|
+
areaGradientStyles: {
|
|
259
|
+
background: [
|
|
260
|
+
`linear-gradient(to ${orientation[Number(dir)]},hsl(0,0%,0%),hsla(0,0%,0%,0))`,
|
|
261
|
+
`linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,100%),hsla(0,0%,100%,0))`,
|
|
262
|
+
`hsl(${zValue}, 100%, 50%)`
|
|
263
|
+
].join(",")
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
return result;
|
|
267
|
+
};
|
|
268
|
+
var generateHSB_S = (orientation, dir, alphaValue) => {
|
|
269
|
+
const result = {
|
|
270
|
+
areaStyles: {},
|
|
271
|
+
areaGradientStyles: {
|
|
272
|
+
background: [
|
|
273
|
+
`linear-gradient(to ${orientation[Number(!dir)]},hsla(0,0%,0%,${alphaValue}),hsla(0,0%,0%,0))`,
|
|
274
|
+
`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}))`,
|
|
275
|
+
`linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,0%),hsl(0,0%,100%))`
|
|
276
|
+
].join(",")
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
return result;
|
|
280
|
+
};
|
|
281
|
+
var generateHSB_B = (orientation, dir, alphaValue) => {
|
|
282
|
+
const result = {
|
|
283
|
+
areaStyles: {},
|
|
284
|
+
areaGradientStyles: {
|
|
285
|
+
background: [
|
|
286
|
+
`linear-gradient(to ${orientation[Number(!dir)]},hsla(0,0%,100%,${alphaValue}),hsla(0,0%,100%,0))`,
|
|
287
|
+
`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}))`,
|
|
288
|
+
"#000"
|
|
289
|
+
].join(",")
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
return result;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
// src/utils/get-color-area-gradient.ts
|
|
296
|
+
function getColorAreaGradient(ctx, xChannel, yChannel) {
|
|
297
|
+
const value = ctx.valueAsColor;
|
|
298
|
+
const { zChannel } = value.getColorSpaceAxes({ xChannel, yChannel });
|
|
299
|
+
const zValue = value.getChannelValue(zChannel);
|
|
300
|
+
const { minValue: zMin, maxValue: zMax } = value.getChannelRange(zChannel);
|
|
301
|
+
const orientation = ["top", ctx.dir === "rtl" ? "left" : "right"];
|
|
302
|
+
let dir = false;
|
|
303
|
+
let background = { areaStyles: {}, areaGradientStyles: {} };
|
|
304
|
+
let alphaValue = (zValue - zMin) / (zMax - zMin);
|
|
305
|
+
let isHSL = value.getColorSpace() === "hsl";
|
|
306
|
+
switch (zChannel) {
|
|
307
|
+
case "red": {
|
|
308
|
+
dir = xChannel === "green";
|
|
309
|
+
background = generateRGB_R(orientation, dir, zValue);
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
case "green": {
|
|
313
|
+
dir = xChannel === "red";
|
|
314
|
+
background = generateRGB_G(orientation, dir, zValue);
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
case "blue": {
|
|
318
|
+
dir = xChannel === "red";
|
|
319
|
+
background = generateRGB_B(orientation, dir, zValue);
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
case "hue": {
|
|
323
|
+
dir = xChannel !== "saturation";
|
|
324
|
+
if (isHSL) {
|
|
325
|
+
background = generateHSL_H(orientation, dir, zValue);
|
|
326
|
+
} else {
|
|
327
|
+
background = generateHSB_H(orientation, dir, zValue);
|
|
328
|
+
}
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
case "saturation": {
|
|
332
|
+
dir = xChannel === "hue";
|
|
333
|
+
if (isHSL) {
|
|
334
|
+
background = generateHSL_S(orientation, dir, alphaValue);
|
|
335
|
+
} else {
|
|
336
|
+
background = generateHSB_S(orientation, dir, alphaValue);
|
|
337
|
+
}
|
|
338
|
+
break;
|
|
339
|
+
}
|
|
340
|
+
case "brightness": {
|
|
341
|
+
dir = xChannel === "hue";
|
|
342
|
+
background = generateHSB_B(orientation, dir, alphaValue);
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
case "lightness": {
|
|
346
|
+
dir = xChannel === "hue";
|
|
347
|
+
background = generateHSL_L(orientation, dir, zValue);
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return background;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// src/utils/get-slider-background.ts
|
|
355
|
+
function getSliderBgDirection(orientation, dir) {
|
|
356
|
+
if (orientation === "vertical") {
|
|
357
|
+
return "top";
|
|
358
|
+
} else if (dir === "ltr") {
|
|
359
|
+
return "right";
|
|
360
|
+
} else {
|
|
361
|
+
return "left";
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
var getSliderBgImage = (ctx, props) => {
|
|
365
|
+
const { channel } = props;
|
|
366
|
+
const dir = getSliderBgDirection(props.orientation, ctx.dir);
|
|
367
|
+
const value = ctx.valueAsColor;
|
|
368
|
+
const { minValue, maxValue } = ctx.valueAsColor.getChannelRange(channel);
|
|
369
|
+
switch (channel) {
|
|
370
|
+
case "hue":
|
|
371
|
+
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%)`;
|
|
372
|
+
case "lightness": {
|
|
373
|
+
let start = ctx.valueAsColor.withChannelValue(channel, minValue).toString("css");
|
|
374
|
+
let middle = value.withChannelValue(channel, (maxValue - minValue) / 2).toString("css");
|
|
375
|
+
let end = value.withChannelValue(channel, maxValue).toString("css");
|
|
376
|
+
return `linear-gradient(to ${dir}, ${start}, ${middle}, ${end})`;
|
|
377
|
+
}
|
|
378
|
+
case "saturation":
|
|
379
|
+
case "brightness":
|
|
380
|
+
case "red":
|
|
381
|
+
case "green":
|
|
382
|
+
case "blue":
|
|
383
|
+
case "alpha": {
|
|
384
|
+
let start = value.withChannelValue(channel, minValue).toString("css");
|
|
385
|
+
let end = value.withChannelValue(channel, maxValue).toString("css");
|
|
386
|
+
return `linear-gradient(to ${dir}, ${start}, ${end})`;
|
|
387
|
+
}
|
|
388
|
+
default:
|
|
389
|
+
throw new Error("Unknown color channel: " + channel);
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
// src/color-picker.connect.ts
|
|
394
|
+
function connect(state, send, normalize) {
|
|
395
|
+
const valueAsColor = state.context.valueAsColor;
|
|
396
|
+
const isDisabled = state.context.disabled;
|
|
397
|
+
const isInteractive = state.context.isInteractive;
|
|
398
|
+
const isDragging = state.matches("dragging");
|
|
399
|
+
const channels = valueAsColor.getColorChannels();
|
|
400
|
+
return {
|
|
401
|
+
isDragging,
|
|
402
|
+
value: state.context.value,
|
|
403
|
+
valueAsColor,
|
|
404
|
+
channels,
|
|
405
|
+
setColor(value) {
|
|
406
|
+
send({ type: "VALUE.SET", value: (0, import_color_utils2.normalizeColor)(value), src: "set-color" });
|
|
407
|
+
},
|
|
408
|
+
setChannelValue(channel, value) {
|
|
409
|
+
const color = valueAsColor.withChannelValue(channel, value);
|
|
410
|
+
send({ type: "VALUE.SET", value: color, src: "set-channel" });
|
|
411
|
+
},
|
|
412
|
+
setFormat(format) {
|
|
413
|
+
const value = valueAsColor.toFormat(format);
|
|
414
|
+
send({ type: "VALUE.SET", value, src: "set-format" });
|
|
415
|
+
},
|
|
416
|
+
contentProps: normalize.element({
|
|
417
|
+
...parts.content.attrs,
|
|
418
|
+
id: dom.getContentId(state.context)
|
|
419
|
+
}),
|
|
420
|
+
getAreaProps(props) {
|
|
421
|
+
const { xChannel, yChannel } = props;
|
|
422
|
+
const { areaStyles } = getColorAreaGradient(state.context, xChannel, yChannel);
|
|
423
|
+
return normalize.element({
|
|
424
|
+
...parts.area.attrs,
|
|
425
|
+
id: dom.getAreaId(state.context),
|
|
426
|
+
role: "group",
|
|
427
|
+
onPointerDown(event) {
|
|
428
|
+
if (!isInteractive)
|
|
429
|
+
return;
|
|
430
|
+
const evt = (0, import_dom_event2.getNativeEvent)(event);
|
|
431
|
+
if (!(0, import_dom_event2.isLeftClick)(evt) || (0, import_dom_event2.isModifiedEvent)(evt))
|
|
432
|
+
return;
|
|
433
|
+
const point = { x: evt.clientX, y: evt.clientY };
|
|
434
|
+
const channel = { xChannel, yChannel };
|
|
435
|
+
send({ type: "AREA.POINTER_DOWN", point, channel, id: "area" });
|
|
436
|
+
},
|
|
437
|
+
style: {
|
|
438
|
+
position: "relative",
|
|
439
|
+
touchAction: "none",
|
|
440
|
+
forcedColorAdjust: "none",
|
|
441
|
+
...areaStyles
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
},
|
|
445
|
+
getAreaGradientProps(props) {
|
|
446
|
+
const { xChannel, yChannel } = props;
|
|
447
|
+
const { areaGradientStyles } = getColorAreaGradient(state.context, xChannel, yChannel);
|
|
448
|
+
return normalize.element({
|
|
449
|
+
...parts.areaGradient.attrs,
|
|
450
|
+
id: dom.getAreaGradientId(state.context),
|
|
451
|
+
style: {
|
|
452
|
+
position: "relative",
|
|
453
|
+
touchAction: "none",
|
|
454
|
+
forcedColorAdjust: "none",
|
|
455
|
+
...areaGradientStyles
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
},
|
|
459
|
+
getAreaThumbProps(props) {
|
|
460
|
+
const { xChannel, yChannel } = props;
|
|
461
|
+
const { getThumbPosition } = getChannelDetails(valueAsColor, xChannel, yChannel);
|
|
462
|
+
const { x, y } = getThumbPosition();
|
|
463
|
+
const channel = { xChannel, yChannel };
|
|
464
|
+
return normalize.element({
|
|
465
|
+
...parts.areaThumb.attrs,
|
|
466
|
+
id: dom.getAreaThumbId(state.context),
|
|
467
|
+
tabIndex: isDisabled ? void 0 : 0,
|
|
468
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
469
|
+
role: "presentation",
|
|
470
|
+
style: {
|
|
471
|
+
position: "absolute",
|
|
472
|
+
left: `${x * 100}%`,
|
|
473
|
+
top: `${y * 100}%`,
|
|
474
|
+
transform: "translate(-50%, -50%)",
|
|
475
|
+
touchAction: "none",
|
|
476
|
+
forcedColorAdjust: "none",
|
|
477
|
+
background: valueAsColor.withChannelValue("alpha", 1).toString("css")
|
|
478
|
+
},
|
|
479
|
+
onBlur() {
|
|
480
|
+
send("AREA.BLUR");
|
|
481
|
+
},
|
|
482
|
+
onKeyDown(event) {
|
|
483
|
+
if (!isInteractive)
|
|
484
|
+
return;
|
|
485
|
+
const step = (0, import_dom_event2.getEventStep)(event);
|
|
486
|
+
const keyMap = {
|
|
487
|
+
ArrowUp() {
|
|
488
|
+
send({ type: "AREA.ARROW_UP", channel, step });
|
|
489
|
+
},
|
|
490
|
+
ArrowDown() {
|
|
491
|
+
send({ type: "AREA.ARROW_DOWN", channel, step });
|
|
492
|
+
},
|
|
493
|
+
ArrowLeft() {
|
|
494
|
+
send({ type: "AREA.ARROW_LEFT", channel, step });
|
|
495
|
+
},
|
|
496
|
+
ArrowRight() {
|
|
497
|
+
send({ type: "AREA.ARROW_RIGHT", channel, step });
|
|
498
|
+
},
|
|
499
|
+
PageUp() {
|
|
500
|
+
send({ type: "AREA.PAGE_UP", channel, step });
|
|
501
|
+
},
|
|
502
|
+
PageDown() {
|
|
503
|
+
send({ type: "AREA.PAGE_DOWN", channel, step });
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
const exec = keyMap[(0, import_dom_event2.getEventKey)(event, state.context)];
|
|
507
|
+
if (exec) {
|
|
508
|
+
exec(event);
|
|
509
|
+
event.preventDefault();
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
},
|
|
514
|
+
getChannelSliderTrackProps(props) {
|
|
515
|
+
const { orientation = "horizontal", channel } = props;
|
|
516
|
+
return normalize.element({
|
|
517
|
+
...parts.channelSliderTrack.attrs,
|
|
518
|
+
id: dom.getChannelSliderTrackId(state.context, channel),
|
|
519
|
+
role: "group",
|
|
520
|
+
"data-channel": channel,
|
|
521
|
+
"data-orientation": orientation,
|
|
522
|
+
onPointerDown(event) {
|
|
523
|
+
if (!isInteractive)
|
|
524
|
+
return;
|
|
525
|
+
const evt = (0, import_dom_event2.getNativeEvent)(event);
|
|
526
|
+
if (!(0, import_dom_event2.isLeftClick)(evt) || (0, import_dom_event2.isModifiedEvent)(evt))
|
|
527
|
+
return;
|
|
528
|
+
const point = { x: evt.clientX, y: evt.clientY };
|
|
529
|
+
send({ type: "CHANNEL_SLIDER.POINTER_DOWN", channel, point, id: channel, orientation });
|
|
530
|
+
},
|
|
531
|
+
style: {
|
|
532
|
+
position: "relative",
|
|
533
|
+
touchAction: "none",
|
|
534
|
+
forcedColorAdjust: "none",
|
|
535
|
+
backgroundImage: getSliderBgImage(state.context, { orientation, channel })
|
|
536
|
+
}
|
|
537
|
+
});
|
|
538
|
+
},
|
|
539
|
+
getChannelSliderBackgroundProps(props) {
|
|
540
|
+
const { orientation = "horizontal", channel } = props;
|
|
541
|
+
return normalize.element({
|
|
542
|
+
...parts.channelSliderTrackBg.attrs,
|
|
543
|
+
"data-orientation": orientation,
|
|
544
|
+
"data-channel": channel,
|
|
545
|
+
style: {
|
|
546
|
+
position: "absolute",
|
|
547
|
+
backgroundColor: "#fff",
|
|
548
|
+
backgroundImage: [
|
|
549
|
+
"linear-gradient(-45deg,#0000 75.5%,#bcbcbc 75.5%)",
|
|
550
|
+
"linear-gradient(45deg,#0000 75.5%,#bcbcbc 75.5%)",
|
|
551
|
+
"linear-gradient(-45deg,#bcbcbc 25.5%,#0000 25.5%)",
|
|
552
|
+
"linear-gradient(45deg,#bcbcbc 25.5%,#0000 25.5%)"
|
|
553
|
+
].join(","),
|
|
554
|
+
backgroundSize: "16px 16px",
|
|
555
|
+
backgroundPosition: "-2px -2px,-2px 6px,6px -10px,-10px -2px",
|
|
556
|
+
inset: 0,
|
|
557
|
+
zIndex: -1
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
},
|
|
561
|
+
getChannelSliderThumbProps(props) {
|
|
562
|
+
const { orientation = "horizontal", channel } = props;
|
|
563
|
+
const { minValue, maxValue, step: stepValue } = valueAsColor.getChannelRange(channel);
|
|
564
|
+
const channelValue = valueAsColor.getChannelValue(channel);
|
|
565
|
+
const offset = (channelValue - minValue) / (maxValue - minValue);
|
|
566
|
+
const placementStyles = orientation === "horizontal" ? { left: `${offset * 100}%`, top: "50%" } : { top: `${offset * 100}%`, left: "50%" };
|
|
567
|
+
return normalize.element({
|
|
568
|
+
...parts.channelSliderThumb.attrs,
|
|
569
|
+
id: dom.getChannelSliderThumbId(state.context, channel),
|
|
570
|
+
role: "slider",
|
|
571
|
+
"aria-label": channel,
|
|
572
|
+
tabIndex: isDisabled ? void 0 : 0,
|
|
573
|
+
"data-channel": channel,
|
|
574
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
575
|
+
"data-orientation": orientation,
|
|
576
|
+
"aria-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
577
|
+
"aria-orientation": orientation,
|
|
578
|
+
"aria-valuemax": maxValue,
|
|
579
|
+
"aria-valuemin": minValue,
|
|
580
|
+
"aria-valuenow": channelValue,
|
|
581
|
+
style: {
|
|
582
|
+
forcedColorAdjust: "none",
|
|
583
|
+
position: "absolute",
|
|
584
|
+
background: getChannelDisplayColor(valueAsColor, channel).toString("css"),
|
|
585
|
+
...placementStyles
|
|
586
|
+
},
|
|
587
|
+
onFocus() {
|
|
588
|
+
if (!isInteractive)
|
|
589
|
+
return;
|
|
590
|
+
send({ type: "CHANNEL_SLIDER.FOCUS", channel });
|
|
591
|
+
},
|
|
592
|
+
onBlur() {
|
|
593
|
+
if (!isInteractive)
|
|
594
|
+
return;
|
|
595
|
+
send({ type: "CHANNEL_SLIDER.BLUR", channel });
|
|
596
|
+
},
|
|
597
|
+
onKeyDown(event) {
|
|
598
|
+
if (!isInteractive)
|
|
599
|
+
return;
|
|
600
|
+
const step = (0, import_dom_event2.getEventStep)(event) * stepValue;
|
|
601
|
+
const keyMap = {
|
|
602
|
+
ArrowUp() {
|
|
603
|
+
send({ type: "CHANNEL_SLIDER.ARROW_UP", channel, step });
|
|
604
|
+
},
|
|
605
|
+
ArrowDown() {
|
|
606
|
+
send({ type: "CHANNEL_SLIDER.ARROW_DOWN", channel, step });
|
|
607
|
+
},
|
|
608
|
+
ArrowLeft() {
|
|
609
|
+
send({ type: "CHANNEL_SLIDER.ARROW_LEFT", channel, step });
|
|
610
|
+
},
|
|
611
|
+
ArrowRight() {
|
|
612
|
+
send({ type: "CHANNEL_SLIDER.ARROW_RIGHT", channel, step });
|
|
613
|
+
},
|
|
614
|
+
PageUp() {
|
|
615
|
+
send({ type: "CHANNEL_SLIDER.PAGE_UP", channel });
|
|
616
|
+
},
|
|
617
|
+
PageDown() {
|
|
618
|
+
send({ type: "CHANNEL_SLIDER.PAGE_DOWN", channel });
|
|
619
|
+
},
|
|
620
|
+
Home() {
|
|
621
|
+
send({ type: "CHANNEL_SLIDER.HOME", channel });
|
|
622
|
+
},
|
|
623
|
+
End() {
|
|
624
|
+
send({ type: "CHANNEL_SLIDER.END", channel });
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
const exec = keyMap[(0, import_dom_event2.getEventKey)(event, state.context)];
|
|
628
|
+
if (exec) {
|
|
629
|
+
exec(event);
|
|
630
|
+
event.preventDefault();
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
});
|
|
634
|
+
},
|
|
635
|
+
getChannelInputProps(props) {
|
|
636
|
+
const { channel } = props;
|
|
637
|
+
const isTextField = channel === "hex" || channel === "css";
|
|
638
|
+
const range = getChannelInputRange(valueAsColor, channel);
|
|
639
|
+
return normalize.input({
|
|
640
|
+
...parts.channelInput.attrs,
|
|
641
|
+
type: isTextField ? "text" : "number",
|
|
642
|
+
"data-channel": channel,
|
|
643
|
+
"aria-label": channel,
|
|
644
|
+
disabled: isDisabled,
|
|
645
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
646
|
+
readOnly: state.context.readOnly,
|
|
647
|
+
id: dom.getChannelInputId(state.context, channel),
|
|
648
|
+
defaultValue: getChannelInputValue(valueAsColor, channel),
|
|
649
|
+
min: range?.minValue,
|
|
650
|
+
max: range?.maxValue,
|
|
651
|
+
step: range?.step,
|
|
652
|
+
onFocus() {
|
|
653
|
+
send({ type: "CHANNEL_INPUT.FOCUS", channel });
|
|
654
|
+
},
|
|
655
|
+
onChange(event) {
|
|
656
|
+
if (isTextField)
|
|
657
|
+
return;
|
|
658
|
+
const value = event.currentTarget.value;
|
|
659
|
+
send({ type: "CHANNEL_INPUT.CHANGE", channel, value, isTextField });
|
|
660
|
+
},
|
|
661
|
+
onBlur(event) {
|
|
662
|
+
const value = event.currentTarget.value;
|
|
663
|
+
send({ type: "CHANNEL_INPUT.BLUR", channel, value, isTextField });
|
|
664
|
+
},
|
|
665
|
+
onKeyDown(event) {
|
|
666
|
+
if (!isTextField)
|
|
667
|
+
return;
|
|
668
|
+
if (event.key === "Enter") {
|
|
669
|
+
const value = event.currentTarget.value;
|
|
670
|
+
send({ type: "CHANNEL_INPUT.CHANGE", channel, value, isTextField });
|
|
671
|
+
}
|
|
672
|
+
},
|
|
673
|
+
style: {
|
|
674
|
+
appearance: "none",
|
|
675
|
+
WebkitAppearance: "none",
|
|
676
|
+
MozAppearance: "textfield"
|
|
677
|
+
}
|
|
678
|
+
});
|
|
679
|
+
},
|
|
680
|
+
eyeDropperTriggerProps: normalize.button({
|
|
681
|
+
...parts.eyeDropTrigger.attrs,
|
|
682
|
+
onClick() {
|
|
683
|
+
send("EYEDROPPER.CLICK");
|
|
684
|
+
}
|
|
685
|
+
}),
|
|
686
|
+
getSwatchBackgroundProps(props) {
|
|
687
|
+
const { value } = props;
|
|
688
|
+
const alpha = (0, import_color_utils2.normalizeColor)(value).getChannelValue("alpha");
|
|
689
|
+
return normalize.element({
|
|
690
|
+
...parts.swatchBg.attrs,
|
|
691
|
+
"data-alpha": alpha,
|
|
692
|
+
style: {
|
|
693
|
+
width: "100%",
|
|
694
|
+
height: "100%",
|
|
695
|
+
background: "#fff",
|
|
696
|
+
backgroundImage: [
|
|
697
|
+
"linear-gradient(-45deg,#0000 75.5%,#bcbcbc 75.5%)",
|
|
698
|
+
"linear-gradient(45deg,#0000 75.5%,#bcbcbc 75.5%)",
|
|
699
|
+
"linear-gradient(-45deg,#bcbcbc 25.5%,#0000 25.5%)",
|
|
700
|
+
"linear-gradient(45deg,#bcbcbc 25.5%,#0000 25.5%)"
|
|
701
|
+
].join(","),
|
|
702
|
+
backgroundPosition: "-2px -2px,-2px 6px,6px -10px,-10px -2px",
|
|
703
|
+
backgroundSize: "16px 16px",
|
|
704
|
+
position: "absolute",
|
|
705
|
+
inset: "0px",
|
|
706
|
+
zIndex: -1
|
|
707
|
+
}
|
|
708
|
+
});
|
|
709
|
+
},
|
|
710
|
+
getSwatchProps(props) {
|
|
711
|
+
const { value, readOnly } = props;
|
|
712
|
+
const color = (0, import_color_utils2.normalizeColor)(value).toFormat(valueAsColor.getColorSpace());
|
|
713
|
+
return normalize.element({
|
|
714
|
+
...parts.swatch.attrs,
|
|
715
|
+
onClick() {
|
|
716
|
+
if (readOnly)
|
|
717
|
+
return;
|
|
718
|
+
send({ type: "VALUE.SET", value: color });
|
|
719
|
+
},
|
|
720
|
+
style: {
|
|
721
|
+
position: "relative",
|
|
722
|
+
background: color.toString("css")
|
|
723
|
+
}
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
729
|
+
0 && (module.exports = {
|
|
730
|
+
connect
|
|
731
|
+
});
|