@zag-js/color-picker 0.10.4 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +150 -0
- package/dist/index.d.ts +150 -4
- package/dist/index.js +1086 -8
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1069 -3
- package/dist/index.mjs.map +1 -0
- package/package.json +11 -11
- package/dist/color-picker.anatomy.d.ts +0 -3
- package/dist/color-picker.anatomy.js +0 -24
- package/dist/color-picker.anatomy.mjs +0 -19
- package/dist/color-picker.connect.d.ts +0 -44
- package/dist/color-picker.connect.js +0 -372
- package/dist/color-picker.connect.mjs +0 -368
- package/dist/color-picker.dom.d.ts +0 -46
- package/dist/color-picker.dom.js +0 -37
- package/dist/color-picker.dom.mjs +0 -33
- package/dist/color-picker.machine.d.ts +0 -3
- package/dist/color-picker.machine.js +0 -340
- package/dist/color-picker.machine.mjs +0 -336
- package/dist/color-picker.types.d.ts +0 -99
- package/dist/utils/generate-format-background.d.ts +0 -66
- package/dist/utils/generate-format-background.js +0 -133
- package/dist/utils/generate-format-background.mjs +0 -121
- package/dist/utils/get-channel-details.d.ts +0 -19
- package/dist/utils/get-channel-details.js +0 -57
- package/dist/utils/get-channel-details.mjs +0 -53
- package/dist/utils/get-channel-display-color.d.ts +0 -3
- package/dist/utils/get-channel-display-color.js +0 -26
- package/dist/utils/get-channel-display-color.mjs +0 -22
- package/dist/utils/get-channel-input-value.d.ts +0 -5
- package/dist/utils/get-channel-input-value.js +0 -26
- package/dist/utils/get-channel-input-value.mjs +0 -21
- package/dist/utils/get-color-area-gradient.d.ts +0 -7
- package/dist/utils/get-color-area-gradient.js +0 -65
- package/dist/utils/get-color-area-gradient.mjs +0 -61
- package/dist/utils/get-slider-background.d.ts +0 -2
- package/dist/utils/get-slider-background.js +0 -43
- package/dist/utils/get-slider-background.mjs +0 -39
package/dist/index.js
CHANGED
|
@@ -1,13 +1,1091 @@
|
|
|
1
|
-
|
|
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);
|
|
2
19
|
|
|
3
|
-
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
anatomy: () => anatomy,
|
|
24
|
+
connect: () => connect,
|
|
25
|
+
machine: () => machine
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(src_exports);
|
|
4
28
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
29
|
+
// src/color-picker.anatomy.ts
|
|
30
|
+
var import_anatomy = require("@zag-js/anatomy");
|
|
31
|
+
var anatomy = (0, import_anatomy.createAnatomy)("color-picker", [
|
|
32
|
+
"area",
|
|
33
|
+
"areaThumb",
|
|
34
|
+
"areaGradient",
|
|
35
|
+
"channelSliderTrack",
|
|
36
|
+
"channelSliderTrackBg",
|
|
37
|
+
"channelSliderThumb",
|
|
38
|
+
"channelInput",
|
|
39
|
+
"swatch",
|
|
40
|
+
"swatchBg",
|
|
41
|
+
"content",
|
|
42
|
+
"label",
|
|
43
|
+
"eyeDropTrigger"
|
|
44
|
+
]);
|
|
45
|
+
var parts = anatomy.build();
|
|
8
46
|
|
|
47
|
+
// src/color-picker.connect.ts
|
|
48
|
+
var import_color_utils2 = require("@zag-js/color-utils");
|
|
49
|
+
var import_dom_event2 = require("@zag-js/dom-event");
|
|
50
|
+
var import_dom_query2 = require("@zag-js/dom-query");
|
|
9
51
|
|
|
52
|
+
// src/color-picker.dom.ts
|
|
53
|
+
var import_dom_event = require("@zag-js/dom-event");
|
|
54
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
55
|
+
var dom = (0, import_dom_query.createScope)({
|
|
56
|
+
getContentId: (ctx) => ctx.ids?.content ?? `color-picker:${ctx.id}:content`,
|
|
57
|
+
getAreaId: (ctx) => ctx.ids?.area ?? `color-picker:${ctx.id}:area`,
|
|
58
|
+
getAreaGradientId: (ctx) => ctx.ids?.areaGradient ?? `color-picker:${ctx.id}:area-gradient`,
|
|
59
|
+
getAreaThumbId: (ctx) => ctx.ids?.areaThumb ?? `color-picker:${ctx.id}:area-thumb`,
|
|
60
|
+
getChannelSliderTrackId: (ctx, channel) => ctx.ids?.channelSliderTrack?.(channel) ?? `color-picker:${ctx.id}:slider-track:${channel}`,
|
|
61
|
+
getChannelInputId: (ctx, channel) => ctx.ids?.channelInput?.(channel) ?? `color-picker:${ctx.id}:input:${channel}`,
|
|
62
|
+
getChannelSliderThumbId: (ctx, channel) => ctx.ids?.channelSliderThumb?.(channel) ?? `color-picker:${ctx.id}:slider-thumb:${channel}`,
|
|
63
|
+
getContentEl: (ctx) => dom.queryById(ctx, dom.getContentId(ctx)),
|
|
64
|
+
getAreaThumbEl: (ctx) => dom.queryById(ctx, dom.getAreaThumbId(ctx)),
|
|
65
|
+
getChannelSliderThumbEl: (ctx, channel) => dom.queryById(ctx, dom.getChannelSliderThumbId(ctx, channel)),
|
|
66
|
+
getChannelInputEl: (ctx, channel) => dom.queryById(ctx, dom.getChannelInputId(ctx, channel)),
|
|
67
|
+
getAreaEl: (ctx) => dom.queryById(ctx, dom.getAreaId(ctx)),
|
|
68
|
+
getAreaValueFromPoint(ctx, point) {
|
|
69
|
+
const { percent } = (0, import_dom_event.getRelativePoint)(point, dom.getAreaEl(ctx));
|
|
70
|
+
return percent;
|
|
71
|
+
},
|
|
72
|
+
getChannelSliderTrackEl: (ctx, channel) => {
|
|
73
|
+
return dom.queryById(ctx, dom.getChannelSliderTrackId(ctx, channel));
|
|
74
|
+
},
|
|
75
|
+
getChannelSliderValueFromPoint(ctx, point, channel) {
|
|
76
|
+
const { percent } = (0, import_dom_event.getRelativePoint)(point, dom.getChannelSliderTrackEl(ctx, channel));
|
|
77
|
+
return percent;
|
|
78
|
+
},
|
|
79
|
+
getChannelInputEls: (ctx) => {
|
|
80
|
+
return (0, import_dom_query.queryAll)(dom.getContentEl(ctx), "input[data-channel]");
|
|
81
|
+
}
|
|
82
|
+
});
|
|
10
83
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
84
|
+
// src/utils/get-channel-details.ts
|
|
85
|
+
var import_numeric_range = require("@zag-js/numeric-range");
|
|
86
|
+
function getChannelDetails(color, xChannel, yChannel) {
|
|
87
|
+
const channels = color.getColorSpaceAxes({ xChannel, yChannel });
|
|
88
|
+
const xChannelRange = color.getChannelRange(channels.xChannel);
|
|
89
|
+
const yChannelRange = color.getChannelRange(channels.yChannel);
|
|
90
|
+
const { minValue: minValueX, maxValue: maxValueX, step: stepX, pageSize: pageSizeX } = xChannelRange;
|
|
91
|
+
const { minValue: minValueY, maxValue: maxValueY, step: stepY, pageSize: pageSizeY } = yChannelRange;
|
|
92
|
+
const xValue = color.getChannelValue(channels.xChannel);
|
|
93
|
+
const yValue = color.getChannelValue(channels.yChannel);
|
|
94
|
+
return {
|
|
95
|
+
channels,
|
|
96
|
+
xChannelStep: stepX,
|
|
97
|
+
yChannelStep: stepY,
|
|
98
|
+
xChannelPageStep: pageSizeX,
|
|
99
|
+
yChannelPageStep: pageSizeY,
|
|
100
|
+
xValue,
|
|
101
|
+
yValue,
|
|
102
|
+
getThumbPosition() {
|
|
103
|
+
let x = (xValue - minValueX) / (maxValueX - minValueX);
|
|
104
|
+
let y = 1 - (yValue - minValueY) / (maxValueY - minValueY);
|
|
105
|
+
return { x, y };
|
|
106
|
+
},
|
|
107
|
+
incrementX(stepSize) {
|
|
108
|
+
return xValue + stepSize > maxValueX ? maxValueX : (0, import_numeric_range.snapValueToStep)(xValue + stepSize, minValueX, maxValueX, stepX);
|
|
109
|
+
},
|
|
110
|
+
incrementY(stepSize) {
|
|
111
|
+
return yValue + stepSize > maxValueY ? maxValueY : (0, import_numeric_range.snapValueToStep)(yValue + stepSize, minValueY, maxValueY, stepY);
|
|
112
|
+
},
|
|
113
|
+
decrementX(stepSize) {
|
|
114
|
+
return (0, import_numeric_range.snapValueToStep)(xValue - stepSize, minValueX, maxValueX, stepX);
|
|
115
|
+
},
|
|
116
|
+
decrementY(stepSize) {
|
|
117
|
+
return (0, import_numeric_range.snapValueToStep)(yValue - stepSize, minValueY, maxValueY, stepY);
|
|
118
|
+
},
|
|
119
|
+
getColorFromPoint(x, y) {
|
|
120
|
+
let newXValue = (0, import_numeric_range.getPercentValue)(x, minValueX, maxValueX, stepX);
|
|
121
|
+
let newYValue = (0, import_numeric_range.getPercentValue)(1 - y, minValueY, maxValueY, stepY);
|
|
122
|
+
let newColor;
|
|
123
|
+
if (newXValue !== xValue) {
|
|
124
|
+
newXValue = (0, import_numeric_range.snapValueToStep)(newXValue, minValueX, maxValueX, stepX);
|
|
125
|
+
newColor = color.withChannelValue(channels.xChannel, newXValue);
|
|
126
|
+
}
|
|
127
|
+
if (newYValue !== yValue) {
|
|
128
|
+
newYValue = (0, import_numeric_range.snapValueToStep)(newYValue, minValueY, maxValueY, stepY);
|
|
129
|
+
newColor = (newColor || color).withChannelValue(channels.yChannel, newYValue);
|
|
130
|
+
}
|
|
131
|
+
return newColor;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// src/utils/get-channel-display-color.ts
|
|
137
|
+
var import_color_utils = require("@zag-js/color-utils");
|
|
138
|
+
function getChannelDisplayColor(color, channel) {
|
|
139
|
+
switch (channel) {
|
|
140
|
+
case "hue":
|
|
141
|
+
return (0, import_color_utils.parseColor)(`hsl(${color.getChannelValue("hue")}, 100%, 50%)`);
|
|
142
|
+
case "lightness":
|
|
143
|
+
case "brightness":
|
|
144
|
+
case "saturation":
|
|
145
|
+
case "red":
|
|
146
|
+
case "green":
|
|
147
|
+
case "blue":
|
|
148
|
+
return color.withChannelValue("alpha", 1);
|
|
149
|
+
case "alpha": {
|
|
150
|
+
return color;
|
|
151
|
+
}
|
|
152
|
+
default:
|
|
153
|
+
throw new Error("Unknown color channel: " + channel);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// src/utils/get-channel-input-value.ts
|
|
158
|
+
function getChannelInputValue(color, channel) {
|
|
159
|
+
switch (channel) {
|
|
160
|
+
case "hex":
|
|
161
|
+
return color.toString("hex");
|
|
162
|
+
case "css":
|
|
163
|
+
return color.toString("css");
|
|
164
|
+
default:
|
|
165
|
+
return color.getChannelValue(channel).toString();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function getChannelInputRange(color, channel) {
|
|
169
|
+
switch (channel) {
|
|
170
|
+
case "hex":
|
|
171
|
+
case "css":
|
|
172
|
+
return void 0;
|
|
173
|
+
default:
|
|
174
|
+
return color.getChannelRange(channel);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// src/utils/generate-format-background.ts
|
|
179
|
+
var generateRGB_R = (orientation, dir, zValue) => {
|
|
180
|
+
const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`;
|
|
181
|
+
const result = {
|
|
182
|
+
areaStyles: {
|
|
183
|
+
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(${zValue},0,0),rgb(${zValue},255,0))`
|
|
184
|
+
},
|
|
185
|
+
areaGradientStyles: {
|
|
186
|
+
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(${zValue},0,255),rgb(${zValue},255,255))`,
|
|
187
|
+
WebkitMaskImage: maskImage,
|
|
188
|
+
maskImage
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
return result;
|
|
192
|
+
};
|
|
193
|
+
var generateRGB_G = (orientation, dir, zValue) => {
|
|
194
|
+
const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`;
|
|
195
|
+
const result = {
|
|
196
|
+
areaStyles: {
|
|
197
|
+
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,${zValue},0),rgb(255,${zValue},0))`
|
|
198
|
+
},
|
|
199
|
+
areaGradientStyles: {
|
|
200
|
+
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,${zValue},255),rgb(255,${zValue},255))`,
|
|
201
|
+
WebkitMaskImage: maskImage,
|
|
202
|
+
maskImage
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
return result;
|
|
206
|
+
};
|
|
207
|
+
var generateRGB_B = (orientation, dir, zValue) => {
|
|
208
|
+
const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`;
|
|
209
|
+
const result = {
|
|
210
|
+
areaStyles: {
|
|
211
|
+
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,0,${zValue}),rgb(255,0,${zValue}))`
|
|
212
|
+
},
|
|
213
|
+
areaGradientStyles: {
|
|
214
|
+
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,255,${zValue}),rgb(255,255,${zValue}))`,
|
|
215
|
+
WebkitMaskImage: maskImage,
|
|
216
|
+
maskImage
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
return result;
|
|
220
|
+
};
|
|
221
|
+
var generateHSL_H = (orientation, dir, zValue) => {
|
|
222
|
+
const result = {
|
|
223
|
+
areaStyles: {},
|
|
224
|
+
areaGradientStyles: {
|
|
225
|
+
background: [
|
|
226
|
+
`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%)`,
|
|
227
|
+
`linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,50%),hsla(0,0%,50%,0))`,
|
|
228
|
+
`hsl(${zValue}, 100%, 50%)`
|
|
229
|
+
].join(",")
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
return result;
|
|
233
|
+
};
|
|
234
|
+
var generateHSL_S = (orientation, dir, alphaValue) => {
|
|
235
|
+
const result = {
|
|
236
|
+
areaStyles: {},
|
|
237
|
+
areaGradientStyles: {
|
|
238
|
+
background: [
|
|
239
|
+
`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%)`,
|
|
240
|
+
`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}))`,
|
|
241
|
+
"hsl(0, 0%, 50%)"
|
|
242
|
+
].join(",")
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
return result;
|
|
246
|
+
};
|
|
247
|
+
var generateHSL_L = (orientation, dir, zValue) => {
|
|
248
|
+
const result = {
|
|
249
|
+
areaStyles: {},
|
|
250
|
+
areaGradientStyles: {
|
|
251
|
+
backgroundImage: [
|
|
252
|
+
`linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,${zValue}%),hsla(0,0%,${zValue}%,0))`,
|
|
253
|
+
`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}%))`
|
|
254
|
+
].join(",")
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
return result;
|
|
258
|
+
};
|
|
259
|
+
var generateHSB_H = (orientation, dir, zValue) => {
|
|
260
|
+
const result = {
|
|
261
|
+
areaStyles: {},
|
|
262
|
+
areaGradientStyles: {
|
|
263
|
+
background: [
|
|
264
|
+
`linear-gradient(to ${orientation[Number(dir)]},hsl(0,0%,0%),hsla(0,0%,0%,0))`,
|
|
265
|
+
`linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,100%),hsla(0,0%,100%,0))`,
|
|
266
|
+
`hsl(${zValue}, 100%, 50%)`
|
|
267
|
+
].join(",")
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
return result;
|
|
271
|
+
};
|
|
272
|
+
var generateHSB_S = (orientation, dir, alphaValue) => {
|
|
273
|
+
const result = {
|
|
274
|
+
areaStyles: {},
|
|
275
|
+
areaGradientStyles: {
|
|
276
|
+
background: [
|
|
277
|
+
`linear-gradient(to ${orientation[Number(!dir)]},hsla(0,0%,0%,${alphaValue}),hsla(0,0%,0%,0))`,
|
|
278
|
+
`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}))`,
|
|
279
|
+
`linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,0%),hsl(0,0%,100%))`
|
|
280
|
+
].join(",")
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
return result;
|
|
284
|
+
};
|
|
285
|
+
var generateHSB_B = (orientation, dir, alphaValue) => {
|
|
286
|
+
const result = {
|
|
287
|
+
areaStyles: {},
|
|
288
|
+
areaGradientStyles: {
|
|
289
|
+
background: [
|
|
290
|
+
`linear-gradient(to ${orientation[Number(!dir)]},hsla(0,0%,100%,${alphaValue}),hsla(0,0%,100%,0))`,
|
|
291
|
+
`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}))`,
|
|
292
|
+
"#000"
|
|
293
|
+
].join(",")
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
return result;
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
// src/utils/get-color-area-gradient.ts
|
|
300
|
+
function getColorAreaGradient(ctx, xChannel, yChannel) {
|
|
301
|
+
const value = ctx.valueAsColor;
|
|
302
|
+
const { zChannel } = value.getColorSpaceAxes({ xChannel, yChannel });
|
|
303
|
+
const zValue = value.getChannelValue(zChannel);
|
|
304
|
+
const { minValue: zMin, maxValue: zMax } = value.getChannelRange(zChannel);
|
|
305
|
+
const orientation = ["top", ctx.dir === "rtl" ? "left" : "right"];
|
|
306
|
+
let dir = false;
|
|
307
|
+
let background = { areaStyles: {}, areaGradientStyles: {} };
|
|
308
|
+
let alphaValue = (zValue - zMin) / (zMax - zMin);
|
|
309
|
+
let isHSL = value.getColorSpace() === "hsl";
|
|
310
|
+
switch (zChannel) {
|
|
311
|
+
case "red": {
|
|
312
|
+
dir = xChannel === "green";
|
|
313
|
+
background = generateRGB_R(orientation, dir, zValue);
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
case "green": {
|
|
317
|
+
dir = xChannel === "red";
|
|
318
|
+
background = generateRGB_G(orientation, dir, zValue);
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
case "blue": {
|
|
322
|
+
dir = xChannel === "red";
|
|
323
|
+
background = generateRGB_B(orientation, dir, zValue);
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
case "hue": {
|
|
327
|
+
dir = xChannel !== "saturation";
|
|
328
|
+
if (isHSL) {
|
|
329
|
+
background = generateHSL_H(orientation, dir, zValue);
|
|
330
|
+
} else {
|
|
331
|
+
background = generateHSB_H(orientation, dir, zValue);
|
|
332
|
+
}
|
|
333
|
+
break;
|
|
334
|
+
}
|
|
335
|
+
case "saturation": {
|
|
336
|
+
dir = xChannel === "hue";
|
|
337
|
+
if (isHSL) {
|
|
338
|
+
background = generateHSL_S(orientation, dir, alphaValue);
|
|
339
|
+
} else {
|
|
340
|
+
background = generateHSB_S(orientation, dir, alphaValue);
|
|
341
|
+
}
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
case "brightness": {
|
|
345
|
+
dir = xChannel === "hue";
|
|
346
|
+
background = generateHSB_B(orientation, dir, alphaValue);
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
case "lightness": {
|
|
350
|
+
dir = xChannel === "hue";
|
|
351
|
+
background = generateHSL_L(orientation, dir, zValue);
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
return background;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// src/utils/get-slider-background.ts
|
|
359
|
+
function getSliderBgDirection(orientation, dir) {
|
|
360
|
+
if (orientation === "vertical") {
|
|
361
|
+
return "top";
|
|
362
|
+
} else if (dir === "ltr") {
|
|
363
|
+
return "right";
|
|
364
|
+
} else {
|
|
365
|
+
return "left";
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
var getSliderBgImage = (ctx, props) => {
|
|
369
|
+
const { channel } = props;
|
|
370
|
+
const dir = getSliderBgDirection(props.orientation, ctx.dir);
|
|
371
|
+
const value = ctx.valueAsColor;
|
|
372
|
+
const { minValue, maxValue } = ctx.valueAsColor.getChannelRange(channel);
|
|
373
|
+
switch (channel) {
|
|
374
|
+
case "hue":
|
|
375
|
+
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%)`;
|
|
376
|
+
case "lightness": {
|
|
377
|
+
let start = ctx.valueAsColor.withChannelValue(channel, minValue).toString("css");
|
|
378
|
+
let middle = value.withChannelValue(channel, (maxValue - minValue) / 2).toString("css");
|
|
379
|
+
let end = value.withChannelValue(channel, maxValue).toString("css");
|
|
380
|
+
return `linear-gradient(to ${dir}, ${start}, ${middle}, ${end})`;
|
|
381
|
+
}
|
|
382
|
+
case "saturation":
|
|
383
|
+
case "brightness":
|
|
384
|
+
case "red":
|
|
385
|
+
case "green":
|
|
386
|
+
case "blue":
|
|
387
|
+
case "alpha": {
|
|
388
|
+
let start = value.withChannelValue(channel, minValue).toString("css");
|
|
389
|
+
let end = value.withChannelValue(channel, maxValue).toString("css");
|
|
390
|
+
return `linear-gradient(to ${dir}, ${start}, ${end})`;
|
|
391
|
+
}
|
|
392
|
+
default:
|
|
393
|
+
throw new Error("Unknown color channel: " + channel);
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
// src/color-picker.connect.ts
|
|
398
|
+
function connect(state, send, normalize) {
|
|
399
|
+
const valueAsColor = state.context.valueAsColor;
|
|
400
|
+
const isDisabled = state.context.disabled;
|
|
401
|
+
const isInteractive = state.context.isInteractive;
|
|
402
|
+
const isDragging = state.matches("dragging");
|
|
403
|
+
const channels = valueAsColor.getColorChannels();
|
|
404
|
+
return {
|
|
405
|
+
/**
|
|
406
|
+
* Whether the color picker is being dragged
|
|
407
|
+
*/
|
|
408
|
+
isDragging,
|
|
409
|
+
/**
|
|
410
|
+
* The current color value (as a string)
|
|
411
|
+
*/
|
|
412
|
+
value: state.context.value,
|
|
413
|
+
/**
|
|
414
|
+
* The current color value (as a Color object)
|
|
415
|
+
*/
|
|
416
|
+
valueAsColor,
|
|
417
|
+
/**
|
|
418
|
+
* The current color channels of the color
|
|
419
|
+
*/
|
|
420
|
+
channels,
|
|
421
|
+
/**
|
|
422
|
+
* Function to set the color value
|
|
423
|
+
*/
|
|
424
|
+
setColor(value) {
|
|
425
|
+
send({ type: "VALUE.SET", value: (0, import_color_utils2.normalizeColor)(value), src: "set-color" });
|
|
426
|
+
},
|
|
427
|
+
/**
|
|
428
|
+
* Function to set the color value of a specific channel
|
|
429
|
+
*/
|
|
430
|
+
setChannelValue(channel, value) {
|
|
431
|
+
const color = valueAsColor.withChannelValue(channel, value);
|
|
432
|
+
send({ type: "VALUE.SET", value: color, src: "set-channel" });
|
|
433
|
+
},
|
|
434
|
+
/**
|
|
435
|
+
* Function to set the color format
|
|
436
|
+
*/
|
|
437
|
+
setFormat(format) {
|
|
438
|
+
const value = valueAsColor.toFormat(format);
|
|
439
|
+
send({ type: "VALUE.SET", value, src: "set-format" });
|
|
440
|
+
},
|
|
441
|
+
contentProps: normalize.element({
|
|
442
|
+
...parts.content.attrs,
|
|
443
|
+
id: dom.getContentId(state.context)
|
|
444
|
+
}),
|
|
445
|
+
getAreaProps(props) {
|
|
446
|
+
const { xChannel, yChannel } = props;
|
|
447
|
+
const { areaStyles } = getColorAreaGradient(state.context, xChannel, yChannel);
|
|
448
|
+
return normalize.element({
|
|
449
|
+
...parts.area.attrs,
|
|
450
|
+
id: dom.getAreaId(state.context),
|
|
451
|
+
role: "group",
|
|
452
|
+
onPointerDown(event) {
|
|
453
|
+
if (!isInteractive)
|
|
454
|
+
return;
|
|
455
|
+
const evt = (0, import_dom_event2.getNativeEvent)(event);
|
|
456
|
+
if (!(0, import_dom_event2.isLeftClick)(evt) || (0, import_dom_event2.isModifiedEvent)(evt))
|
|
457
|
+
return;
|
|
458
|
+
const point = (0, import_dom_event2.getEventPoint)(evt);
|
|
459
|
+
const channel = { xChannel, yChannel };
|
|
460
|
+
send({ type: "AREA.POINTER_DOWN", point, channel, id: "area" });
|
|
461
|
+
},
|
|
462
|
+
style: {
|
|
463
|
+
position: "relative",
|
|
464
|
+
touchAction: "none",
|
|
465
|
+
forcedColorAdjust: "none",
|
|
466
|
+
...areaStyles
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
},
|
|
470
|
+
getAreaGradientProps(props) {
|
|
471
|
+
const { xChannel, yChannel } = props;
|
|
472
|
+
const { areaGradientStyles } = getColorAreaGradient(state.context, xChannel, yChannel);
|
|
473
|
+
return normalize.element({
|
|
474
|
+
...parts.areaGradient.attrs,
|
|
475
|
+
id: dom.getAreaGradientId(state.context),
|
|
476
|
+
style: {
|
|
477
|
+
position: "relative",
|
|
478
|
+
touchAction: "none",
|
|
479
|
+
forcedColorAdjust: "none",
|
|
480
|
+
...areaGradientStyles
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
},
|
|
484
|
+
getAreaThumbProps(props) {
|
|
485
|
+
const { xChannel, yChannel } = props;
|
|
486
|
+
const { getThumbPosition } = getChannelDetails(valueAsColor, xChannel, yChannel);
|
|
487
|
+
const { x, y } = getThumbPosition();
|
|
488
|
+
const channel = { xChannel, yChannel };
|
|
489
|
+
return normalize.element({
|
|
490
|
+
...parts.areaThumb.attrs,
|
|
491
|
+
id: dom.getAreaThumbId(state.context),
|
|
492
|
+
tabIndex: isDisabled ? void 0 : 0,
|
|
493
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
494
|
+
role: "presentation",
|
|
495
|
+
style: {
|
|
496
|
+
position: "absolute",
|
|
497
|
+
left: `${x * 100}%`,
|
|
498
|
+
top: `${y * 100}%`,
|
|
499
|
+
transform: "translate(-50%, -50%)",
|
|
500
|
+
touchAction: "none",
|
|
501
|
+
forcedColorAdjust: "none",
|
|
502
|
+
background: valueAsColor.withChannelValue("alpha", 1).toString("css")
|
|
503
|
+
},
|
|
504
|
+
onBlur() {
|
|
505
|
+
send("AREA.BLUR");
|
|
506
|
+
},
|
|
507
|
+
onKeyDown(event) {
|
|
508
|
+
if (!isInteractive)
|
|
509
|
+
return;
|
|
510
|
+
const step = (0, import_dom_event2.getEventStep)(event);
|
|
511
|
+
const keyMap = {
|
|
512
|
+
ArrowUp() {
|
|
513
|
+
send({ type: "AREA.ARROW_UP", channel, step });
|
|
514
|
+
},
|
|
515
|
+
ArrowDown() {
|
|
516
|
+
send({ type: "AREA.ARROW_DOWN", channel, step });
|
|
517
|
+
},
|
|
518
|
+
ArrowLeft() {
|
|
519
|
+
send({ type: "AREA.ARROW_LEFT", channel, step });
|
|
520
|
+
},
|
|
521
|
+
ArrowRight() {
|
|
522
|
+
send({ type: "AREA.ARROW_RIGHT", channel, step });
|
|
523
|
+
},
|
|
524
|
+
PageUp() {
|
|
525
|
+
send({ type: "AREA.PAGE_UP", channel, step });
|
|
526
|
+
},
|
|
527
|
+
PageDown() {
|
|
528
|
+
send({ type: "AREA.PAGE_DOWN", channel, step });
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
const exec = keyMap[(0, import_dom_event2.getEventKey)(event, state.context)];
|
|
532
|
+
if (exec) {
|
|
533
|
+
exec(event);
|
|
534
|
+
event.preventDefault();
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
});
|
|
538
|
+
},
|
|
539
|
+
getChannelSliderTrackProps(props) {
|
|
540
|
+
const { orientation = "horizontal", channel } = props;
|
|
541
|
+
return normalize.element({
|
|
542
|
+
...parts.channelSliderTrack.attrs,
|
|
543
|
+
id: dom.getChannelSliderTrackId(state.context, channel),
|
|
544
|
+
role: "group",
|
|
545
|
+
"data-channel": channel,
|
|
546
|
+
"data-orientation": orientation,
|
|
547
|
+
onPointerDown(event) {
|
|
548
|
+
if (!isInteractive)
|
|
549
|
+
return;
|
|
550
|
+
const evt = (0, import_dom_event2.getNativeEvent)(event);
|
|
551
|
+
if (!(0, import_dom_event2.isLeftClick)(evt) || (0, import_dom_event2.isModifiedEvent)(evt))
|
|
552
|
+
return;
|
|
553
|
+
const point = (0, import_dom_event2.getEventPoint)(evt);
|
|
554
|
+
send({ type: "CHANNEL_SLIDER.POINTER_DOWN", channel, point, id: channel, orientation });
|
|
555
|
+
},
|
|
556
|
+
style: {
|
|
557
|
+
position: "relative",
|
|
558
|
+
touchAction: "none",
|
|
559
|
+
forcedColorAdjust: "none",
|
|
560
|
+
backgroundImage: getSliderBgImage(state.context, { orientation, channel })
|
|
561
|
+
}
|
|
562
|
+
});
|
|
563
|
+
},
|
|
564
|
+
getChannelSliderBackgroundProps(props) {
|
|
565
|
+
const { orientation = "horizontal", channel } = props;
|
|
566
|
+
return normalize.element({
|
|
567
|
+
...parts.channelSliderTrackBg.attrs,
|
|
568
|
+
"data-orientation": orientation,
|
|
569
|
+
"data-channel": channel,
|
|
570
|
+
style: {
|
|
571
|
+
position: "absolute",
|
|
572
|
+
backgroundColor: "#fff",
|
|
573
|
+
backgroundImage: [
|
|
574
|
+
"linear-gradient(-45deg,#0000 75.5%,#bcbcbc 75.5%)",
|
|
575
|
+
"linear-gradient(45deg,#0000 75.5%,#bcbcbc 75.5%)",
|
|
576
|
+
"linear-gradient(-45deg,#bcbcbc 25.5%,#0000 25.5%)",
|
|
577
|
+
"linear-gradient(45deg,#bcbcbc 25.5%,#0000 25.5%)"
|
|
578
|
+
].join(","),
|
|
579
|
+
backgroundSize: "16px 16px",
|
|
580
|
+
backgroundPosition: "-2px -2px,-2px 6px,6px -10px,-10px -2px",
|
|
581
|
+
inset: 0,
|
|
582
|
+
zIndex: -1
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
},
|
|
586
|
+
getChannelSliderThumbProps(props) {
|
|
587
|
+
const { orientation = "horizontal", channel } = props;
|
|
588
|
+
const { minValue, maxValue, step: stepValue } = valueAsColor.getChannelRange(channel);
|
|
589
|
+
const channelValue = valueAsColor.getChannelValue(channel);
|
|
590
|
+
const offset = (channelValue - minValue) / (maxValue - minValue);
|
|
591
|
+
const placementStyles = orientation === "horizontal" ? { left: `${offset * 100}%`, top: "50%" } : { top: `${offset * 100}%`, left: "50%" };
|
|
592
|
+
return normalize.element({
|
|
593
|
+
...parts.channelSliderThumb.attrs,
|
|
594
|
+
id: dom.getChannelSliderThumbId(state.context, channel),
|
|
595
|
+
role: "slider",
|
|
596
|
+
"aria-label": channel,
|
|
597
|
+
tabIndex: isDisabled ? void 0 : 0,
|
|
598
|
+
"data-channel": channel,
|
|
599
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
600
|
+
"data-orientation": orientation,
|
|
601
|
+
"aria-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
602
|
+
"aria-orientation": orientation,
|
|
603
|
+
"aria-valuemax": maxValue,
|
|
604
|
+
"aria-valuemin": minValue,
|
|
605
|
+
"aria-valuenow": channelValue,
|
|
606
|
+
style: {
|
|
607
|
+
forcedColorAdjust: "none",
|
|
608
|
+
position: "absolute",
|
|
609
|
+
background: getChannelDisplayColor(valueAsColor, channel).toString("css"),
|
|
610
|
+
...placementStyles
|
|
611
|
+
},
|
|
612
|
+
onFocus() {
|
|
613
|
+
if (!isInteractive)
|
|
614
|
+
return;
|
|
615
|
+
send({ type: "CHANNEL_SLIDER.FOCUS", channel });
|
|
616
|
+
},
|
|
617
|
+
onBlur() {
|
|
618
|
+
if (!isInteractive)
|
|
619
|
+
return;
|
|
620
|
+
send({ type: "CHANNEL_SLIDER.BLUR", channel });
|
|
621
|
+
},
|
|
622
|
+
onKeyDown(event) {
|
|
623
|
+
if (!isInteractive)
|
|
624
|
+
return;
|
|
625
|
+
const step = (0, import_dom_event2.getEventStep)(event) * stepValue;
|
|
626
|
+
const keyMap = {
|
|
627
|
+
ArrowUp() {
|
|
628
|
+
send({ type: "CHANNEL_SLIDER.ARROW_UP", channel, step });
|
|
629
|
+
},
|
|
630
|
+
ArrowDown() {
|
|
631
|
+
send({ type: "CHANNEL_SLIDER.ARROW_DOWN", channel, step });
|
|
632
|
+
},
|
|
633
|
+
ArrowLeft() {
|
|
634
|
+
send({ type: "CHANNEL_SLIDER.ARROW_LEFT", channel, step });
|
|
635
|
+
},
|
|
636
|
+
ArrowRight() {
|
|
637
|
+
send({ type: "CHANNEL_SLIDER.ARROW_RIGHT", channel, step });
|
|
638
|
+
},
|
|
639
|
+
PageUp() {
|
|
640
|
+
send({ type: "CHANNEL_SLIDER.PAGE_UP", channel });
|
|
641
|
+
},
|
|
642
|
+
PageDown() {
|
|
643
|
+
send({ type: "CHANNEL_SLIDER.PAGE_DOWN", channel });
|
|
644
|
+
},
|
|
645
|
+
Home() {
|
|
646
|
+
send({ type: "CHANNEL_SLIDER.HOME", channel });
|
|
647
|
+
},
|
|
648
|
+
End() {
|
|
649
|
+
send({ type: "CHANNEL_SLIDER.END", channel });
|
|
650
|
+
}
|
|
651
|
+
};
|
|
652
|
+
const exec = keyMap[(0, import_dom_event2.getEventKey)(event, state.context)];
|
|
653
|
+
if (exec) {
|
|
654
|
+
exec(event);
|
|
655
|
+
event.preventDefault();
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
});
|
|
659
|
+
},
|
|
660
|
+
getChannelInputProps(props) {
|
|
661
|
+
const { channel } = props;
|
|
662
|
+
const isTextField = channel === "hex" || channel === "css";
|
|
663
|
+
const range = getChannelInputRange(valueAsColor, channel);
|
|
664
|
+
return normalize.input({
|
|
665
|
+
...parts.channelInput.attrs,
|
|
666
|
+
type: isTextField ? "text" : "number",
|
|
667
|
+
"data-channel": channel,
|
|
668
|
+
"aria-label": channel,
|
|
669
|
+
disabled: isDisabled,
|
|
670
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
671
|
+
readOnly: state.context.readOnly,
|
|
672
|
+
id: dom.getChannelInputId(state.context, channel),
|
|
673
|
+
defaultValue: getChannelInputValue(valueAsColor, channel),
|
|
674
|
+
min: range?.minValue,
|
|
675
|
+
max: range?.maxValue,
|
|
676
|
+
step: range?.step,
|
|
677
|
+
onFocus() {
|
|
678
|
+
send({ type: "CHANNEL_INPUT.FOCUS", channel });
|
|
679
|
+
},
|
|
680
|
+
onChange(event) {
|
|
681
|
+
if (isTextField)
|
|
682
|
+
return;
|
|
683
|
+
const value = event.currentTarget.value;
|
|
684
|
+
send({ type: "CHANNEL_INPUT.CHANGE", channel, value, isTextField });
|
|
685
|
+
},
|
|
686
|
+
onBlur(event) {
|
|
687
|
+
const value = event.currentTarget.value;
|
|
688
|
+
send({ type: "CHANNEL_INPUT.BLUR", channel, value, isTextField });
|
|
689
|
+
},
|
|
690
|
+
onKeyDown(event) {
|
|
691
|
+
if (!isTextField)
|
|
692
|
+
return;
|
|
693
|
+
if (event.key === "Enter") {
|
|
694
|
+
const value = event.currentTarget.value;
|
|
695
|
+
send({ type: "CHANNEL_INPUT.CHANGE", channel, value, isTextField });
|
|
696
|
+
}
|
|
697
|
+
},
|
|
698
|
+
style: {
|
|
699
|
+
appearance: "none",
|
|
700
|
+
WebkitAppearance: "none",
|
|
701
|
+
MozAppearance: "textfield"
|
|
702
|
+
}
|
|
703
|
+
});
|
|
704
|
+
},
|
|
705
|
+
eyeDropperTriggerProps: normalize.button({
|
|
706
|
+
...parts.eyeDropTrigger.attrs,
|
|
707
|
+
onClick() {
|
|
708
|
+
send("EYEDROPPER.CLICK");
|
|
709
|
+
}
|
|
710
|
+
}),
|
|
711
|
+
getSwatchBackgroundProps(props) {
|
|
712
|
+
const { value } = props;
|
|
713
|
+
const alpha = (0, import_color_utils2.normalizeColor)(value).getChannelValue("alpha");
|
|
714
|
+
return normalize.element({
|
|
715
|
+
...parts.swatchBg.attrs,
|
|
716
|
+
"data-alpha": alpha,
|
|
717
|
+
style: {
|
|
718
|
+
width: "100%",
|
|
719
|
+
height: "100%",
|
|
720
|
+
background: "#fff",
|
|
721
|
+
backgroundImage: [
|
|
722
|
+
"linear-gradient(-45deg,#0000 75.5%,#bcbcbc 75.5%)",
|
|
723
|
+
"linear-gradient(45deg,#0000 75.5%,#bcbcbc 75.5%)",
|
|
724
|
+
"linear-gradient(-45deg,#bcbcbc 25.5%,#0000 25.5%)",
|
|
725
|
+
"linear-gradient(45deg,#bcbcbc 25.5%,#0000 25.5%)"
|
|
726
|
+
].join(","),
|
|
727
|
+
backgroundPosition: "-2px -2px,-2px 6px,6px -10px,-10px -2px",
|
|
728
|
+
backgroundSize: "16px 16px",
|
|
729
|
+
position: "absolute",
|
|
730
|
+
inset: "0px",
|
|
731
|
+
zIndex: -1
|
|
732
|
+
}
|
|
733
|
+
});
|
|
734
|
+
},
|
|
735
|
+
getSwatchProps(props) {
|
|
736
|
+
const { value, readOnly } = props;
|
|
737
|
+
const color = (0, import_color_utils2.normalizeColor)(value).toFormat(valueAsColor.getColorSpace());
|
|
738
|
+
return normalize.element({
|
|
739
|
+
...parts.swatch.attrs,
|
|
740
|
+
onClick() {
|
|
741
|
+
if (readOnly)
|
|
742
|
+
return;
|
|
743
|
+
send({ type: "VALUE.SET", value: color });
|
|
744
|
+
},
|
|
745
|
+
style: {
|
|
746
|
+
position: "relative",
|
|
747
|
+
background: color.toString("css")
|
|
748
|
+
}
|
|
749
|
+
});
|
|
750
|
+
}
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
// src/color-picker.machine.ts
|
|
755
|
+
var import_color_utils3 = require("@zag-js/color-utils");
|
|
756
|
+
var import_core = require("@zag-js/core");
|
|
757
|
+
var import_dom_event3 = require("@zag-js/dom-event");
|
|
758
|
+
var import_dom_query3 = require("@zag-js/dom-query");
|
|
759
|
+
var import_numeric_range2 = require("@zag-js/numeric-range");
|
|
760
|
+
var import_text_selection = require("@zag-js/text-selection");
|
|
761
|
+
var import_utils = require("@zag-js/utils");
|
|
762
|
+
function machine(userContext) {
|
|
763
|
+
const ctx = (0, import_utils.compact)(userContext);
|
|
764
|
+
return (0, import_core.createMachine)(
|
|
765
|
+
{
|
|
766
|
+
id: "color-picker",
|
|
767
|
+
initial: "idle",
|
|
768
|
+
context: {
|
|
769
|
+
dir: "ltr",
|
|
770
|
+
activeId: null,
|
|
771
|
+
activeChannel: null,
|
|
772
|
+
activeOrientation: null,
|
|
773
|
+
value: "#D9D9D9",
|
|
774
|
+
...ctx,
|
|
775
|
+
valueAsColor: (0, import_color_utils3.parseColor)(ctx.value || "#D9D9D9")
|
|
776
|
+
},
|
|
777
|
+
computed: {
|
|
778
|
+
isRtl: (ctx2) => ctx2.dir === "rtl",
|
|
779
|
+
isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readOnly)
|
|
780
|
+
},
|
|
781
|
+
on: {
|
|
782
|
+
"VALUE.SET": {
|
|
783
|
+
actions: ["setValue"]
|
|
784
|
+
}
|
|
785
|
+
},
|
|
786
|
+
created: ["setValueAsColor"],
|
|
787
|
+
watch: {
|
|
788
|
+
value: ["setValueAsColor", "syncChannelInputs", "invokeOnChange"]
|
|
789
|
+
},
|
|
790
|
+
states: {
|
|
791
|
+
idle: {
|
|
792
|
+
on: {
|
|
793
|
+
"EYEDROPPER.CLICK": {
|
|
794
|
+
actions: ["openEyeDropper"]
|
|
795
|
+
},
|
|
796
|
+
"AREA.POINTER_DOWN": {
|
|
797
|
+
target: "dragging",
|
|
798
|
+
actions: ["setActiveChannel", "setAreaColorFromPoint", "focusAreaThumb"]
|
|
799
|
+
},
|
|
800
|
+
"CHANNEL_SLIDER.POINTER_DOWN": {
|
|
801
|
+
target: "dragging",
|
|
802
|
+
actions: ["setActiveChannel", "setChannelColorFromPoint", "focusChannelThumb"]
|
|
803
|
+
},
|
|
804
|
+
"CHANNEL_INPUT.FOCUS": {
|
|
805
|
+
target: "focused",
|
|
806
|
+
actions: ["setActiveChannel"]
|
|
807
|
+
},
|
|
808
|
+
"CHANNEL_INPUT.CHANGE": {
|
|
809
|
+
actions: ["setChannelColorFromInput"]
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
},
|
|
813
|
+
focused: {
|
|
814
|
+
on: {
|
|
815
|
+
"AREA.POINTER_DOWN": {
|
|
816
|
+
target: "dragging",
|
|
817
|
+
actions: ["setActiveChannel", "setAreaColorFromPoint", "focusAreaThumb"]
|
|
818
|
+
},
|
|
819
|
+
"CHANNEL_SLIDER.POINTER_DOWN": {
|
|
820
|
+
target: "dragging",
|
|
821
|
+
actions: ["setActiveChannel", "setChannelColorFromPoint", "focusChannelThumb"]
|
|
822
|
+
},
|
|
823
|
+
"AREA.ARROW_LEFT": {
|
|
824
|
+
actions: ["decrementXChannel"]
|
|
825
|
+
},
|
|
826
|
+
"AREA.ARROW_RIGHT": {
|
|
827
|
+
actions: ["incrementXChannel"]
|
|
828
|
+
},
|
|
829
|
+
"AREA.ARROW_UP": {
|
|
830
|
+
actions: ["incrementYChannel"]
|
|
831
|
+
},
|
|
832
|
+
"AREA.ARROW_DOWN": {
|
|
833
|
+
actions: ["decrementYChannel"]
|
|
834
|
+
},
|
|
835
|
+
"AREA.PAGE_UP": {
|
|
836
|
+
actions: ["incrementXChannel"]
|
|
837
|
+
},
|
|
838
|
+
"AREA.PAGE_DOWN": {
|
|
839
|
+
actions: ["decrementXChannel"]
|
|
840
|
+
},
|
|
841
|
+
"CHANNEL_SLIDER.ARROW_LEFT": {
|
|
842
|
+
actions: ["decrementChannel"]
|
|
843
|
+
},
|
|
844
|
+
"CHANNEL_SLIDER.ARROW_RIGHT": {
|
|
845
|
+
actions: ["incrementChannel"]
|
|
846
|
+
},
|
|
847
|
+
"CHANNEL_SLIDER.ARROW_UP": {
|
|
848
|
+
actions: ["incrementChannel"]
|
|
849
|
+
},
|
|
850
|
+
"CHANNEL_SLIDER.ARROW_DOWN": {
|
|
851
|
+
actions: ["decrementChannel"]
|
|
852
|
+
},
|
|
853
|
+
"CHANNEL_SLIDER.PAGE_UP": {
|
|
854
|
+
actions: ["incrementChannel"]
|
|
855
|
+
},
|
|
856
|
+
"CHANNEL_SLIDER.PAGE_DOWN": {
|
|
857
|
+
actions: ["decrementChannel"]
|
|
858
|
+
},
|
|
859
|
+
"CHANNEL_SLIDER.HOME": {
|
|
860
|
+
actions: ["setChannelToMin"]
|
|
861
|
+
},
|
|
862
|
+
"CHANNEL_SLIDER.END": {
|
|
863
|
+
actions: ["setChannelToMax"]
|
|
864
|
+
},
|
|
865
|
+
"CHANNEL_INPUT.FOCUS": {
|
|
866
|
+
actions: ["setActiveChannel"]
|
|
867
|
+
},
|
|
868
|
+
"CHANNEL_INPUT.CHANGE": {
|
|
869
|
+
actions: ["setChannelColorFromInput"]
|
|
870
|
+
},
|
|
871
|
+
"CHANNEL_INPUT.BLUR": [
|
|
872
|
+
{
|
|
873
|
+
guard: "isTextField",
|
|
874
|
+
target: "idle",
|
|
875
|
+
actions: ["setChannelColorFromInput"]
|
|
876
|
+
},
|
|
877
|
+
{ target: "idle" }
|
|
878
|
+
],
|
|
879
|
+
"CHANNEL_SLIDER.BLUR": {
|
|
880
|
+
target: "idle"
|
|
881
|
+
},
|
|
882
|
+
"AREA.BLUR": {
|
|
883
|
+
target: "idle"
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
},
|
|
887
|
+
dragging: {
|
|
888
|
+
exit: ["clearActiveChannel"],
|
|
889
|
+
activities: ["trackPointerMove", "disableTextSelection"],
|
|
890
|
+
on: {
|
|
891
|
+
"AREA.POINTER_MOVE": {
|
|
892
|
+
actions: ["setAreaColorFromPoint"]
|
|
893
|
+
},
|
|
894
|
+
"AREA.POINTER_UP": {
|
|
895
|
+
target: "focused",
|
|
896
|
+
actions: ["invokeOnChangeEnd"]
|
|
897
|
+
},
|
|
898
|
+
"CHANNEL_SLIDER.POINTER_MOVE": {
|
|
899
|
+
actions: ["setChannelColorFromPoint"]
|
|
900
|
+
},
|
|
901
|
+
"CHANNEL_SLIDER.POINTER_UP": {
|
|
902
|
+
target: "focused",
|
|
903
|
+
actions: ["invokeOnChangeEnd"]
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
},
|
|
909
|
+
{
|
|
910
|
+
guards: {
|
|
911
|
+
isTextField: (_ctx, evt) => !!evt.isTextField
|
|
912
|
+
},
|
|
913
|
+
activities: {
|
|
914
|
+
trackPointerMove(ctx2, _evt, { send }) {
|
|
915
|
+
return (0, import_dom_event3.trackPointerMove)(dom.getDoc(ctx2), {
|
|
916
|
+
onPointerMove({ point }) {
|
|
917
|
+
const type = ctx2.activeId === "area" ? "AREA.POINTER_MOVE" : "CHANNEL_SLIDER.POINTER_MOVE";
|
|
918
|
+
send({ type, point });
|
|
919
|
+
},
|
|
920
|
+
onPointerUp() {
|
|
921
|
+
const type = ctx2.activeId === "area" ? "AREA.POINTER_UP" : "CHANNEL_SLIDER.POINTER_UP";
|
|
922
|
+
send({ type });
|
|
923
|
+
}
|
|
924
|
+
});
|
|
925
|
+
},
|
|
926
|
+
disableTextSelection(ctx2) {
|
|
927
|
+
return (0, import_text_selection.disableTextSelection)({ doc: dom.getDoc(ctx2), target: dom.getContentEl(ctx2) });
|
|
928
|
+
}
|
|
929
|
+
},
|
|
930
|
+
actions: {
|
|
931
|
+
openEyeDropper(ctx2) {
|
|
932
|
+
const isSupported = "EyeDropper" in dom.getWin(ctx2);
|
|
933
|
+
if (!isSupported)
|
|
934
|
+
return;
|
|
935
|
+
const win = dom.getWin(ctx2);
|
|
936
|
+
const picker = new win.EyeDropper();
|
|
937
|
+
picker.open().then(({ sRGBHex }) => {
|
|
938
|
+
const format = ctx2.valueAsColor.getColorSpace();
|
|
939
|
+
const color = (0, import_color_utils3.parseColor)(sRGBHex).toFormat(format);
|
|
940
|
+
setColor(ctx2, color);
|
|
941
|
+
ctx2.onChangeEnd?.({ value: ctx2.value, valueAsColor: color });
|
|
942
|
+
}).catch(() => void 0);
|
|
943
|
+
},
|
|
944
|
+
setActiveChannel(ctx2, evt) {
|
|
945
|
+
ctx2.activeId = evt.id;
|
|
946
|
+
if (evt.channel) {
|
|
947
|
+
ctx2.activeChannel = evt.channel;
|
|
948
|
+
}
|
|
949
|
+
if (evt.orientation) {
|
|
950
|
+
ctx2.activeOrientation = evt.orientation;
|
|
951
|
+
}
|
|
952
|
+
},
|
|
953
|
+
clearActiveChannel(ctx2) {
|
|
954
|
+
ctx2.activeChannel = null;
|
|
955
|
+
ctx2.activeId = null;
|
|
956
|
+
ctx2.activeOrientation = null;
|
|
957
|
+
},
|
|
958
|
+
setAreaColorFromPoint(ctx2, evt) {
|
|
959
|
+
const { xChannel, yChannel } = evt.channel || ctx2.activeChannel;
|
|
960
|
+
const percent = dom.getAreaValueFromPoint(ctx2, evt.point);
|
|
961
|
+
const { getColorFromPoint } = getChannelDetails(ctx2.valueAsColor, xChannel, yChannel);
|
|
962
|
+
const color = getColorFromPoint(percent.x, percent.y);
|
|
963
|
+
if (!color)
|
|
964
|
+
return;
|
|
965
|
+
setColor(ctx2, color);
|
|
966
|
+
},
|
|
967
|
+
setChannelColorFromPoint(ctx2, evt) {
|
|
968
|
+
const channel = evt.channel || ctx2.activeId;
|
|
969
|
+
const percent = dom.getChannelSliderValueFromPoint(ctx2, evt.point, channel);
|
|
970
|
+
const { minValue, maxValue, step } = ctx2.valueAsColor.getChannelRange(channel);
|
|
971
|
+
const orientation = ctx2.activeOrientation || "horizontal";
|
|
972
|
+
const point = orientation === "horizontal" ? percent.x : percent.y;
|
|
973
|
+
const channelValue = (0, import_numeric_range2.getPercentValue)(point, minValue, maxValue, step);
|
|
974
|
+
const value = (0, import_numeric_range2.snapValueToStep)(channelValue - step, minValue, maxValue, step);
|
|
975
|
+
const newColor = ctx2.valueAsColor.withChannelValue(channel, value);
|
|
976
|
+
setColor(ctx2, newColor);
|
|
977
|
+
},
|
|
978
|
+
setValue(ctx2, evt) {
|
|
979
|
+
setColor(ctx2, evt.value);
|
|
980
|
+
},
|
|
981
|
+
setValueAsColor(ctx2) {
|
|
982
|
+
try {
|
|
983
|
+
const color = (0, import_color_utils3.parseColor)(ctx2.value);
|
|
984
|
+
if (color.isEqual(ctx2.valueAsColor))
|
|
985
|
+
return;
|
|
986
|
+
ctx2.valueAsColor = color;
|
|
987
|
+
} catch {
|
|
988
|
+
}
|
|
989
|
+
},
|
|
990
|
+
syncChannelInputs(ctx2) {
|
|
991
|
+
const inputs = dom.getChannelInputEls(ctx2);
|
|
992
|
+
inputs.forEach((input) => {
|
|
993
|
+
const channel = input.getAttribute("data-channel");
|
|
994
|
+
if (!channel)
|
|
995
|
+
return;
|
|
996
|
+
const value = getChannelInputValue(ctx2.valueAsColor, channel);
|
|
997
|
+
input.value = value.toString();
|
|
998
|
+
});
|
|
999
|
+
},
|
|
1000
|
+
setChannelColorFromInput(ctx2, evt) {
|
|
1001
|
+
const { channel, isTextField, value } = evt;
|
|
1002
|
+
try {
|
|
1003
|
+
const format = ctx2.valueAsColor.getColorSpace();
|
|
1004
|
+
const newColor = isTextField ? (0, import_color_utils3.parseColor)(value).toFormat(format) : ctx2.valueAsColor.withChannelValue(channel, value);
|
|
1005
|
+
setColor(ctx2, newColor);
|
|
1006
|
+
} catch {
|
|
1007
|
+
const input = dom.getChannelInputEl(ctx2, channel);
|
|
1008
|
+
if (!input)
|
|
1009
|
+
return;
|
|
1010
|
+
input.value = getChannelInputValue(ctx2.valueAsColor, channel);
|
|
1011
|
+
}
|
|
1012
|
+
},
|
|
1013
|
+
incrementChannel(ctx2, evt) {
|
|
1014
|
+
const { minValue, maxValue, step } = ctx2.valueAsColor.getChannelRange(evt.channel);
|
|
1015
|
+
const channelValue = ctx2.valueAsColor.getChannelValue(evt.channel);
|
|
1016
|
+
const value = (0, import_numeric_range2.snapValueToStep)(channelValue + evt.step, minValue, maxValue, step);
|
|
1017
|
+
const newColor = ctx2.valueAsColor.withChannelValue(evt.channel, (0, import_numeric_range2.clampValue)(value, minValue, maxValue));
|
|
1018
|
+
setColor(ctx2, newColor);
|
|
1019
|
+
},
|
|
1020
|
+
decrementChannel(ctx2, evt) {
|
|
1021
|
+
const { minValue, maxValue, step } = ctx2.valueAsColor.getChannelRange(evt.channel);
|
|
1022
|
+
const channelValue = ctx2.valueAsColor.getChannelValue(evt.channel);
|
|
1023
|
+
const value = (0, import_numeric_range2.snapValueToStep)(channelValue - evt.step, minValue, maxValue, step);
|
|
1024
|
+
const newColor = ctx2.valueAsColor.withChannelValue(evt.channel, (0, import_numeric_range2.clampValue)(value, minValue, maxValue));
|
|
1025
|
+
setColor(ctx2, newColor);
|
|
1026
|
+
},
|
|
1027
|
+
incrementXChannel(ctx2, evt) {
|
|
1028
|
+
const { xChannel, yChannel } = evt.channel;
|
|
1029
|
+
const { incrementX } = getChannelDetails(ctx2.valueAsColor, xChannel, yChannel);
|
|
1030
|
+
const newColor = ctx2.valueAsColor.withChannelValue(xChannel, incrementX(evt.step));
|
|
1031
|
+
setColor(ctx2, newColor);
|
|
1032
|
+
},
|
|
1033
|
+
decrementXChannel(ctx2, evt) {
|
|
1034
|
+
const { xChannel, yChannel } = evt.channel;
|
|
1035
|
+
const { decrementX } = getChannelDetails(ctx2.valueAsColor, xChannel, yChannel);
|
|
1036
|
+
const newColor = ctx2.valueAsColor.withChannelValue(xChannel, decrementX(evt.step));
|
|
1037
|
+
setColor(ctx2, newColor);
|
|
1038
|
+
},
|
|
1039
|
+
incrementYChannel(ctx2, evt) {
|
|
1040
|
+
const { xChannel, yChannel } = evt.channel;
|
|
1041
|
+
const { incrementY } = getChannelDetails(ctx2.valueAsColor, xChannel, yChannel);
|
|
1042
|
+
const newColor = ctx2.valueAsColor.withChannelValue(yChannel, incrementY(evt.step));
|
|
1043
|
+
setColor(ctx2, newColor);
|
|
1044
|
+
},
|
|
1045
|
+
decrementYChannel(ctx2, evt) {
|
|
1046
|
+
const { xChannel, yChannel } = evt.channel;
|
|
1047
|
+
const { decrementY } = getChannelDetails(ctx2.valueAsColor, xChannel, yChannel);
|
|
1048
|
+
const newColor = ctx2.valueAsColor.withChannelValue(yChannel, decrementY(evt.step));
|
|
1049
|
+
setColor(ctx2, newColor);
|
|
1050
|
+
},
|
|
1051
|
+
setChannelToMax(ctx2, evt) {
|
|
1052
|
+
const { maxValue } = ctx2.valueAsColor.getChannelRange(evt.channel);
|
|
1053
|
+
const newColor = ctx2.valueAsColor.withChannelValue(evt.channel, maxValue);
|
|
1054
|
+
setColor(ctx2, newColor);
|
|
1055
|
+
},
|
|
1056
|
+
setChannelToMin(ctx2, evt) {
|
|
1057
|
+
const { minValue } = ctx2.valueAsColor.getChannelRange(evt.channel);
|
|
1058
|
+
const newColor = ctx2.valueAsColor.withChannelValue(evt.channel, minValue);
|
|
1059
|
+
setColor(ctx2, newColor);
|
|
1060
|
+
},
|
|
1061
|
+
invokeOnChangeEnd(ctx2) {
|
|
1062
|
+
ctx2.onChangeEnd?.({ value: ctx2.value, valueAsColor: ctx2.valueAsColor });
|
|
1063
|
+
},
|
|
1064
|
+
invokeOnChange(ctx2) {
|
|
1065
|
+
ctx2.onChange?.({ value: ctx2.value, valueAsColor: ctx2.valueAsColor });
|
|
1066
|
+
},
|
|
1067
|
+
focusAreaThumb(ctx2) {
|
|
1068
|
+
(0, import_dom_query3.raf)(() => {
|
|
1069
|
+
dom.getAreaThumbEl(ctx2)?.focus({ preventScroll: true });
|
|
1070
|
+
});
|
|
1071
|
+
},
|
|
1072
|
+
focusChannelThumb(ctx2, evt) {
|
|
1073
|
+
(0, import_dom_query3.raf)(() => {
|
|
1074
|
+
dom.getChannelSliderThumbEl(ctx2, evt.channel)?.focus({ preventScroll: true });
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
);
|
|
1080
|
+
}
|
|
1081
|
+
var setColor = (ctx, color) => {
|
|
1082
|
+
ctx.value = color.toString("css");
|
|
1083
|
+
ctx.valueAsColor = color;
|
|
1084
|
+
};
|
|
1085
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1086
|
+
0 && (module.exports = {
|
|
1087
|
+
anatomy,
|
|
1088
|
+
connect,
|
|
1089
|
+
machine
|
|
1090
|
+
});
|
|
1091
|
+
//# sourceMappingURL=index.js.map
|