@zag-js/color-picker 0.50.0 → 0.51.1
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.js +1 -1402
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1379
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -12
package/dist/index.js
CHANGED
|
@@ -1,1403 +1,2 @@
|
|
|
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/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
anatomy: () => anatomy,
|
|
24
|
-
connect: () => connect,
|
|
25
|
-
machine: () => machine,
|
|
26
|
-
parse: () => parse
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(src_exports);
|
|
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
|
-
"root",
|
|
34
|
-
"label",
|
|
35
|
-
"control",
|
|
36
|
-
"trigger",
|
|
37
|
-
"positioner",
|
|
38
|
-
"content",
|
|
39
|
-
"area",
|
|
40
|
-
"areaThumb",
|
|
41
|
-
"areaBackground",
|
|
42
|
-
"channelSlider",
|
|
43
|
-
"channelSliderTrack",
|
|
44
|
-
"channelSliderThumb",
|
|
45
|
-
"channelInput",
|
|
46
|
-
"transparencyGrid",
|
|
47
|
-
"swatchGroup",
|
|
48
|
-
"swatchTrigger",
|
|
49
|
-
"swatchIndicator",
|
|
50
|
-
"swatch",
|
|
51
|
-
"eyeDropperTrigger",
|
|
52
|
-
"formatTrigger",
|
|
53
|
-
"formatSelect"
|
|
54
|
-
]);
|
|
55
|
-
var parts = anatomy.build();
|
|
56
|
-
|
|
57
|
-
// src/color-picker.connect.ts
|
|
58
|
-
var import_color_utils3 = require("@zag-js/color-utils");
|
|
59
|
-
var import_dom_event2 = require("@zag-js/dom-event");
|
|
60
|
-
var import_dom_query2 = require("@zag-js/dom-query");
|
|
61
|
-
var import_popper = require("@zag-js/popper");
|
|
62
|
-
|
|
63
|
-
// src/color-picker.dom.ts
|
|
64
|
-
var import_dom_event = require("@zag-js/dom-event");
|
|
65
|
-
var import_dom_query = require("@zag-js/dom-query");
|
|
66
|
-
var dom = (0, import_dom_query.createScope)({
|
|
67
|
-
getRootId: (ctx) => ctx.ids?.root ?? `color-picker:${ctx.id}`,
|
|
68
|
-
getLabelId: (ctx) => ctx.ids?.label ?? `color-picker:${ctx.id}:label`,
|
|
69
|
-
getHiddenInputId: (ctx) => `color-picker:${ctx.id}:hidden-input`,
|
|
70
|
-
getControlId: (ctx) => ctx.ids?.control ?? `color-picker:${ctx.id}:control`,
|
|
71
|
-
getTriggerId: (ctx) => ctx.ids?.trigger ?? `color-picker:${ctx.id}:trigger`,
|
|
72
|
-
getContentId: (ctx) => ctx.ids?.content ?? `color-picker:${ctx.id}:content`,
|
|
73
|
-
getPositionerId: (ctx) => `color-picker:${ctx.id}:positioner`,
|
|
74
|
-
getFormatSelectId: (ctx) => `color-picker:${ctx.id}:format-select`,
|
|
75
|
-
getAreaId: (ctx) => ctx.ids?.area ?? `color-picker:${ctx.id}:area`,
|
|
76
|
-
getAreaGradientId: (ctx) => ctx.ids?.areaGradient ?? `color-picker:${ctx.id}:area-gradient`,
|
|
77
|
-
getAreaThumbId: (ctx) => ctx.ids?.areaThumb ?? `color-picker:${ctx.id}:area-thumb`,
|
|
78
|
-
getChannelSliderId: (ctx, channel) => ctx.ids?.channelSliderTrack?.(channel) ?? `color-picker:${ctx.id}:slider-track:${channel}`,
|
|
79
|
-
getChannelSliderThumbId: (ctx, channel) => ctx.ids?.channelSliderThumb?.(channel) ?? `color-picker:${ctx.id}:slider-thumb:${channel}`,
|
|
80
|
-
getContentEl: (ctx) => dom.getById(ctx, dom.getContentId(ctx)),
|
|
81
|
-
getAreaThumbEl: (ctx) => dom.getById(ctx, dom.getAreaThumbId(ctx)),
|
|
82
|
-
getChannelSliderThumbEl: (ctx, channel) => dom.getById(ctx, dom.getChannelSliderThumbId(ctx, channel)),
|
|
83
|
-
getChannelInputEl: (ctx, channel) => {
|
|
84
|
-
return [
|
|
85
|
-
...(0, import_dom_query.queryAll)(dom.getContentEl(ctx), `input[data-channel="${channel}"]`),
|
|
86
|
-
...(0, import_dom_query.queryAll)(dom.getControlEl(ctx), `input[data-channel="${channel}"]`)
|
|
87
|
-
];
|
|
88
|
-
},
|
|
89
|
-
getFormatSelectEl: (ctx) => dom.getById(ctx, dom.getFormatSelectId(ctx)),
|
|
90
|
-
getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx)),
|
|
91
|
-
getAreaEl: (ctx) => dom.getById(ctx, dom.getAreaId(ctx)),
|
|
92
|
-
getAreaValueFromPoint(ctx, point) {
|
|
93
|
-
const areaEl = dom.getAreaEl(ctx);
|
|
94
|
-
if (!areaEl)
|
|
95
|
-
return;
|
|
96
|
-
const { percent } = (0, import_dom_event.getRelativePoint)(point, areaEl);
|
|
97
|
-
return percent;
|
|
98
|
-
},
|
|
99
|
-
getControlEl: (ctx) => dom.getById(ctx, dom.getControlId(ctx)),
|
|
100
|
-
getTriggerEl: (ctx) => dom.getById(ctx, dom.getTriggerId(ctx)),
|
|
101
|
-
getPositionerEl: (ctx) => dom.getById(ctx, dom.getPositionerId(ctx)),
|
|
102
|
-
getChannelSliderTrackEl: (ctx, channel) => {
|
|
103
|
-
return dom.getById(ctx, dom.getChannelSliderId(ctx, channel));
|
|
104
|
-
},
|
|
105
|
-
getChannelSliderValueFromPoint(ctx, point, channel) {
|
|
106
|
-
const trackEl = dom.getChannelSliderTrackEl(ctx, channel);
|
|
107
|
-
if (!trackEl)
|
|
108
|
-
return;
|
|
109
|
-
const { percent } = (0, import_dom_event.getRelativePoint)(point, trackEl);
|
|
110
|
-
return percent;
|
|
111
|
-
},
|
|
112
|
-
getChannelInputEls: (ctx) => {
|
|
113
|
-
return [
|
|
114
|
-
...(0, import_dom_query.queryAll)(dom.getContentEl(ctx), "input[data-channel]"),
|
|
115
|
-
...(0, import_dom_query.queryAll)(dom.getControlEl(ctx), "input[data-channel]")
|
|
116
|
-
];
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
// src/utils/get-channel-display-color.ts
|
|
121
|
-
var import_color_utils = require("@zag-js/color-utils");
|
|
122
|
-
function getChannelDisplayColor(color, channel) {
|
|
123
|
-
switch (channel) {
|
|
124
|
-
case "hue":
|
|
125
|
-
return (0, import_color_utils.parseColor)(`hsl(${color.getChannelValue("hue")}, 100%, 50%)`);
|
|
126
|
-
case "lightness":
|
|
127
|
-
case "brightness":
|
|
128
|
-
case "saturation":
|
|
129
|
-
case "red":
|
|
130
|
-
case "green":
|
|
131
|
-
case "blue":
|
|
132
|
-
return color.withChannelValue("alpha", 1);
|
|
133
|
-
case "alpha": {
|
|
134
|
-
return color;
|
|
135
|
-
}
|
|
136
|
-
default:
|
|
137
|
-
throw new Error("Unknown color channel: " + channel);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// src/utils/get-channel-input-value.ts
|
|
142
|
-
var import_color_utils2 = require("@zag-js/color-utils");
|
|
143
|
-
function getChannelValue(color, channel) {
|
|
144
|
-
if (channel == null)
|
|
145
|
-
return "";
|
|
146
|
-
if (channel === "hex") {
|
|
147
|
-
return color.toString("hex");
|
|
148
|
-
}
|
|
149
|
-
if (channel === "css") {
|
|
150
|
-
return color.toString("css");
|
|
151
|
-
}
|
|
152
|
-
if (channel in color) {
|
|
153
|
-
return color.getChannelValue(channel).toString();
|
|
154
|
-
}
|
|
155
|
-
const isHSL = color.getFormat() === "hsla";
|
|
156
|
-
switch (channel) {
|
|
157
|
-
case "hue":
|
|
158
|
-
return isHSL ? color.toFormat("hsla").getChannelValue("hue").toString() : color.toFormat("hsba").getChannelValue("hue").toString();
|
|
159
|
-
case "saturation":
|
|
160
|
-
return isHSL ? color.toFormat("hsla").getChannelValue("saturation").toString() : color.toFormat("hsba").getChannelValue("saturation").toString();
|
|
161
|
-
case "lightness":
|
|
162
|
-
return color.toFormat("hsla").getChannelValue("lightness").toString();
|
|
163
|
-
case "brightness":
|
|
164
|
-
return color.toFormat("hsba").getChannelValue("brightness").toString();
|
|
165
|
-
case "red":
|
|
166
|
-
case "green":
|
|
167
|
-
case "blue":
|
|
168
|
-
return color.toFormat("rgba").getChannelValue(channel).toString();
|
|
169
|
-
default:
|
|
170
|
-
return color.getChannelValue(channel).toString();
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
function getChannelRange(color, channel) {
|
|
174
|
-
switch (channel) {
|
|
175
|
-
case "hex":
|
|
176
|
-
const minColor = (0, import_color_utils2.parseColor)("#000000");
|
|
177
|
-
const maxColor = (0, import_color_utils2.parseColor)("#FFFFFF");
|
|
178
|
-
return {
|
|
179
|
-
minValue: minColor.toHexInt(),
|
|
180
|
-
maxValue: maxColor.toHexInt(),
|
|
181
|
-
pageSize: 10,
|
|
182
|
-
step: 1
|
|
183
|
-
};
|
|
184
|
-
case "css":
|
|
185
|
-
return void 0;
|
|
186
|
-
case "hue":
|
|
187
|
-
case "saturation":
|
|
188
|
-
case "lightness":
|
|
189
|
-
return color.toFormat("hsla").getChannelRange(channel);
|
|
190
|
-
case "brightness":
|
|
191
|
-
return color.toFormat("hsba").getChannelRange(channel);
|
|
192
|
-
case "red":
|
|
193
|
-
case "green":
|
|
194
|
-
case "blue":
|
|
195
|
-
return color.toFormat("rgba").getChannelRange(channel);
|
|
196
|
-
default:
|
|
197
|
-
return color.getChannelRange(channel);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// src/utils/get-slider-background.ts
|
|
202
|
-
function getSliderBackgroundDirection(orientation, dir) {
|
|
203
|
-
if (orientation === "vertical") {
|
|
204
|
-
return "top";
|
|
205
|
-
} else if (dir === "ltr") {
|
|
206
|
-
return "right";
|
|
207
|
-
} else {
|
|
208
|
-
return "left";
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
var getSliderBackground = (props) => {
|
|
212
|
-
const { channel, value, dir } = props;
|
|
213
|
-
const bgDirection = getSliderBackgroundDirection(props.orientation, dir);
|
|
214
|
-
const { minValue, maxValue } = value.getChannelRange(channel);
|
|
215
|
-
switch (channel) {
|
|
216
|
-
case "hue":
|
|
217
|
-
return `linear-gradient(to ${bgDirection}, 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%)`;
|
|
218
|
-
case "lightness": {
|
|
219
|
-
let start = value.withChannelValue(channel, minValue).toString("css");
|
|
220
|
-
let middle = value.withChannelValue(channel, (maxValue - minValue) / 2).toString("css");
|
|
221
|
-
let end = value.withChannelValue(channel, maxValue).toString("css");
|
|
222
|
-
return `linear-gradient(to ${bgDirection}, ${start}, ${middle}, ${end})`;
|
|
223
|
-
}
|
|
224
|
-
case "saturation":
|
|
225
|
-
case "brightness":
|
|
226
|
-
case "red":
|
|
227
|
-
case "green":
|
|
228
|
-
case "blue":
|
|
229
|
-
case "alpha": {
|
|
230
|
-
let start = value.withChannelValue(channel, minValue).toString("css");
|
|
231
|
-
let end = value.withChannelValue(channel, maxValue).toString("css");
|
|
232
|
-
return `linear-gradient(to ${bgDirection}, ${start}, ${end})`;
|
|
233
|
-
}
|
|
234
|
-
default:
|
|
235
|
-
throw new Error("Unknown color channel: " + channel);
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
// src/color-picker.connect.ts
|
|
240
|
-
function connect(state, send, normalize) {
|
|
241
|
-
const value = state.context.value;
|
|
242
|
-
const areaValue = state.context.areaValue;
|
|
243
|
-
const valueAsString = state.context.valueAsString;
|
|
244
|
-
const disabled = state.context.isDisabled;
|
|
245
|
-
const interactive = state.context.isInteractive;
|
|
246
|
-
const dragging = state.hasTag("dragging");
|
|
247
|
-
const open = state.hasTag("open");
|
|
248
|
-
const focused = state.hasTag("focused");
|
|
249
|
-
const getAreaChannels = (props) => {
|
|
250
|
-
const channels = areaValue.getChannels();
|
|
251
|
-
return {
|
|
252
|
-
xChannel: props.xChannel ?? channels[1],
|
|
253
|
-
yChannel: props.yChannel ?? channels[2]
|
|
254
|
-
};
|
|
255
|
-
};
|
|
256
|
-
const currentPlacement = state.context.currentPlacement;
|
|
257
|
-
const popperStyles = (0, import_popper.getPlacementStyles)({
|
|
258
|
-
...state.context.positioning,
|
|
259
|
-
placement: currentPlacement
|
|
260
|
-
});
|
|
261
|
-
function getSwatchTriggerState(props) {
|
|
262
|
-
const color = (0, import_color_utils3.normalizeColor)(props.value).toFormat(state.context.format);
|
|
263
|
-
return {
|
|
264
|
-
value: color,
|
|
265
|
-
valueAsString: color.toString("hex"),
|
|
266
|
-
checked: color.isEqual(value),
|
|
267
|
-
disabled: props.disabled || !interactive
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
return {
|
|
271
|
-
dragging,
|
|
272
|
-
open,
|
|
273
|
-
valueAsString,
|
|
274
|
-
value,
|
|
275
|
-
setOpen(nextOpen) {
|
|
276
|
-
if (nextOpen === open)
|
|
277
|
-
return;
|
|
278
|
-
send({ type: nextOpen ? "OPEN" : "CLOSE" });
|
|
279
|
-
},
|
|
280
|
-
setValue(value2) {
|
|
281
|
-
send({ type: "VALUE.SET", value: (0, import_color_utils3.normalizeColor)(value2), src: "set-color" });
|
|
282
|
-
},
|
|
283
|
-
getChannelValue(channel) {
|
|
284
|
-
return getChannelValue(value, channel);
|
|
285
|
-
},
|
|
286
|
-
setChannelValue(channel, channelValue) {
|
|
287
|
-
const color = value.withChannelValue(channel, channelValue);
|
|
288
|
-
send({ type: "VALUE.SET", value: color, src: "set-channel" });
|
|
289
|
-
},
|
|
290
|
-
format: state.context.format,
|
|
291
|
-
setFormat(format) {
|
|
292
|
-
const formatValue = value.toFormat(format);
|
|
293
|
-
send({ type: "VALUE.SET", value: formatValue, src: "set-format" });
|
|
294
|
-
},
|
|
295
|
-
alpha: value.getChannelValue("alpha"),
|
|
296
|
-
setAlpha(alphaValue) {
|
|
297
|
-
const color = value.withChannelValue("alpha", alphaValue);
|
|
298
|
-
send({ type: "VALUE.SET", value: color, src: "set-alpha" });
|
|
299
|
-
},
|
|
300
|
-
rootProps: normalize.element({
|
|
301
|
-
...parts.root.attrs,
|
|
302
|
-
dir: state.context.dir,
|
|
303
|
-
id: dom.getRootId(state.context),
|
|
304
|
-
"data-disabled": (0, import_dom_query2.dataAttr)(disabled),
|
|
305
|
-
"data-readonly": (0, import_dom_query2.dataAttr)(state.context.readOnly),
|
|
306
|
-
style: {
|
|
307
|
-
"--value": value.toString("css")
|
|
308
|
-
}
|
|
309
|
-
}),
|
|
310
|
-
labelProps: normalize.element({
|
|
311
|
-
...parts.label.attrs,
|
|
312
|
-
dir: state.context.dir,
|
|
313
|
-
id: dom.getLabelId(state.context),
|
|
314
|
-
htmlFor: dom.getHiddenInputId(state.context),
|
|
315
|
-
"data-disabled": (0, import_dom_query2.dataAttr)(disabled),
|
|
316
|
-
"data-readonly": (0, import_dom_query2.dataAttr)(state.context.readOnly),
|
|
317
|
-
"data-focus": (0, import_dom_query2.dataAttr)(focused),
|
|
318
|
-
onClick(event) {
|
|
319
|
-
event.preventDefault();
|
|
320
|
-
const inputEl = (0, import_dom_query2.query)(dom.getControlEl(state.context), "[data-channel=hex]");
|
|
321
|
-
inputEl?.focus({ preventScroll: true });
|
|
322
|
-
}
|
|
323
|
-
}),
|
|
324
|
-
controlProps: normalize.element({
|
|
325
|
-
...parts.control.attrs,
|
|
326
|
-
id: dom.getControlId(state.context),
|
|
327
|
-
dir: state.context.dir,
|
|
328
|
-
"data-disabled": (0, import_dom_query2.dataAttr)(disabled),
|
|
329
|
-
"data-readonly": (0, import_dom_query2.dataAttr)(state.context.readOnly),
|
|
330
|
-
"data-state": open ? "open" : "closed",
|
|
331
|
-
"data-focus": (0, import_dom_query2.dataAttr)(focused)
|
|
332
|
-
}),
|
|
333
|
-
triggerProps: normalize.button({
|
|
334
|
-
...parts.trigger.attrs,
|
|
335
|
-
id: dom.getTriggerId(state.context),
|
|
336
|
-
dir: state.context.dir,
|
|
337
|
-
disabled,
|
|
338
|
-
"aria-label": `select color. current color is ${valueAsString}`,
|
|
339
|
-
"aria-controls": dom.getContentId(state.context),
|
|
340
|
-
"aria-labelledby": dom.getLabelId(state.context),
|
|
341
|
-
"data-disabled": (0, import_dom_query2.dataAttr)(disabled),
|
|
342
|
-
"data-readonly": (0, import_dom_query2.dataAttr)(state.context.readOnly),
|
|
343
|
-
"data-placement": currentPlacement,
|
|
344
|
-
"aria-expanded": (0, import_dom_query2.dataAttr)(open),
|
|
345
|
-
"data-state": open ? "open" : "closed",
|
|
346
|
-
"data-focus": (0, import_dom_query2.dataAttr)(focused),
|
|
347
|
-
type: "button",
|
|
348
|
-
onClick() {
|
|
349
|
-
if (!interactive)
|
|
350
|
-
return;
|
|
351
|
-
send({ type: "TRIGGER.CLICK" });
|
|
352
|
-
},
|
|
353
|
-
onBlur() {
|
|
354
|
-
if (!interactive)
|
|
355
|
-
return;
|
|
356
|
-
send({ type: "TRIGGER.BLUR" });
|
|
357
|
-
},
|
|
358
|
-
style: {
|
|
359
|
-
position: "relative"
|
|
360
|
-
}
|
|
361
|
-
}),
|
|
362
|
-
positionerProps: normalize.element({
|
|
363
|
-
...parts.positioner.attrs,
|
|
364
|
-
id: dom.getPositionerId(state.context),
|
|
365
|
-
dir: state.context.dir,
|
|
366
|
-
style: popperStyles.floating
|
|
367
|
-
}),
|
|
368
|
-
contentProps: normalize.element({
|
|
369
|
-
...parts.content.attrs,
|
|
370
|
-
id: dom.getContentId(state.context),
|
|
371
|
-
dir: state.context.dir,
|
|
372
|
-
"data-placement": currentPlacement,
|
|
373
|
-
"data-state": open ? "open" : "closed",
|
|
374
|
-
hidden: !open
|
|
375
|
-
}),
|
|
376
|
-
getAreaProps(props = {}) {
|
|
377
|
-
const { xChannel, yChannel } = getAreaChannels(props);
|
|
378
|
-
const { areaStyles } = (0, import_color_utils3.getColorAreaGradient)(areaValue, {
|
|
379
|
-
xChannel,
|
|
380
|
-
yChannel,
|
|
381
|
-
dir: state.context.dir
|
|
382
|
-
});
|
|
383
|
-
return normalize.element({
|
|
384
|
-
...parts.area.attrs,
|
|
385
|
-
id: dom.getAreaId(state.context),
|
|
386
|
-
role: "group",
|
|
387
|
-
onPointerDown(event) {
|
|
388
|
-
if (!interactive)
|
|
389
|
-
return;
|
|
390
|
-
const evt = (0, import_dom_event2.getNativeEvent)(event);
|
|
391
|
-
if (!(0, import_dom_event2.isLeftClick)(evt) || (0, import_dom_event2.isModifierKey)(evt))
|
|
392
|
-
return;
|
|
393
|
-
const point = (0, import_dom_event2.getEventPoint)(evt);
|
|
394
|
-
const channel = { xChannel, yChannel };
|
|
395
|
-
send({ type: "AREA.POINTER_DOWN", point, channel, id: "area" });
|
|
396
|
-
event.preventDefault();
|
|
397
|
-
},
|
|
398
|
-
style: {
|
|
399
|
-
position: "relative",
|
|
400
|
-
touchAction: "none",
|
|
401
|
-
forcedColorAdjust: "none",
|
|
402
|
-
...areaStyles
|
|
403
|
-
}
|
|
404
|
-
});
|
|
405
|
-
},
|
|
406
|
-
getAreaBackgroundProps(props = {}) {
|
|
407
|
-
const { xChannel, yChannel } = getAreaChannels(props);
|
|
408
|
-
const { areaGradientStyles } = (0, import_color_utils3.getColorAreaGradient)(areaValue, {
|
|
409
|
-
xChannel,
|
|
410
|
-
yChannel,
|
|
411
|
-
dir: state.context.dir
|
|
412
|
-
});
|
|
413
|
-
return normalize.element({
|
|
414
|
-
...parts.areaBackground.attrs,
|
|
415
|
-
id: dom.getAreaGradientId(state.context),
|
|
416
|
-
style: {
|
|
417
|
-
position: "relative",
|
|
418
|
-
touchAction: "none",
|
|
419
|
-
forcedColorAdjust: "none",
|
|
420
|
-
...areaGradientStyles
|
|
421
|
-
}
|
|
422
|
-
});
|
|
423
|
-
},
|
|
424
|
-
getAreaThumbProps(props = {}) {
|
|
425
|
-
const { xChannel, yChannel } = getAreaChannels(props);
|
|
426
|
-
const channel = { xChannel, yChannel };
|
|
427
|
-
const xPercent = areaValue.getChannelValuePercent(xChannel);
|
|
428
|
-
const yPercent = 1 - areaValue.getChannelValuePercent(yChannel);
|
|
429
|
-
const xValue = areaValue.getChannelValue(xChannel);
|
|
430
|
-
const yValue = areaValue.getChannelValue(yChannel);
|
|
431
|
-
return normalize.element({
|
|
432
|
-
...parts.areaThumb.attrs,
|
|
433
|
-
id: dom.getAreaThumbId(state.context),
|
|
434
|
-
dir: state.context.dir,
|
|
435
|
-
tabIndex: disabled ? void 0 : 0,
|
|
436
|
-
"data-disabled": (0, import_dom_query2.dataAttr)(disabled),
|
|
437
|
-
role: "slider",
|
|
438
|
-
"aria-valuemin": 0,
|
|
439
|
-
"aria-valuemax": 100,
|
|
440
|
-
"aria-valuenow": xValue,
|
|
441
|
-
"aria-label": `${xChannel} and ${yChannel}`,
|
|
442
|
-
"aria-roledescription": "2d slider",
|
|
443
|
-
"aria-valuetext": `${xChannel} ${xValue}, ${yChannel} ${yValue}`,
|
|
444
|
-
style: {
|
|
445
|
-
position: "absolute",
|
|
446
|
-
left: `${xPercent * 100}%`,
|
|
447
|
-
top: `${yPercent * 100}%`,
|
|
448
|
-
transform: "translate(-50%, -50%)",
|
|
449
|
-
touchAction: "none",
|
|
450
|
-
forcedColorAdjust: "none",
|
|
451
|
-
background: areaValue.withChannelValue("alpha", 1).toString("css")
|
|
452
|
-
},
|
|
453
|
-
onFocus() {
|
|
454
|
-
if (!interactive)
|
|
455
|
-
return;
|
|
456
|
-
send({ type: "AREA.FOCUS", id: "area", channel });
|
|
457
|
-
},
|
|
458
|
-
onKeyDown(event) {
|
|
459
|
-
if (event.defaultPrevented)
|
|
460
|
-
return;
|
|
461
|
-
if (!interactive)
|
|
462
|
-
return;
|
|
463
|
-
const step = (0, import_dom_event2.getEventStep)(event);
|
|
464
|
-
const keyMap = {
|
|
465
|
-
ArrowUp() {
|
|
466
|
-
send({ type: "AREA.ARROW_UP", channel, step });
|
|
467
|
-
},
|
|
468
|
-
ArrowDown() {
|
|
469
|
-
send({ type: "AREA.ARROW_DOWN", channel, step });
|
|
470
|
-
},
|
|
471
|
-
ArrowLeft() {
|
|
472
|
-
send({ type: "AREA.ARROW_LEFT", channel, step });
|
|
473
|
-
},
|
|
474
|
-
ArrowRight() {
|
|
475
|
-
send({ type: "AREA.ARROW_RIGHT", channel, step });
|
|
476
|
-
},
|
|
477
|
-
PageUp() {
|
|
478
|
-
send({ type: "AREA.PAGE_UP", channel, step });
|
|
479
|
-
},
|
|
480
|
-
PageDown() {
|
|
481
|
-
send({ type: "AREA.PAGE_DOWN", channel, step });
|
|
482
|
-
},
|
|
483
|
-
Escape(event2) {
|
|
484
|
-
event2.stopPropagation();
|
|
485
|
-
}
|
|
486
|
-
};
|
|
487
|
-
const exec = keyMap[(0, import_dom_event2.getEventKey)(event, state.context)];
|
|
488
|
-
if (exec) {
|
|
489
|
-
exec(event);
|
|
490
|
-
event.preventDefault();
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
});
|
|
494
|
-
},
|
|
495
|
-
getTransparencyGridProps(props = {}) {
|
|
496
|
-
const { size = "12px" } = props;
|
|
497
|
-
return normalize.element({
|
|
498
|
-
...parts.transparencyGrid.attrs,
|
|
499
|
-
style: {
|
|
500
|
-
"--size": size,
|
|
501
|
-
width: "100%",
|
|
502
|
-
height: "100%",
|
|
503
|
-
position: "absolute",
|
|
504
|
-
backgroundColor: "#fff",
|
|
505
|
-
backgroundImage: "conic-gradient(#eeeeee 0 25%, transparent 0 50%, #eeeeee 0 75%, transparent 0)",
|
|
506
|
-
backgroundSize: "var(--size) var(--size)",
|
|
507
|
-
inset: "0px",
|
|
508
|
-
zIndex: "auto",
|
|
509
|
-
pointerEvents: "none"
|
|
510
|
-
}
|
|
511
|
-
});
|
|
512
|
-
},
|
|
513
|
-
getChannelSliderProps(props) {
|
|
514
|
-
const { orientation = "horizontal", channel } = props;
|
|
515
|
-
return normalize.element({
|
|
516
|
-
...parts.channelSlider.attrs,
|
|
517
|
-
"data-channel": channel,
|
|
518
|
-
"data-orientation": orientation,
|
|
519
|
-
role: "presentation",
|
|
520
|
-
onPointerDown(event) {
|
|
521
|
-
if (!interactive)
|
|
522
|
-
return;
|
|
523
|
-
const evt = (0, import_dom_event2.getNativeEvent)(event);
|
|
524
|
-
if (!(0, import_dom_event2.isLeftClick)(evt) || (0, import_dom_event2.isModifierKey)(evt))
|
|
525
|
-
return;
|
|
526
|
-
const point = (0, import_dom_event2.getEventPoint)(evt);
|
|
527
|
-
send({ type: "CHANNEL_SLIDER.POINTER_DOWN", channel, point, id: channel, orientation });
|
|
528
|
-
event.preventDefault();
|
|
529
|
-
},
|
|
530
|
-
style: {
|
|
531
|
-
position: "relative",
|
|
532
|
-
touchAction: "none"
|
|
533
|
-
}
|
|
534
|
-
});
|
|
535
|
-
},
|
|
536
|
-
getChannelSliderTrackProps(props) {
|
|
537
|
-
const { orientation = "horizontal", channel } = props;
|
|
538
|
-
return normalize.element({
|
|
539
|
-
...parts.channelSliderTrack.attrs,
|
|
540
|
-
id: dom.getChannelSliderId(state.context, channel),
|
|
541
|
-
role: "group",
|
|
542
|
-
"data-channel": channel,
|
|
543
|
-
"data-orientation": orientation,
|
|
544
|
-
style: {
|
|
545
|
-
position: "relative",
|
|
546
|
-
forcedColorAdjust: "none",
|
|
547
|
-
backgroundImage: getSliderBackground({
|
|
548
|
-
orientation,
|
|
549
|
-
channel,
|
|
550
|
-
dir: state.context.dir,
|
|
551
|
-
value: areaValue
|
|
552
|
-
})
|
|
553
|
-
}
|
|
554
|
-
});
|
|
555
|
-
},
|
|
556
|
-
getChannelSliderThumbProps(props) {
|
|
557
|
-
const { orientation = "horizontal", channel } = props;
|
|
558
|
-
const { minValue, maxValue, step: stepValue } = areaValue.getChannelRange(channel);
|
|
559
|
-
const channelValue = areaValue.getChannelValue(channel);
|
|
560
|
-
const offset = (channelValue - minValue) / (maxValue - minValue);
|
|
561
|
-
const placementStyles = orientation === "horizontal" ? { left: `${offset * 100}%`, top: "50%" } : { top: `${offset * 100}%`, left: "50%" };
|
|
562
|
-
return normalize.element({
|
|
563
|
-
...parts.channelSliderThumb.attrs,
|
|
564
|
-
id: dom.getChannelSliderThumbId(state.context, channel),
|
|
565
|
-
role: "slider",
|
|
566
|
-
"aria-label": channel,
|
|
567
|
-
tabIndex: disabled ? void 0 : 0,
|
|
568
|
-
"data-channel": channel,
|
|
569
|
-
"data-disabled": (0, import_dom_query2.dataAttr)(disabled),
|
|
570
|
-
"data-orientation": orientation,
|
|
571
|
-
"aria-disabled": (0, import_dom_query2.dataAttr)(disabled),
|
|
572
|
-
"aria-orientation": orientation,
|
|
573
|
-
"aria-valuemax": maxValue,
|
|
574
|
-
"aria-valuemin": minValue,
|
|
575
|
-
"aria-valuenow": channelValue,
|
|
576
|
-
"aria-valuetext": `${channel} ${channelValue}`,
|
|
577
|
-
style: {
|
|
578
|
-
forcedColorAdjust: "none",
|
|
579
|
-
position: "absolute",
|
|
580
|
-
background: getChannelDisplayColor(areaValue, channel).toString("css"),
|
|
581
|
-
...placementStyles
|
|
582
|
-
},
|
|
583
|
-
onFocus() {
|
|
584
|
-
if (!interactive)
|
|
585
|
-
return;
|
|
586
|
-
send({ type: "CHANNEL_SLIDER.FOCUS", channel });
|
|
587
|
-
},
|
|
588
|
-
onKeyDown(event) {
|
|
589
|
-
if (event.defaultPrevented)
|
|
590
|
-
return;
|
|
591
|
-
if (!interactive)
|
|
592
|
-
return;
|
|
593
|
-
const step = (0, import_dom_event2.getEventStep)(event) * stepValue;
|
|
594
|
-
const keyMap = {
|
|
595
|
-
ArrowUp() {
|
|
596
|
-
send({ type: "CHANNEL_SLIDER.ARROW_UP", channel, step });
|
|
597
|
-
},
|
|
598
|
-
ArrowDown() {
|
|
599
|
-
send({ type: "CHANNEL_SLIDER.ARROW_DOWN", channel, step });
|
|
600
|
-
},
|
|
601
|
-
ArrowLeft() {
|
|
602
|
-
send({ type: "CHANNEL_SLIDER.ARROW_LEFT", channel, step });
|
|
603
|
-
},
|
|
604
|
-
ArrowRight() {
|
|
605
|
-
send({ type: "CHANNEL_SLIDER.ARROW_RIGHT", channel, step });
|
|
606
|
-
},
|
|
607
|
-
PageUp() {
|
|
608
|
-
send({ type: "CHANNEL_SLIDER.PAGE_UP", channel });
|
|
609
|
-
},
|
|
610
|
-
PageDown() {
|
|
611
|
-
send({ type: "CHANNEL_SLIDER.PAGE_DOWN", channel });
|
|
612
|
-
},
|
|
613
|
-
Home() {
|
|
614
|
-
send({ type: "CHANNEL_SLIDER.HOME", channel });
|
|
615
|
-
},
|
|
616
|
-
End() {
|
|
617
|
-
send({ type: "CHANNEL_SLIDER.END", channel });
|
|
618
|
-
},
|
|
619
|
-
Escape(event2) {
|
|
620
|
-
event2.stopPropagation();
|
|
621
|
-
}
|
|
622
|
-
};
|
|
623
|
-
const exec = keyMap[(0, import_dom_event2.getEventKey)(event, state.context)];
|
|
624
|
-
if (exec) {
|
|
625
|
-
exec(event);
|
|
626
|
-
event.preventDefault();
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
});
|
|
630
|
-
},
|
|
631
|
-
getChannelInputProps(props) {
|
|
632
|
-
const { channel } = props;
|
|
633
|
-
const isTextField = channel === "hex" || channel === "css";
|
|
634
|
-
const range = getChannelRange(value, channel);
|
|
635
|
-
return normalize.input({
|
|
636
|
-
...parts.channelInput.attrs,
|
|
637
|
-
dir: state.context.dir,
|
|
638
|
-
type: isTextField ? "text" : "number",
|
|
639
|
-
"data-channel": channel,
|
|
640
|
-
"aria-label": channel,
|
|
641
|
-
spellCheck: false,
|
|
642
|
-
autoComplete: "off",
|
|
643
|
-
disabled,
|
|
644
|
-
"data-disabled": (0, import_dom_query2.dataAttr)(disabled),
|
|
645
|
-
readOnly: state.context.readOnly,
|
|
646
|
-
defaultValue: getChannelValue(value, channel),
|
|
647
|
-
min: range?.minValue,
|
|
648
|
-
max: range?.maxValue,
|
|
649
|
-
step: range?.step,
|
|
650
|
-
onBeforeInput(event) {
|
|
651
|
-
if (isTextField || !interactive)
|
|
652
|
-
return;
|
|
653
|
-
const value2 = event.currentTarget.value;
|
|
654
|
-
if (value2.match(/[^0-9.]/g)) {
|
|
655
|
-
event.preventDefault();
|
|
656
|
-
}
|
|
657
|
-
},
|
|
658
|
-
onFocus(event) {
|
|
659
|
-
if (!interactive)
|
|
660
|
-
return;
|
|
661
|
-
send({ type: "CHANNEL_INPUT.FOCUS", channel });
|
|
662
|
-
event.target.select();
|
|
663
|
-
},
|
|
664
|
-
onBlur(event) {
|
|
665
|
-
if (!interactive)
|
|
666
|
-
return;
|
|
667
|
-
const value2 = isTextField ? event.currentTarget.value : event.currentTarget.valueAsNumber;
|
|
668
|
-
send({ type: "CHANNEL_INPUT.BLUR", channel, value: value2, isTextField });
|
|
669
|
-
},
|
|
670
|
-
onKeyDown(event) {
|
|
671
|
-
if (event.defaultPrevented)
|
|
672
|
-
return;
|
|
673
|
-
if (!interactive)
|
|
674
|
-
return;
|
|
675
|
-
if (event.key === "Enter") {
|
|
676
|
-
const value2 = isTextField ? event.currentTarget.value : event.currentTarget.valueAsNumber;
|
|
677
|
-
send({ type: "CHANNEL_INPUT.CHANGE", channel, value: value2, isTextField });
|
|
678
|
-
event.preventDefault();
|
|
679
|
-
}
|
|
680
|
-
},
|
|
681
|
-
style: {
|
|
682
|
-
appearance: "none",
|
|
683
|
-
WebkitAppearance: "none",
|
|
684
|
-
MozAppearance: "textfield"
|
|
685
|
-
}
|
|
686
|
-
});
|
|
687
|
-
},
|
|
688
|
-
hiddenInputProps: normalize.input({
|
|
689
|
-
type: "text",
|
|
690
|
-
disabled,
|
|
691
|
-
name: state.context.name,
|
|
692
|
-
id: dom.getHiddenInputId(state.context),
|
|
693
|
-
style: import_dom_query2.visuallyHiddenStyle,
|
|
694
|
-
defaultValue: valueAsString
|
|
695
|
-
}),
|
|
696
|
-
eyeDropperTriggerProps: normalize.button({
|
|
697
|
-
...parts.eyeDropperTrigger.attrs,
|
|
698
|
-
type: "button",
|
|
699
|
-
dir: state.context.dir,
|
|
700
|
-
disabled,
|
|
701
|
-
"data-disabled": (0, import_dom_query2.dataAttr)(disabled),
|
|
702
|
-
"aria-label": "Pick a color from the screen",
|
|
703
|
-
onClick() {
|
|
704
|
-
if (!interactive)
|
|
705
|
-
return;
|
|
706
|
-
send("EYEDROPPER.CLICK");
|
|
707
|
-
}
|
|
708
|
-
}),
|
|
709
|
-
swatchGroupProps: normalize.element({
|
|
710
|
-
...parts.swatchGroup.attrs,
|
|
711
|
-
role: "group"
|
|
712
|
-
}),
|
|
713
|
-
getSwatchTriggerState,
|
|
714
|
-
getSwatchTriggerProps(props) {
|
|
715
|
-
const triggerState = getSwatchTriggerState(props);
|
|
716
|
-
return normalize.button({
|
|
717
|
-
...parts.swatchTrigger.attrs,
|
|
718
|
-
disabled: triggerState.disabled,
|
|
719
|
-
dir: state.context.dir,
|
|
720
|
-
type: "button",
|
|
721
|
-
"aria-label": `select ${triggerState.valueAsString} as the color`,
|
|
722
|
-
"data-state": triggerState.checked ? "checked" : "unchecked",
|
|
723
|
-
"data-value": triggerState.valueAsString,
|
|
724
|
-
"data-disabled": (0, import_dom_query2.dataAttr)(triggerState.disabled),
|
|
725
|
-
onClick() {
|
|
726
|
-
if (triggerState.disabled)
|
|
727
|
-
return;
|
|
728
|
-
send({ type: "SWATCH_TRIGGER.CLICK", value: triggerState.value });
|
|
729
|
-
},
|
|
730
|
-
style: {
|
|
731
|
-
position: "relative"
|
|
732
|
-
}
|
|
733
|
-
});
|
|
734
|
-
},
|
|
735
|
-
getSwatchIndicatorProps(props) {
|
|
736
|
-
const triggerState = getSwatchTriggerState(props);
|
|
737
|
-
return normalize.element({
|
|
738
|
-
...parts.swatchIndicator.attrs,
|
|
739
|
-
dir: state.context.dir,
|
|
740
|
-
hidden: !triggerState.checked
|
|
741
|
-
});
|
|
742
|
-
},
|
|
743
|
-
getSwatchProps(props) {
|
|
744
|
-
const { respectAlpha = true } = props;
|
|
745
|
-
const triggerState = getSwatchTriggerState(props);
|
|
746
|
-
return normalize.element({
|
|
747
|
-
...parts.swatch.attrs,
|
|
748
|
-
dir: state.context.dir,
|
|
749
|
-
"data-state": triggerState.checked ? "checked" : "unchecked",
|
|
750
|
-
"data-value": triggerState.valueAsString,
|
|
751
|
-
style: {
|
|
752
|
-
position: "relative",
|
|
753
|
-
background: triggerState.value.toString(respectAlpha ? "css" : "hex")
|
|
754
|
-
}
|
|
755
|
-
});
|
|
756
|
-
},
|
|
757
|
-
formatTriggerProps: normalize.button({
|
|
758
|
-
...parts.formatTrigger.attrs,
|
|
759
|
-
dir: state.context.dir,
|
|
760
|
-
type: "button",
|
|
761
|
-
"aria-label": `change color format to ${getNextFormat(state.context.format)}`,
|
|
762
|
-
onClick(event) {
|
|
763
|
-
if (event.currentTarget.disabled)
|
|
764
|
-
return;
|
|
765
|
-
const nextFormat = getNextFormat(state.context.format);
|
|
766
|
-
send({ type: "FORMAT.SET", format: nextFormat, src: "format-trigger" });
|
|
767
|
-
}
|
|
768
|
-
}),
|
|
769
|
-
formatSelectProps: normalize.select({
|
|
770
|
-
...parts.formatSelect.attrs,
|
|
771
|
-
"aria-label": "change color format",
|
|
772
|
-
dir: state.context.dir,
|
|
773
|
-
defaultValue: state.context.format,
|
|
774
|
-
disabled,
|
|
775
|
-
onChange(event) {
|
|
776
|
-
const format = assertFormat(event.currentTarget.value);
|
|
777
|
-
send({ type: "FORMAT.SET", format, src: "format-select" });
|
|
778
|
-
}
|
|
779
|
-
})
|
|
780
|
-
};
|
|
781
|
-
}
|
|
782
|
-
var formats = ["hsba", "hsla", "rgba"];
|
|
783
|
-
var formatRegex = new RegExp(`^(${formats.join("|")})$`);
|
|
784
|
-
function getNextFormat(format) {
|
|
785
|
-
const index = formats.indexOf(format);
|
|
786
|
-
return formats[index + 1] ?? formats[0];
|
|
787
|
-
}
|
|
788
|
-
function assertFormat(format) {
|
|
789
|
-
if (formatRegex.test(format))
|
|
790
|
-
return format;
|
|
791
|
-
throw new Error(`Unsupported color format: ${format}`);
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
// src/color-picker.machine.ts
|
|
795
|
-
var import_color_utils5 = require("@zag-js/color-utils");
|
|
796
|
-
var import_core = require("@zag-js/core");
|
|
797
|
-
var import_dismissable = require("@zag-js/dismissable");
|
|
798
|
-
var import_dom_event3 = require("@zag-js/dom-event");
|
|
799
|
-
var import_dom_query3 = require("@zag-js/dom-query");
|
|
800
|
-
var import_form_utils = require("@zag-js/form-utils");
|
|
801
|
-
var import_popper2 = require("@zag-js/popper");
|
|
802
|
-
var import_text_selection = require("@zag-js/text-selection");
|
|
803
|
-
var import_utils = require("@zag-js/utils");
|
|
804
|
-
|
|
805
|
-
// src/color-picker.parse.ts
|
|
806
|
-
var import_color_utils4 = require("@zag-js/color-utils");
|
|
807
|
-
var parse = (colorString) => {
|
|
808
|
-
return (0, import_color_utils4.parseColor)(colorString);
|
|
809
|
-
};
|
|
810
|
-
|
|
811
|
-
// src/color-picker.machine.ts
|
|
812
|
-
var { and } = import_core.guards;
|
|
813
|
-
function machine(userContext) {
|
|
814
|
-
const ctx = (0, import_utils.compact)(userContext);
|
|
815
|
-
return (0, import_core.createMachine)(
|
|
816
|
-
{
|
|
817
|
-
id: "color-picker",
|
|
818
|
-
initial: ctx.open ? "open" : "idle",
|
|
819
|
-
context: {
|
|
820
|
-
dir: "ltr",
|
|
821
|
-
value: parse("#000000"),
|
|
822
|
-
format: "rgba",
|
|
823
|
-
disabled: false,
|
|
824
|
-
closeOnSelect: false,
|
|
825
|
-
...ctx,
|
|
826
|
-
activeId: null,
|
|
827
|
-
activeChannel: null,
|
|
828
|
-
activeOrientation: null,
|
|
829
|
-
fieldsetDisabled: false,
|
|
830
|
-
restoreFocus: true,
|
|
831
|
-
positioning: {
|
|
832
|
-
...ctx.positioning,
|
|
833
|
-
placement: "bottom"
|
|
834
|
-
}
|
|
835
|
-
},
|
|
836
|
-
computed: {
|
|
837
|
-
isRtl: (ctx2) => ctx2.dir === "rtl",
|
|
838
|
-
isDisabled: (ctx2) => !!ctx2.disabled || ctx2.fieldsetDisabled,
|
|
839
|
-
isInteractive: (ctx2) => !(ctx2.isDisabled || ctx2.readOnly),
|
|
840
|
-
valueAsString: (ctx2) => ctx2.value.toString(ctx2.format),
|
|
841
|
-
areaValue: (ctx2) => {
|
|
842
|
-
const format = ctx2.format.startsWith("hsl") ? "hsla" : "hsba";
|
|
843
|
-
return ctx2.value.toFormat(format);
|
|
844
|
-
}
|
|
845
|
-
},
|
|
846
|
-
activities: ["trackFormControl"],
|
|
847
|
-
watch: {
|
|
848
|
-
value: ["syncInputElements"],
|
|
849
|
-
format: ["syncFormatSelectElement"],
|
|
850
|
-
open: ["toggleVisibility"]
|
|
851
|
-
},
|
|
852
|
-
on: {
|
|
853
|
-
"VALUE.SET": {
|
|
854
|
-
actions: ["setValue"]
|
|
855
|
-
},
|
|
856
|
-
"FORMAT.SET": {
|
|
857
|
-
actions: ["setFormat"]
|
|
858
|
-
},
|
|
859
|
-
"CHANNEL_INPUT.CHANGE": {
|
|
860
|
-
actions: ["setChannelColorFromInput"]
|
|
861
|
-
},
|
|
862
|
-
"EYEDROPPER.CLICK": {
|
|
863
|
-
actions: ["openEyeDropper"]
|
|
864
|
-
}
|
|
865
|
-
},
|
|
866
|
-
states: {
|
|
867
|
-
idle: {
|
|
868
|
-
tags: ["closed"],
|
|
869
|
-
on: {
|
|
870
|
-
"CONTROLLED.OPEN": {
|
|
871
|
-
target: "open",
|
|
872
|
-
actions: ["setInitialFocus"]
|
|
873
|
-
},
|
|
874
|
-
OPEN: [
|
|
875
|
-
{
|
|
876
|
-
guard: "isOpenControlled",
|
|
877
|
-
actions: ["invokeOnOpen"]
|
|
878
|
-
},
|
|
879
|
-
{
|
|
880
|
-
target: "open",
|
|
881
|
-
actions: ["invokeOnOpen", "setInitialFocus"]
|
|
882
|
-
}
|
|
883
|
-
],
|
|
884
|
-
"TRIGGER.CLICK": [
|
|
885
|
-
{
|
|
886
|
-
guard: "isOpenControlled",
|
|
887
|
-
actions: ["invokeOnOpen"]
|
|
888
|
-
},
|
|
889
|
-
{
|
|
890
|
-
target: "open",
|
|
891
|
-
actions: ["invokeOnOpen", "setInitialFocus"]
|
|
892
|
-
}
|
|
893
|
-
],
|
|
894
|
-
"CHANNEL_INPUT.FOCUS": {
|
|
895
|
-
target: "focused",
|
|
896
|
-
actions: ["setActiveChannel"]
|
|
897
|
-
}
|
|
898
|
-
}
|
|
899
|
-
},
|
|
900
|
-
focused: {
|
|
901
|
-
tags: ["closed", "focused"],
|
|
902
|
-
on: {
|
|
903
|
-
"CONTROLLED.OPEN": {
|
|
904
|
-
target: "open",
|
|
905
|
-
actions: ["setInitialFocus"]
|
|
906
|
-
},
|
|
907
|
-
OPEN: [
|
|
908
|
-
{
|
|
909
|
-
guard: "isOpenControlled",
|
|
910
|
-
actions: ["invokeOnOpen"]
|
|
911
|
-
},
|
|
912
|
-
{
|
|
913
|
-
target: "open",
|
|
914
|
-
actions: ["invokeOnOpen", "setInitialFocus"]
|
|
915
|
-
}
|
|
916
|
-
],
|
|
917
|
-
"TRIGGER.CLICK": [
|
|
918
|
-
{
|
|
919
|
-
guard: "isOpenControlled",
|
|
920
|
-
actions: ["invokeOnOpen"]
|
|
921
|
-
},
|
|
922
|
-
{
|
|
923
|
-
target: "open",
|
|
924
|
-
actions: ["invokeOnOpen", "setInitialFocus"]
|
|
925
|
-
}
|
|
926
|
-
],
|
|
927
|
-
"CHANNEL_INPUT.FOCUS": {
|
|
928
|
-
actions: ["setActiveChannel"]
|
|
929
|
-
},
|
|
930
|
-
"CHANNEL_INPUT.BLUR": {
|
|
931
|
-
target: "idle",
|
|
932
|
-
actions: ["setChannelColorFromInput"]
|
|
933
|
-
},
|
|
934
|
-
"TRIGGER.BLUR": {
|
|
935
|
-
target: "idle"
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
},
|
|
939
|
-
open: {
|
|
940
|
-
tags: ["open"],
|
|
941
|
-
activities: ["trackPositioning", "trackDismissableElement"],
|
|
942
|
-
on: {
|
|
943
|
-
"CONTROLLED.CLOSE": [
|
|
944
|
-
{
|
|
945
|
-
guard: "shouldRestoreFocus",
|
|
946
|
-
target: "focused",
|
|
947
|
-
actions: ["setReturnFocus"]
|
|
948
|
-
},
|
|
949
|
-
{
|
|
950
|
-
target: "idle"
|
|
951
|
-
}
|
|
952
|
-
],
|
|
953
|
-
"TRIGGER.CLICK": [
|
|
954
|
-
{
|
|
955
|
-
guard: "isOpenControlled",
|
|
956
|
-
actions: ["invokeOnClose"]
|
|
957
|
-
},
|
|
958
|
-
{
|
|
959
|
-
target: "idle",
|
|
960
|
-
actions: ["invokeOnClose"]
|
|
961
|
-
}
|
|
962
|
-
],
|
|
963
|
-
"AREA.POINTER_DOWN": {
|
|
964
|
-
target: "open:dragging",
|
|
965
|
-
actions: ["setActiveChannel", "setAreaColorFromPoint", "focusAreaThumb"]
|
|
966
|
-
},
|
|
967
|
-
"AREA.FOCUS": {
|
|
968
|
-
actions: ["setActiveChannel"]
|
|
969
|
-
},
|
|
970
|
-
"CHANNEL_SLIDER.POINTER_DOWN": {
|
|
971
|
-
target: "open:dragging",
|
|
972
|
-
actions: ["setActiveChannel", "setChannelColorFromPoint", "focusChannelThumb"]
|
|
973
|
-
},
|
|
974
|
-
"CHANNEL_SLIDER.FOCUS": {
|
|
975
|
-
actions: ["setActiveChannel"]
|
|
976
|
-
},
|
|
977
|
-
"AREA.ARROW_LEFT": {
|
|
978
|
-
actions: ["decrementXChannel"]
|
|
979
|
-
},
|
|
980
|
-
"AREA.ARROW_RIGHT": {
|
|
981
|
-
actions: ["incrementXChannel"]
|
|
982
|
-
},
|
|
983
|
-
"AREA.ARROW_UP": {
|
|
984
|
-
actions: ["incrementYChannel"]
|
|
985
|
-
},
|
|
986
|
-
"AREA.ARROW_DOWN": {
|
|
987
|
-
actions: ["decrementYChannel"]
|
|
988
|
-
},
|
|
989
|
-
"AREA.PAGE_UP": {
|
|
990
|
-
actions: ["incrementXChannel"]
|
|
991
|
-
},
|
|
992
|
-
"AREA.PAGE_DOWN": {
|
|
993
|
-
actions: ["decrementXChannel"]
|
|
994
|
-
},
|
|
995
|
-
"CHANNEL_SLIDER.ARROW_LEFT": {
|
|
996
|
-
actions: ["decrementChannel"]
|
|
997
|
-
},
|
|
998
|
-
"CHANNEL_SLIDER.ARROW_RIGHT": {
|
|
999
|
-
actions: ["incrementChannel"]
|
|
1000
|
-
},
|
|
1001
|
-
"CHANNEL_SLIDER.ARROW_UP": {
|
|
1002
|
-
actions: ["incrementChannel"]
|
|
1003
|
-
},
|
|
1004
|
-
"CHANNEL_SLIDER.ARROW_DOWN": {
|
|
1005
|
-
actions: ["decrementChannel"]
|
|
1006
|
-
},
|
|
1007
|
-
"CHANNEL_SLIDER.PAGE_UP": {
|
|
1008
|
-
actions: ["incrementChannel"]
|
|
1009
|
-
},
|
|
1010
|
-
"CHANNEL_SLIDER.PAGE_DOWN": {
|
|
1011
|
-
actions: ["decrementChannel"]
|
|
1012
|
-
},
|
|
1013
|
-
"CHANNEL_SLIDER.HOME": {
|
|
1014
|
-
actions: ["setChannelToMin"]
|
|
1015
|
-
},
|
|
1016
|
-
"CHANNEL_SLIDER.END": {
|
|
1017
|
-
actions: ["setChannelToMax"]
|
|
1018
|
-
},
|
|
1019
|
-
"CHANNEL_INPUT.BLUR": {
|
|
1020
|
-
actions: ["setChannelColorFromInput"]
|
|
1021
|
-
},
|
|
1022
|
-
INTERACT_OUTSIDE: [
|
|
1023
|
-
{
|
|
1024
|
-
guard: "isOpenControlled",
|
|
1025
|
-
actions: ["invokeOnClose"]
|
|
1026
|
-
},
|
|
1027
|
-
{
|
|
1028
|
-
guard: "shouldRestoreFocus",
|
|
1029
|
-
target: "focused",
|
|
1030
|
-
actions: ["invokeOnClose", "setReturnFocus"]
|
|
1031
|
-
},
|
|
1032
|
-
{
|
|
1033
|
-
target: "idle",
|
|
1034
|
-
actions: ["invokeOnClose"]
|
|
1035
|
-
}
|
|
1036
|
-
],
|
|
1037
|
-
CLOSE: [
|
|
1038
|
-
{
|
|
1039
|
-
guard: "isOpenControlled",
|
|
1040
|
-
actions: ["invokeOnClose"]
|
|
1041
|
-
},
|
|
1042
|
-
{
|
|
1043
|
-
target: "idle",
|
|
1044
|
-
actions: ["invokeOnClose"]
|
|
1045
|
-
}
|
|
1046
|
-
],
|
|
1047
|
-
"SWATCH_TRIGGER.CLICK": [
|
|
1048
|
-
{
|
|
1049
|
-
guard: and("isOpenControlled", "closeOnSelect"),
|
|
1050
|
-
actions: ["setValue", "invokeOnClose"]
|
|
1051
|
-
},
|
|
1052
|
-
{
|
|
1053
|
-
guard: "closeOnSelect",
|
|
1054
|
-
target: "focused",
|
|
1055
|
-
actions: ["setValue", "invokeOnClose", "setReturnFocus"]
|
|
1056
|
-
},
|
|
1057
|
-
{
|
|
1058
|
-
actions: ["setValue"]
|
|
1059
|
-
}
|
|
1060
|
-
]
|
|
1061
|
-
}
|
|
1062
|
-
},
|
|
1063
|
-
"open:dragging": {
|
|
1064
|
-
tags: ["open"],
|
|
1065
|
-
exit: ["clearActiveChannel"],
|
|
1066
|
-
activities: ["trackPointerMove", "disableTextSelection", "trackPositioning", "trackDismissableElement"],
|
|
1067
|
-
on: {
|
|
1068
|
-
"CONTROLLED.CLOSE": [
|
|
1069
|
-
{
|
|
1070
|
-
guard: "shouldRestoreFocus",
|
|
1071
|
-
target: "focused",
|
|
1072
|
-
actions: ["setReturnFocus"]
|
|
1073
|
-
},
|
|
1074
|
-
{
|
|
1075
|
-
target: "idle"
|
|
1076
|
-
}
|
|
1077
|
-
],
|
|
1078
|
-
"AREA.POINTER_MOVE": {
|
|
1079
|
-
actions: ["setAreaColorFromPoint", "focusAreaThumb"]
|
|
1080
|
-
},
|
|
1081
|
-
"AREA.POINTER_UP": {
|
|
1082
|
-
target: "open",
|
|
1083
|
-
actions: ["invokeOnChangeEnd"]
|
|
1084
|
-
},
|
|
1085
|
-
"CHANNEL_SLIDER.POINTER_MOVE": {
|
|
1086
|
-
actions: ["setChannelColorFromPoint", "focusChannelThumb"]
|
|
1087
|
-
},
|
|
1088
|
-
"CHANNEL_SLIDER.POINTER_UP": {
|
|
1089
|
-
target: "open",
|
|
1090
|
-
actions: ["invokeOnChangeEnd"]
|
|
1091
|
-
},
|
|
1092
|
-
INTERACT_OUTSIDE: [
|
|
1093
|
-
{
|
|
1094
|
-
guard: "isOpenControlled",
|
|
1095
|
-
actions: ["invokeOnClose"]
|
|
1096
|
-
},
|
|
1097
|
-
{
|
|
1098
|
-
guard: "shouldRestoreFocus",
|
|
1099
|
-
target: "focused",
|
|
1100
|
-
actions: ["invokeOnClose", "setReturnFocus"]
|
|
1101
|
-
},
|
|
1102
|
-
{
|
|
1103
|
-
target: "idle",
|
|
1104
|
-
actions: ["invokeOnClose"]
|
|
1105
|
-
}
|
|
1106
|
-
],
|
|
1107
|
-
CLOSE: [
|
|
1108
|
-
{
|
|
1109
|
-
guard: "isOpenControlled",
|
|
1110
|
-
actions: ["invokeOnClose"]
|
|
1111
|
-
},
|
|
1112
|
-
{
|
|
1113
|
-
target: "idle",
|
|
1114
|
-
actions: ["invokeOnClose"]
|
|
1115
|
-
}
|
|
1116
|
-
]
|
|
1117
|
-
}
|
|
1118
|
-
}
|
|
1119
|
-
}
|
|
1120
|
-
},
|
|
1121
|
-
{
|
|
1122
|
-
guards: {
|
|
1123
|
-
closeOnSelect: (ctx2) => !!ctx2.closeOnSelect,
|
|
1124
|
-
isOpenControlled: (ctx2) => !!ctx2["open.controlled"],
|
|
1125
|
-
shouldRestoreFocus: (ctx2) => !!ctx2.restoreFocus
|
|
1126
|
-
},
|
|
1127
|
-
activities: {
|
|
1128
|
-
trackPositioning(ctx2) {
|
|
1129
|
-
ctx2.currentPlacement = ctx2.positioning.placement;
|
|
1130
|
-
const anchorEl = dom.getTriggerEl(ctx2);
|
|
1131
|
-
const getPositionerEl = () => dom.getPositionerEl(ctx2);
|
|
1132
|
-
return (0, import_popper2.getPlacement)(anchorEl, getPositionerEl, {
|
|
1133
|
-
...ctx2.positioning,
|
|
1134
|
-
defer: true,
|
|
1135
|
-
onComplete(data) {
|
|
1136
|
-
ctx2.currentPlacement = data.placement;
|
|
1137
|
-
}
|
|
1138
|
-
});
|
|
1139
|
-
},
|
|
1140
|
-
trackDismissableElement(ctx2, _evt, { send }) {
|
|
1141
|
-
const getContentEl = () => dom.getContentEl(ctx2);
|
|
1142
|
-
return (0, import_dismissable.trackDismissableElement)(getContentEl, {
|
|
1143
|
-
exclude: dom.getTriggerEl(ctx2),
|
|
1144
|
-
defer: true,
|
|
1145
|
-
onInteractOutside(event) {
|
|
1146
|
-
ctx2.onInteractOutside?.(event);
|
|
1147
|
-
if (event.defaultPrevented)
|
|
1148
|
-
return;
|
|
1149
|
-
ctx2.restoreFocus = !(event.detail.focusable || event.detail.contextmenu);
|
|
1150
|
-
},
|
|
1151
|
-
onPointerDownOutside: ctx2.onPointerDownOutside,
|
|
1152
|
-
onFocusOutside: ctx2.onFocusOutside,
|
|
1153
|
-
onDismiss() {
|
|
1154
|
-
send({ type: "INTERACT_OUTSIDE" });
|
|
1155
|
-
}
|
|
1156
|
-
});
|
|
1157
|
-
},
|
|
1158
|
-
trackFormControl(ctx2, _evt, { send, initialContext }) {
|
|
1159
|
-
const inputEl = dom.getHiddenInputEl(ctx2);
|
|
1160
|
-
return (0, import_form_utils.trackFormControl)(inputEl, {
|
|
1161
|
-
onFieldsetDisabledChange(disabled) {
|
|
1162
|
-
ctx2.fieldsetDisabled = disabled;
|
|
1163
|
-
},
|
|
1164
|
-
onFormReset() {
|
|
1165
|
-
send({ type: "VALUE.SET", value: initialContext.value, src: "form.reset" });
|
|
1166
|
-
}
|
|
1167
|
-
});
|
|
1168
|
-
},
|
|
1169
|
-
trackPointerMove(ctx2, _evt, { send }) {
|
|
1170
|
-
return (0, import_dom_event3.trackPointerMove)(dom.getDoc(ctx2), {
|
|
1171
|
-
onPointerMove({ point }) {
|
|
1172
|
-
const type = ctx2.activeId === "area" ? "AREA.POINTER_MOVE" : "CHANNEL_SLIDER.POINTER_MOVE";
|
|
1173
|
-
send({ type, point });
|
|
1174
|
-
},
|
|
1175
|
-
onPointerUp() {
|
|
1176
|
-
const type = ctx2.activeId === "area" ? "AREA.POINTER_UP" : "CHANNEL_SLIDER.POINTER_UP";
|
|
1177
|
-
send({ type });
|
|
1178
|
-
}
|
|
1179
|
-
});
|
|
1180
|
-
},
|
|
1181
|
-
disableTextSelection(ctx2) {
|
|
1182
|
-
return (0, import_text_selection.disableTextSelection)({ doc: dom.getDoc(ctx2), target: dom.getContentEl(ctx2) });
|
|
1183
|
-
}
|
|
1184
|
-
},
|
|
1185
|
-
actions: {
|
|
1186
|
-
openEyeDropper(ctx2) {
|
|
1187
|
-
const isSupported = "EyeDropper" in dom.getWin(ctx2);
|
|
1188
|
-
if (!isSupported)
|
|
1189
|
-
return;
|
|
1190
|
-
const win = dom.getWin(ctx2);
|
|
1191
|
-
const picker = new win.EyeDropper();
|
|
1192
|
-
picker.open().then(({ sRGBHex }) => {
|
|
1193
|
-
const format = ctx2.value.getFormat();
|
|
1194
|
-
const color = (0, import_color_utils5.parseColor)(sRGBHex).toFormat(format);
|
|
1195
|
-
set.value(ctx2, color);
|
|
1196
|
-
ctx2.onValueChangeEnd?.({ value: ctx2.value, valueAsString: ctx2.valueAsString });
|
|
1197
|
-
}).catch(() => void 0);
|
|
1198
|
-
},
|
|
1199
|
-
setActiveChannel(ctx2, evt) {
|
|
1200
|
-
ctx2.activeId = evt.id;
|
|
1201
|
-
if (evt.channel)
|
|
1202
|
-
ctx2.activeChannel = evt.channel;
|
|
1203
|
-
if (evt.orientation)
|
|
1204
|
-
ctx2.activeOrientation = evt.orientation;
|
|
1205
|
-
},
|
|
1206
|
-
clearActiveChannel(ctx2) {
|
|
1207
|
-
ctx2.activeChannel = null;
|
|
1208
|
-
ctx2.activeId = null;
|
|
1209
|
-
ctx2.activeOrientation = null;
|
|
1210
|
-
},
|
|
1211
|
-
setAreaColorFromPoint(ctx2, evt) {
|
|
1212
|
-
const { xChannel, yChannel } = evt.channel || ctx2.activeChannel;
|
|
1213
|
-
const percent = dom.getAreaValueFromPoint(ctx2, evt.point);
|
|
1214
|
-
if (!percent)
|
|
1215
|
-
return;
|
|
1216
|
-
const xValue = ctx2.areaValue.getChannelPercentValue(xChannel, percent.x);
|
|
1217
|
-
const yValue = ctx2.areaValue.getChannelPercentValue(yChannel, 1 - percent.y);
|
|
1218
|
-
const color = ctx2.areaValue.withChannelValue(xChannel, xValue).withChannelValue(yChannel, yValue);
|
|
1219
|
-
set.value(ctx2, color);
|
|
1220
|
-
},
|
|
1221
|
-
setChannelColorFromPoint(ctx2, evt) {
|
|
1222
|
-
const channel = evt.channel || ctx2.activeId;
|
|
1223
|
-
const percent = dom.getChannelSliderValueFromPoint(ctx2, evt.point, channel);
|
|
1224
|
-
if (!percent)
|
|
1225
|
-
return;
|
|
1226
|
-
const orientation = ctx2.activeOrientation || "horizontal";
|
|
1227
|
-
const channelPercent = orientation === "horizontal" ? percent.x : percent.y;
|
|
1228
|
-
const value = ctx2.areaValue.getChannelPercentValue(channel, channelPercent);
|
|
1229
|
-
const color = ctx2.areaValue.withChannelValue(channel, value);
|
|
1230
|
-
set.value(ctx2, color);
|
|
1231
|
-
},
|
|
1232
|
-
setValue(ctx2, evt) {
|
|
1233
|
-
set.value(ctx2, evt.value);
|
|
1234
|
-
},
|
|
1235
|
-
setFormat(ctx2, evt) {
|
|
1236
|
-
set.format(ctx2, evt.format);
|
|
1237
|
-
},
|
|
1238
|
-
syncInputElements(ctx2) {
|
|
1239
|
-
sync.inputs(ctx2);
|
|
1240
|
-
},
|
|
1241
|
-
invokeOnChangeEnd(ctx2) {
|
|
1242
|
-
invoke.changeEnd(ctx2);
|
|
1243
|
-
},
|
|
1244
|
-
setChannelColorFromInput(ctx2, evt) {
|
|
1245
|
-
const { channel, isTextField, value } = evt;
|
|
1246
|
-
const currentAlpha = ctx2.value.getChannelValue("alpha");
|
|
1247
|
-
let color;
|
|
1248
|
-
if (channel === "alpha") {
|
|
1249
|
-
let valueAsNumber = parseFloat(value);
|
|
1250
|
-
valueAsNumber = Number.isNaN(valueAsNumber) ? currentAlpha : valueAsNumber;
|
|
1251
|
-
color = ctx2.value.withChannelValue("alpha", valueAsNumber);
|
|
1252
|
-
} else if (isTextField) {
|
|
1253
|
-
color = (0, import_utils.tryCatch)(
|
|
1254
|
-
() => parse(value).withChannelValue("alpha", currentAlpha),
|
|
1255
|
-
() => ctx2.value
|
|
1256
|
-
);
|
|
1257
|
-
} else {
|
|
1258
|
-
const current = ctx2.value.toFormat(ctx2.format);
|
|
1259
|
-
const valueAsNumber = Number.isNaN(value) ? current.getChannelValue(channel) : value;
|
|
1260
|
-
color = current.withChannelValue(channel, valueAsNumber);
|
|
1261
|
-
}
|
|
1262
|
-
sync.inputs(ctx2, color);
|
|
1263
|
-
set.value(ctx2, color);
|
|
1264
|
-
},
|
|
1265
|
-
incrementChannel(ctx2, evt) {
|
|
1266
|
-
const color = ctx2.value.incrementChannel(evt.channel, evt.step);
|
|
1267
|
-
set.value(ctx2, color);
|
|
1268
|
-
},
|
|
1269
|
-
decrementChannel(ctx2, evt) {
|
|
1270
|
-
const color = ctx2.value.decrementChannel(evt.channel, evt.step);
|
|
1271
|
-
set.value(ctx2, color);
|
|
1272
|
-
},
|
|
1273
|
-
incrementXChannel(ctx2, evt) {
|
|
1274
|
-
const { xChannel } = evt.channel;
|
|
1275
|
-
const color = ctx2.areaValue.incrementChannel(xChannel, evt.step);
|
|
1276
|
-
set.value(ctx2, color);
|
|
1277
|
-
},
|
|
1278
|
-
decrementXChannel(ctx2, evt) {
|
|
1279
|
-
const { xChannel } = evt.channel;
|
|
1280
|
-
const color = ctx2.areaValue.decrementChannel(xChannel, evt.step);
|
|
1281
|
-
set.value(ctx2, color);
|
|
1282
|
-
},
|
|
1283
|
-
incrementYChannel(ctx2, evt) {
|
|
1284
|
-
const { yChannel } = evt.channel;
|
|
1285
|
-
const color = ctx2.areaValue.incrementChannel(yChannel, evt.step);
|
|
1286
|
-
set.value(ctx2, color);
|
|
1287
|
-
},
|
|
1288
|
-
decrementYChannel(ctx2, evt) {
|
|
1289
|
-
const { yChannel } = evt.channel;
|
|
1290
|
-
const color = ctx2.areaValue.decrementChannel(yChannel, evt.step);
|
|
1291
|
-
set.value(ctx2, color);
|
|
1292
|
-
},
|
|
1293
|
-
setChannelToMax(ctx2, evt) {
|
|
1294
|
-
const range = ctx2.value.getChannelRange(evt.channel);
|
|
1295
|
-
const color = ctx2.value.withChannelValue(evt.channel, range.maxValue);
|
|
1296
|
-
set.value(ctx2, color);
|
|
1297
|
-
},
|
|
1298
|
-
setChannelToMin(ctx2, evt) {
|
|
1299
|
-
const range = ctx2.value.getChannelRange(evt.channel);
|
|
1300
|
-
const color = ctx2.value.withChannelValue(evt.channel, range.minValue);
|
|
1301
|
-
set.value(ctx2, color);
|
|
1302
|
-
},
|
|
1303
|
-
focusAreaThumb(ctx2) {
|
|
1304
|
-
(0, import_dom_query3.raf)(() => {
|
|
1305
|
-
dom.getAreaThumbEl(ctx2)?.focus({ preventScroll: true });
|
|
1306
|
-
});
|
|
1307
|
-
},
|
|
1308
|
-
focusChannelThumb(ctx2, evt) {
|
|
1309
|
-
(0, import_dom_query3.raf)(() => {
|
|
1310
|
-
dom.getChannelSliderThumbEl(ctx2, evt.channel)?.focus({ preventScroll: true });
|
|
1311
|
-
});
|
|
1312
|
-
},
|
|
1313
|
-
setInitialFocus(ctx2) {
|
|
1314
|
-
(0, import_dom_query3.raf)(() => {
|
|
1315
|
-
const element = (0, import_dom_query3.getInitialFocus)(dom.getContentEl(ctx2), ctx2.initialFocusEl);
|
|
1316
|
-
element?.focus({ preventScroll: true });
|
|
1317
|
-
});
|
|
1318
|
-
},
|
|
1319
|
-
setReturnFocus(ctx2) {
|
|
1320
|
-
(0, import_dom_query3.raf)(() => {
|
|
1321
|
-
dom.getTriggerEl(ctx2)?.focus({ preventScroll: true });
|
|
1322
|
-
});
|
|
1323
|
-
},
|
|
1324
|
-
syncFormatSelectElement(ctx2) {
|
|
1325
|
-
sync.formatSelect(ctx2);
|
|
1326
|
-
},
|
|
1327
|
-
invokeOnOpen(ctx2) {
|
|
1328
|
-
ctx2.onOpenChange?.({ open: true });
|
|
1329
|
-
},
|
|
1330
|
-
invokeOnClose(ctx2) {
|
|
1331
|
-
ctx2.onOpenChange?.({ open: false });
|
|
1332
|
-
},
|
|
1333
|
-
toggleVisibility(ctx2, evt, { send }) {
|
|
1334
|
-
send({ type: ctx2.open ? "CONTROLLED.OPEN" : "CONTROLLED.CLOSE", previousEvent: evt });
|
|
1335
|
-
}
|
|
1336
|
-
},
|
|
1337
|
-
compareFns: {
|
|
1338
|
-
value: (a, b) => a.isEqual(b)
|
|
1339
|
-
}
|
|
1340
|
-
}
|
|
1341
|
-
);
|
|
1342
|
-
}
|
|
1343
|
-
var sync = {
|
|
1344
|
-
// sync channel inputs
|
|
1345
|
-
inputs(ctx, color) {
|
|
1346
|
-
const channelInputs = dom.getChannelInputEls(ctx);
|
|
1347
|
-
(0, import_dom_query3.raf)(() => {
|
|
1348
|
-
channelInputs.forEach((inputEl) => {
|
|
1349
|
-
const channel = inputEl.dataset.channel;
|
|
1350
|
-
dom.setValue(inputEl, getChannelValue(color || ctx.value, channel));
|
|
1351
|
-
});
|
|
1352
|
-
});
|
|
1353
|
-
},
|
|
1354
|
-
// sync format select
|
|
1355
|
-
formatSelect(ctx) {
|
|
1356
|
-
const selectEl = dom.getFormatSelectEl(ctx);
|
|
1357
|
-
(0, import_dom_query3.raf)(() => {
|
|
1358
|
-
dom.setValue(selectEl, ctx.format);
|
|
1359
|
-
});
|
|
1360
|
-
}
|
|
1361
|
-
};
|
|
1362
|
-
var invoke = {
|
|
1363
|
-
changeEnd(ctx) {
|
|
1364
|
-
const value = ctx.value.toFormat(ctx.format);
|
|
1365
|
-
ctx.onValueChangeEnd?.({
|
|
1366
|
-
value,
|
|
1367
|
-
valueAsString: ctx.valueAsString
|
|
1368
|
-
});
|
|
1369
|
-
},
|
|
1370
|
-
change(ctx) {
|
|
1371
|
-
const value = ctx.value.toFormat(ctx.format);
|
|
1372
|
-
ctx.onValueChange?.({
|
|
1373
|
-
value,
|
|
1374
|
-
valueAsString: ctx.valueAsString
|
|
1375
|
-
});
|
|
1376
|
-
(0, import_form_utils.dispatchInputValueEvent)(dom.getHiddenInputEl(ctx), { value: ctx.valueAsString });
|
|
1377
|
-
},
|
|
1378
|
-
formatChange(ctx) {
|
|
1379
|
-
ctx.onFormatChange?.({ format: ctx.format });
|
|
1380
|
-
}
|
|
1381
|
-
};
|
|
1382
|
-
var set = {
|
|
1383
|
-
value(ctx, color) {
|
|
1384
|
-
if (!color || ctx.value.isEqual(color))
|
|
1385
|
-
return;
|
|
1386
|
-
ctx.value = color;
|
|
1387
|
-
invoke.change(ctx);
|
|
1388
|
-
},
|
|
1389
|
-
format(ctx, format) {
|
|
1390
|
-
if (ctx.format === format)
|
|
1391
|
-
return;
|
|
1392
|
-
ctx.format = format;
|
|
1393
|
-
invoke.formatChange(ctx);
|
|
1394
|
-
}
|
|
1395
|
-
};
|
|
1396
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1397
|
-
0 && (module.exports = {
|
|
1398
|
-
anatomy,
|
|
1399
|
-
connect,
|
|
1400
|
-
machine,
|
|
1401
|
-
parse
|
|
1402
|
-
});
|
|
1
|
+
"use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from==="object"||typeof from==="function"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:true}),mod);var src_exports={};__export(src_exports,{anatomy:()=>anatomy,connect:()=>connect,machine:()=>machine,parse:()=>parse});module.exports=__toCommonJS(src_exports);var import_anatomy=require("@zag-js/anatomy");var anatomy=(0,import_anatomy.createAnatomy)("color-picker",["root","label","control","trigger","positioner","content","area","areaThumb","areaBackground","channelSlider","channelSliderTrack","channelSliderThumb","channelInput","transparencyGrid","swatchGroup","swatchTrigger","swatchIndicator","swatch","eyeDropperTrigger","formatTrigger","formatSelect"]);var parts=anatomy.build();var import_color_utils3=require("@zag-js/color-utils");var import_dom_event2=require("@zag-js/dom-event");var import_dom_query2=require("@zag-js/dom-query");var import_popper=require("@zag-js/popper");var import_dom_event=require("@zag-js/dom-event");var import_dom_query=require("@zag-js/dom-query");var dom=(0,import_dom_query.createScope)({getRootId:ctx=>ctx.ids?.root??`color-picker:${ctx.id}`,getLabelId:ctx=>ctx.ids?.label??`color-picker:${ctx.id}:label`,getHiddenInputId:ctx=>`color-picker:${ctx.id}:hidden-input`,getControlId:ctx=>ctx.ids?.control??`color-picker:${ctx.id}:control`,getTriggerId:ctx=>ctx.ids?.trigger??`color-picker:${ctx.id}:trigger`,getContentId:ctx=>ctx.ids?.content??`color-picker:${ctx.id}:content`,getPositionerId:ctx=>`color-picker:${ctx.id}:positioner`,getFormatSelectId:ctx=>`color-picker:${ctx.id}:format-select`,getAreaId:ctx=>ctx.ids?.area??`color-picker:${ctx.id}:area`,getAreaGradientId:ctx=>ctx.ids?.areaGradient??`color-picker:${ctx.id}:area-gradient`,getAreaThumbId:ctx=>ctx.ids?.areaThumb??`color-picker:${ctx.id}:area-thumb`,getChannelSliderId:(ctx,channel)=>ctx.ids?.channelSliderTrack?.(channel)??`color-picker:${ctx.id}:slider-track:${channel}`,getChannelSliderThumbId:(ctx,channel)=>ctx.ids?.channelSliderThumb?.(channel)??`color-picker:${ctx.id}:slider-thumb:${channel}`,getContentEl:ctx=>dom.getById(ctx,dom.getContentId(ctx)),getAreaThumbEl:ctx=>dom.getById(ctx,dom.getAreaThumbId(ctx)),getChannelSliderThumbEl:(ctx,channel)=>dom.getById(ctx,dom.getChannelSliderThumbId(ctx,channel)),getChannelInputEl:(ctx,channel)=>{return[...(0,import_dom_query.queryAll)(dom.getContentEl(ctx),`input[data-channel="${channel}"]`),...(0,import_dom_query.queryAll)(dom.getControlEl(ctx),`input[data-channel="${channel}"]`)]},getFormatSelectEl:ctx=>dom.getById(ctx,dom.getFormatSelectId(ctx)),getHiddenInputEl:ctx=>dom.getById(ctx,dom.getHiddenInputId(ctx)),getAreaEl:ctx=>dom.getById(ctx,dom.getAreaId(ctx)),getAreaValueFromPoint(ctx,point){const areaEl=dom.getAreaEl(ctx);if(!areaEl)return;const{percent}=(0,import_dom_event.getRelativePoint)(point,areaEl);return percent},getControlEl:ctx=>dom.getById(ctx,dom.getControlId(ctx)),getTriggerEl:ctx=>dom.getById(ctx,dom.getTriggerId(ctx)),getPositionerEl:ctx=>dom.getById(ctx,dom.getPositionerId(ctx)),getChannelSliderTrackEl:(ctx,channel)=>{return dom.getById(ctx,dom.getChannelSliderId(ctx,channel))},getChannelSliderValueFromPoint(ctx,point,channel){const trackEl=dom.getChannelSliderTrackEl(ctx,channel);if(!trackEl)return;const{percent}=(0,import_dom_event.getRelativePoint)(point,trackEl);return percent},getChannelInputEls:ctx=>{return[...(0,import_dom_query.queryAll)(dom.getContentEl(ctx),"input[data-channel]"),...(0,import_dom_query.queryAll)(dom.getControlEl(ctx),"input[data-channel]")]}});var import_color_utils=require("@zag-js/color-utils");function getChannelDisplayColor(color,channel){switch(channel){case"hue":return(0,import_color_utils.parseColor)(`hsl(${color.getChannelValue("hue")}, 100%, 50%)`);case"lightness":case"brightness":case"saturation":case"red":case"green":case"blue":return color.withChannelValue("alpha",1);case"alpha":{return color}default:throw new Error("Unknown color channel: "+channel)}}var import_color_utils2=require("@zag-js/color-utils");function getChannelValue(color,channel){if(channel==null)return"";if(channel==="hex"){return color.toString("hex")}if(channel==="css"){return color.toString("css")}if(channel in color){return color.getChannelValue(channel).toString()}const isHSL=color.getFormat()==="hsla";switch(channel){case"hue":return isHSL?color.toFormat("hsla").getChannelValue("hue").toString():color.toFormat("hsba").getChannelValue("hue").toString();case"saturation":return isHSL?color.toFormat("hsla").getChannelValue("saturation").toString():color.toFormat("hsba").getChannelValue("saturation").toString();case"lightness":return color.toFormat("hsla").getChannelValue("lightness").toString();case"brightness":return color.toFormat("hsba").getChannelValue("brightness").toString();case"red":case"green":case"blue":return color.toFormat("rgba").getChannelValue(channel).toString();default:return color.getChannelValue(channel).toString()}}function getChannelRange(color,channel){switch(channel){case"hex":const minColor=(0,import_color_utils2.parseColor)("#000000");const maxColor=(0,import_color_utils2.parseColor)("#FFFFFF");return{minValue:minColor.toHexInt(),maxValue:maxColor.toHexInt(),pageSize:10,step:1};case"css":return void 0;case"hue":case"saturation":case"lightness":return color.toFormat("hsla").getChannelRange(channel);case"brightness":return color.toFormat("hsba").getChannelRange(channel);case"red":case"green":case"blue":return color.toFormat("rgba").getChannelRange(channel);default:return color.getChannelRange(channel)}}function getSliderBackgroundDirection(orientation,dir){if(orientation==="vertical"){return"top"}else if(dir==="ltr"){return"right"}else{return"left"}}var getSliderBackground=props=>{const{channel,value,dir}=props;const bgDirection=getSliderBackgroundDirection(props.orientation,dir);const{minValue,maxValue}=value.getChannelRange(channel);switch(channel){case"hue":return`linear-gradient(to ${bgDirection}, 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%)`;case"lightness":{let start=value.withChannelValue(channel,minValue).toString("css");let middle=value.withChannelValue(channel,(maxValue-minValue)/2).toString("css");let end=value.withChannelValue(channel,maxValue).toString("css");return`linear-gradient(to ${bgDirection}, ${start}, ${middle}, ${end})`}case"saturation":case"brightness":case"red":case"green":case"blue":case"alpha":{let start=value.withChannelValue(channel,minValue).toString("css");let end=value.withChannelValue(channel,maxValue).toString("css");return`linear-gradient(to ${bgDirection}, ${start}, ${end})`}default:throw new Error("Unknown color channel: "+channel)}};function connect(state,send,normalize){const value=state.context.value;const areaValue=state.context.areaValue;const valueAsString=state.context.valueAsString;const disabled=state.context.isDisabled;const interactive=state.context.isInteractive;const dragging=state.hasTag("dragging");const open=state.hasTag("open");const focused=state.hasTag("focused");const getAreaChannels=props=>{const channels=areaValue.getChannels();return{xChannel:props.xChannel??channels[1],yChannel:props.yChannel??channels[2]}};const currentPlacement=state.context.currentPlacement;const popperStyles=(0,import_popper.getPlacementStyles)({...state.context.positioning,placement:currentPlacement});function getSwatchTriggerState(props){const color=(0,import_color_utils3.normalizeColor)(props.value).toFormat(state.context.format);return{value:color,valueAsString:color.toString("hex"),checked:color.isEqual(value),disabled:props.disabled||!interactive}}return{dragging,open,valueAsString,value,setOpen(nextOpen){if(nextOpen===open)return;send({type:nextOpen?"OPEN":"CLOSE"})},setValue(value2){send({type:"VALUE.SET",value:(0,import_color_utils3.normalizeColor)(value2),src:"set-color"})},getChannelValue(channel){return getChannelValue(value,channel)},setChannelValue(channel,channelValue){const color=value.withChannelValue(channel,channelValue);send({type:"VALUE.SET",value:color,src:"set-channel"})},format:state.context.format,setFormat(format){const formatValue=value.toFormat(format);send({type:"VALUE.SET",value:formatValue,src:"set-format"})},alpha:value.getChannelValue("alpha"),setAlpha(alphaValue){const color=value.withChannelValue("alpha",alphaValue);send({type:"VALUE.SET",value:color,src:"set-alpha"})},rootProps:normalize.element({...parts.root.attrs,dir:state.context.dir,id:dom.getRootId(state.context),"data-disabled":(0,import_dom_query2.dataAttr)(disabled),"data-readonly":(0,import_dom_query2.dataAttr)(state.context.readOnly),style:{"--value":value.toString("css")}}),labelProps:normalize.element({...parts.label.attrs,dir:state.context.dir,id:dom.getLabelId(state.context),htmlFor:dom.getHiddenInputId(state.context),"data-disabled":(0,import_dom_query2.dataAttr)(disabled),"data-readonly":(0,import_dom_query2.dataAttr)(state.context.readOnly),"data-focus":(0,import_dom_query2.dataAttr)(focused),onClick(event){event.preventDefault();const inputEl=(0,import_dom_query2.query)(dom.getControlEl(state.context),"[data-channel=hex]");inputEl?.focus({preventScroll:true})}}),controlProps:normalize.element({...parts.control.attrs,id:dom.getControlId(state.context),dir:state.context.dir,"data-disabled":(0,import_dom_query2.dataAttr)(disabled),"data-readonly":(0,import_dom_query2.dataAttr)(state.context.readOnly),"data-state":open?"open":"closed","data-focus":(0,import_dom_query2.dataAttr)(focused)}),triggerProps:normalize.button({...parts.trigger.attrs,id:dom.getTriggerId(state.context),dir:state.context.dir,disabled,"aria-label":`select color. current color is ${valueAsString}`,"aria-controls":dom.getContentId(state.context),"aria-labelledby":dom.getLabelId(state.context),"data-disabled":(0,import_dom_query2.dataAttr)(disabled),"data-readonly":(0,import_dom_query2.dataAttr)(state.context.readOnly),"data-placement":currentPlacement,"aria-expanded":(0,import_dom_query2.dataAttr)(open),"data-state":open?"open":"closed","data-focus":(0,import_dom_query2.dataAttr)(focused),type:"button",onClick(){if(!interactive)return;send({type:"TRIGGER.CLICK"})},onBlur(){if(!interactive)return;send({type:"TRIGGER.BLUR"})},style:{position:"relative"}}),positionerProps:normalize.element({...parts.positioner.attrs,id:dom.getPositionerId(state.context),dir:state.context.dir,style:popperStyles.floating}),contentProps:normalize.element({...parts.content.attrs,id:dom.getContentId(state.context),dir:state.context.dir,"data-placement":currentPlacement,"data-state":open?"open":"closed",hidden:!open}),getAreaProps(props={}){const{xChannel,yChannel}=getAreaChannels(props);const{areaStyles}=(0,import_color_utils3.getColorAreaGradient)(areaValue,{xChannel,yChannel,dir:state.context.dir});return normalize.element({...parts.area.attrs,id:dom.getAreaId(state.context),role:"group",onPointerDown(event){if(!interactive)return;const evt=(0,import_dom_event2.getNativeEvent)(event);if(!(0,import_dom_event2.isLeftClick)(evt)||(0,import_dom_event2.isModifierKey)(evt))return;const point=(0,import_dom_event2.getEventPoint)(evt);const channel={xChannel,yChannel};send({type:"AREA.POINTER_DOWN",point,channel,id:"area"});event.preventDefault()},style:{position:"relative",touchAction:"none",forcedColorAdjust:"none",...areaStyles}})},getAreaBackgroundProps(props={}){const{xChannel,yChannel}=getAreaChannels(props);const{areaGradientStyles}=(0,import_color_utils3.getColorAreaGradient)(areaValue,{xChannel,yChannel,dir:state.context.dir});return normalize.element({...parts.areaBackground.attrs,id:dom.getAreaGradientId(state.context),style:{position:"relative",touchAction:"none",forcedColorAdjust:"none",...areaGradientStyles}})},getAreaThumbProps(props={}){const{xChannel,yChannel}=getAreaChannels(props);const channel={xChannel,yChannel};const xPercent=areaValue.getChannelValuePercent(xChannel);const yPercent=1-areaValue.getChannelValuePercent(yChannel);const xValue=areaValue.getChannelValue(xChannel);const yValue=areaValue.getChannelValue(yChannel);return normalize.element({...parts.areaThumb.attrs,id:dom.getAreaThumbId(state.context),dir:state.context.dir,tabIndex:disabled?void 0:0,"data-disabled":(0,import_dom_query2.dataAttr)(disabled),role:"slider","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":xValue,"aria-label":`${xChannel} and ${yChannel}`,"aria-roledescription":"2d slider","aria-valuetext":`${xChannel} ${xValue}, ${yChannel} ${yValue}`,style:{position:"absolute",left:`${xPercent*100}%`,top:`${yPercent*100}%`,transform:"translate(-50%, -50%)",touchAction:"none",forcedColorAdjust:"none",background:areaValue.withChannelValue("alpha",1).toString("css")},onFocus(){if(!interactive)return;send({type:"AREA.FOCUS",id:"area",channel})},onKeyDown(event){if(event.defaultPrevented)return;if(!interactive)return;const step=(0,import_dom_event2.getEventStep)(event);const keyMap={ArrowUp(){send({type:"AREA.ARROW_UP",channel,step})},ArrowDown(){send({type:"AREA.ARROW_DOWN",channel,step})},ArrowLeft(){send({type:"AREA.ARROW_LEFT",channel,step})},ArrowRight(){send({type:"AREA.ARROW_RIGHT",channel,step})},PageUp(){send({type:"AREA.PAGE_UP",channel,step})},PageDown(){send({type:"AREA.PAGE_DOWN",channel,step})},Escape(event2){event2.stopPropagation()}};const exec=keyMap[(0,import_dom_event2.getEventKey)(event,state.context)];if(exec){exec(event);event.preventDefault()}}})},getTransparencyGridProps(props={}){const{size="12px"}=props;return normalize.element({...parts.transparencyGrid.attrs,style:{"--size":size,width:"100%",height:"100%",position:"absolute",backgroundColor:"#fff",backgroundImage:"conic-gradient(#eeeeee 0 25%, transparent 0 50%, #eeeeee 0 75%, transparent 0)",backgroundSize:"var(--size) var(--size)",inset:"0px",zIndex:"auto",pointerEvents:"none"}})},getChannelSliderProps(props){const{orientation="horizontal",channel}=props;return normalize.element({...parts.channelSlider.attrs,"data-channel":channel,"data-orientation":orientation,role:"presentation",onPointerDown(event){if(!interactive)return;const evt=(0,import_dom_event2.getNativeEvent)(event);if(!(0,import_dom_event2.isLeftClick)(evt)||(0,import_dom_event2.isModifierKey)(evt))return;const point=(0,import_dom_event2.getEventPoint)(evt);send({type:"CHANNEL_SLIDER.POINTER_DOWN",channel,point,id:channel,orientation});event.preventDefault()},style:{position:"relative",touchAction:"none"}})},getChannelSliderTrackProps(props){const{orientation="horizontal",channel}=props;return normalize.element({...parts.channelSliderTrack.attrs,id:dom.getChannelSliderId(state.context,channel),role:"group","data-channel":channel,"data-orientation":orientation,style:{position:"relative",forcedColorAdjust:"none",backgroundImage:getSliderBackground({orientation,channel,dir:state.context.dir,value:areaValue})}})},getChannelSliderThumbProps(props){const{orientation="horizontal",channel}=props;const{minValue,maxValue,step:stepValue}=areaValue.getChannelRange(channel);const channelValue=areaValue.getChannelValue(channel);const offset=(channelValue-minValue)/(maxValue-minValue);const placementStyles=orientation==="horizontal"?{left:`${offset*100}%`,top:"50%"}:{top:`${offset*100}%`,left:"50%"};return normalize.element({...parts.channelSliderThumb.attrs,id:dom.getChannelSliderThumbId(state.context,channel),role:"slider","aria-label":channel,tabIndex:disabled?void 0:0,"data-channel":channel,"data-disabled":(0,import_dom_query2.dataAttr)(disabled),"data-orientation":orientation,"aria-disabled":(0,import_dom_query2.dataAttr)(disabled),"aria-orientation":orientation,"aria-valuemax":maxValue,"aria-valuemin":minValue,"aria-valuenow":channelValue,"aria-valuetext":`${channel} ${channelValue}`,style:{forcedColorAdjust:"none",position:"absolute",background:getChannelDisplayColor(areaValue,channel).toString("css"),...placementStyles},onFocus(){if(!interactive)return;send({type:"CHANNEL_SLIDER.FOCUS",channel})},onKeyDown(event){if(event.defaultPrevented)return;if(!interactive)return;const step=(0,import_dom_event2.getEventStep)(event)*stepValue;const keyMap={ArrowUp(){send({type:"CHANNEL_SLIDER.ARROW_UP",channel,step})},ArrowDown(){send({type:"CHANNEL_SLIDER.ARROW_DOWN",channel,step})},ArrowLeft(){send({type:"CHANNEL_SLIDER.ARROW_LEFT",channel,step})},ArrowRight(){send({type:"CHANNEL_SLIDER.ARROW_RIGHT",channel,step})},PageUp(){send({type:"CHANNEL_SLIDER.PAGE_UP",channel})},PageDown(){send({type:"CHANNEL_SLIDER.PAGE_DOWN",channel})},Home(){send({type:"CHANNEL_SLIDER.HOME",channel})},End(){send({type:"CHANNEL_SLIDER.END",channel})},Escape(event2){event2.stopPropagation()}};const exec=keyMap[(0,import_dom_event2.getEventKey)(event,state.context)];if(exec){exec(event);event.preventDefault()}}})},getChannelInputProps(props){const{channel}=props;const isTextField=channel==="hex"||channel==="css";const range=getChannelRange(value,channel);return normalize.input({...parts.channelInput.attrs,dir:state.context.dir,type:isTextField?"text":"number","data-channel":channel,"aria-label":channel,spellCheck:false,autoComplete:"off",disabled,"data-disabled":(0,import_dom_query2.dataAttr)(disabled),readOnly:state.context.readOnly,defaultValue:getChannelValue(value,channel),min:range?.minValue,max:range?.maxValue,step:range?.step,onBeforeInput(event){if(isTextField||!interactive)return;const value2=event.currentTarget.value;if(value2.match(/[^0-9.]/g)){event.preventDefault()}},onFocus(event){if(!interactive)return;send({type:"CHANNEL_INPUT.FOCUS",channel});event.target.select()},onBlur(event){if(!interactive)return;const value2=isTextField?event.currentTarget.value:event.currentTarget.valueAsNumber;send({type:"CHANNEL_INPUT.BLUR",channel,value:value2,isTextField})},onKeyDown(event){if(event.defaultPrevented)return;if(!interactive)return;if(event.key==="Enter"){const value2=isTextField?event.currentTarget.value:event.currentTarget.valueAsNumber;send({type:"CHANNEL_INPUT.CHANGE",channel,value:value2,isTextField});event.preventDefault()}},style:{appearance:"none",WebkitAppearance:"none",MozAppearance:"textfield"}})},hiddenInputProps:normalize.input({type:"text",disabled,name:state.context.name,id:dom.getHiddenInputId(state.context),style:import_dom_query2.visuallyHiddenStyle,defaultValue:valueAsString}),eyeDropperTriggerProps:normalize.button({...parts.eyeDropperTrigger.attrs,type:"button",dir:state.context.dir,disabled,"data-disabled":(0,import_dom_query2.dataAttr)(disabled),"aria-label":"Pick a color from the screen",onClick(){if(!interactive)return;send("EYEDROPPER.CLICK")}}),swatchGroupProps:normalize.element({...parts.swatchGroup.attrs,role:"group"}),getSwatchTriggerState,getSwatchTriggerProps(props){const triggerState=getSwatchTriggerState(props);return normalize.button({...parts.swatchTrigger.attrs,disabled:triggerState.disabled,dir:state.context.dir,type:"button","aria-label":`select ${triggerState.valueAsString} as the color`,"data-state":triggerState.checked?"checked":"unchecked","data-value":triggerState.valueAsString,"data-disabled":(0,import_dom_query2.dataAttr)(triggerState.disabled),onClick(){if(triggerState.disabled)return;send({type:"SWATCH_TRIGGER.CLICK",value:triggerState.value})},style:{position:"relative"}})},getSwatchIndicatorProps(props){const triggerState=getSwatchTriggerState(props);return normalize.element({...parts.swatchIndicator.attrs,dir:state.context.dir,hidden:!triggerState.checked})},getSwatchProps(props){const{respectAlpha=true}=props;const triggerState=getSwatchTriggerState(props);return normalize.element({...parts.swatch.attrs,dir:state.context.dir,"data-state":triggerState.checked?"checked":"unchecked","data-value":triggerState.valueAsString,style:{position:"relative",background:triggerState.value.toString(respectAlpha?"css":"hex")}})},formatTriggerProps:normalize.button({...parts.formatTrigger.attrs,dir:state.context.dir,type:"button","aria-label":`change color format to ${getNextFormat(state.context.format)}`,onClick(event){if(event.currentTarget.disabled)return;const nextFormat=getNextFormat(state.context.format);send({type:"FORMAT.SET",format:nextFormat,src:"format-trigger"})}}),formatSelectProps:normalize.select({...parts.formatSelect.attrs,"aria-label":"change color format",dir:state.context.dir,defaultValue:state.context.format,disabled,onChange(event){const format=assertFormat(event.currentTarget.value);send({type:"FORMAT.SET",format,src:"format-select"})}})}}var formats=["hsba","hsla","rgba"];var formatRegex=new RegExp(`^(${formats.join("|")})$`);function getNextFormat(format){const index=formats.indexOf(format);return formats[index+1]??formats[0]}function assertFormat(format){if(formatRegex.test(format))return format;throw new Error(`Unsupported color format: ${format}`)}var import_color_utils5=require("@zag-js/color-utils");var import_core=require("@zag-js/core");var import_dismissable=require("@zag-js/dismissable");var import_dom_event3=require("@zag-js/dom-event");var import_dom_query3=require("@zag-js/dom-query");var import_form_utils=require("@zag-js/form-utils");var import_popper2=require("@zag-js/popper");var import_text_selection=require("@zag-js/text-selection");var import_utils=require("@zag-js/utils");var import_color_utils4=require("@zag-js/color-utils");var parse=colorString=>{return(0,import_color_utils4.parseColor)(colorString)};var{and}=import_core.guards;function machine(userContext){const ctx=(0,import_utils.compact)(userContext);return(0,import_core.createMachine)({id:"color-picker",initial:ctx.open?"open":"idle",context:{dir:"ltr",value:parse("#000000"),format:"rgba",disabled:false,closeOnSelect:false,...ctx,activeId:null,activeChannel:null,activeOrientation:null,fieldsetDisabled:false,restoreFocus:true,positioning:{...ctx.positioning,placement:"bottom"}},computed:{isRtl:ctx2=>ctx2.dir==="rtl",isDisabled:ctx2=>!!ctx2.disabled||ctx2.fieldsetDisabled,isInteractive:ctx2=>!(ctx2.isDisabled||ctx2.readOnly),valueAsString:ctx2=>ctx2.value.toString(ctx2.format),areaValue:ctx2=>{const format=ctx2.format.startsWith("hsl")?"hsla":"hsba";return ctx2.value.toFormat(format)}},activities:["trackFormControl"],watch:{value:["syncInputElements"],format:["syncFormatSelectElement"],open:["toggleVisibility"]},on:{"VALUE.SET":{actions:["setValue"]},"FORMAT.SET":{actions:["setFormat"]},"CHANNEL_INPUT.CHANGE":{actions:["setChannelColorFromInput"]},"EYEDROPPER.CLICK":{actions:["openEyeDropper"]}},states:{idle:{tags:["closed"],on:{"CONTROLLED.OPEN":{target:"open",actions:["setInitialFocus"]},OPEN:[{guard:"isOpenControlled",actions:["invokeOnOpen"]},{target:"open",actions:["invokeOnOpen","setInitialFocus"]}],"TRIGGER.CLICK":[{guard:"isOpenControlled",actions:["invokeOnOpen"]},{target:"open",actions:["invokeOnOpen","setInitialFocus"]}],"CHANNEL_INPUT.FOCUS":{target:"focused",actions:["setActiveChannel"]}}},focused:{tags:["closed","focused"],on:{"CONTROLLED.OPEN":{target:"open",actions:["setInitialFocus"]},OPEN:[{guard:"isOpenControlled",actions:["invokeOnOpen"]},{target:"open",actions:["invokeOnOpen","setInitialFocus"]}],"TRIGGER.CLICK":[{guard:"isOpenControlled",actions:["invokeOnOpen"]},{target:"open",actions:["invokeOnOpen","setInitialFocus"]}],"CHANNEL_INPUT.FOCUS":{actions:["setActiveChannel"]},"CHANNEL_INPUT.BLUR":{target:"idle",actions:["setChannelColorFromInput"]},"TRIGGER.BLUR":{target:"idle"}}},open:{tags:["open"],activities:["trackPositioning","trackDismissableElement"],on:{"CONTROLLED.CLOSE":[{guard:"shouldRestoreFocus",target:"focused",actions:["setReturnFocus"]},{target:"idle"}],"TRIGGER.CLICK":[{guard:"isOpenControlled",actions:["invokeOnClose"]},{target:"idle",actions:["invokeOnClose"]}],"AREA.POINTER_DOWN":{target:"open:dragging",actions:["setActiveChannel","setAreaColorFromPoint","focusAreaThumb"]},"AREA.FOCUS":{actions:["setActiveChannel"]},"CHANNEL_SLIDER.POINTER_DOWN":{target:"open:dragging",actions:["setActiveChannel","setChannelColorFromPoint","focusChannelThumb"]},"CHANNEL_SLIDER.FOCUS":{actions:["setActiveChannel"]},"AREA.ARROW_LEFT":{actions:["decrementXChannel"]},"AREA.ARROW_RIGHT":{actions:["incrementXChannel"]},"AREA.ARROW_UP":{actions:["incrementYChannel"]},"AREA.ARROW_DOWN":{actions:["decrementYChannel"]},"AREA.PAGE_UP":{actions:["incrementXChannel"]},"AREA.PAGE_DOWN":{actions:["decrementXChannel"]},"CHANNEL_SLIDER.ARROW_LEFT":{actions:["decrementChannel"]},"CHANNEL_SLIDER.ARROW_RIGHT":{actions:["incrementChannel"]},"CHANNEL_SLIDER.ARROW_UP":{actions:["incrementChannel"]},"CHANNEL_SLIDER.ARROW_DOWN":{actions:["decrementChannel"]},"CHANNEL_SLIDER.PAGE_UP":{actions:["incrementChannel"]},"CHANNEL_SLIDER.PAGE_DOWN":{actions:["decrementChannel"]},"CHANNEL_SLIDER.HOME":{actions:["setChannelToMin"]},"CHANNEL_SLIDER.END":{actions:["setChannelToMax"]},"CHANNEL_INPUT.BLUR":{actions:["setChannelColorFromInput"]},INTERACT_OUTSIDE:[{guard:"isOpenControlled",actions:["invokeOnClose"]},{guard:"shouldRestoreFocus",target:"focused",actions:["invokeOnClose","setReturnFocus"]},{target:"idle",actions:["invokeOnClose"]}],CLOSE:[{guard:"isOpenControlled",actions:["invokeOnClose"]},{target:"idle",actions:["invokeOnClose"]}],"SWATCH_TRIGGER.CLICK":[{guard:and("isOpenControlled","closeOnSelect"),actions:["setValue","invokeOnClose"]},{guard:"closeOnSelect",target:"focused",actions:["setValue","invokeOnClose","setReturnFocus"]},{actions:["setValue"]}]}},"open:dragging":{tags:["open"],exit:["clearActiveChannel"],activities:["trackPointerMove","disableTextSelection","trackPositioning","trackDismissableElement"],on:{"CONTROLLED.CLOSE":[{guard:"shouldRestoreFocus",target:"focused",actions:["setReturnFocus"]},{target:"idle"}],"AREA.POINTER_MOVE":{actions:["setAreaColorFromPoint","focusAreaThumb"]},"AREA.POINTER_UP":{target:"open",actions:["invokeOnChangeEnd"]},"CHANNEL_SLIDER.POINTER_MOVE":{actions:["setChannelColorFromPoint","focusChannelThumb"]},"CHANNEL_SLIDER.POINTER_UP":{target:"open",actions:["invokeOnChangeEnd"]},INTERACT_OUTSIDE:[{guard:"isOpenControlled",actions:["invokeOnClose"]},{guard:"shouldRestoreFocus",target:"focused",actions:["invokeOnClose","setReturnFocus"]},{target:"idle",actions:["invokeOnClose"]}],CLOSE:[{guard:"isOpenControlled",actions:["invokeOnClose"]},{target:"idle",actions:["invokeOnClose"]}]}}}},{guards:{closeOnSelect:ctx2=>!!ctx2.closeOnSelect,isOpenControlled:ctx2=>!!ctx2["open.controlled"],shouldRestoreFocus:ctx2=>!!ctx2.restoreFocus},activities:{trackPositioning(ctx2){ctx2.currentPlacement=ctx2.positioning.placement;const anchorEl=dom.getTriggerEl(ctx2);const getPositionerEl=()=>dom.getPositionerEl(ctx2);return(0,import_popper2.getPlacement)(anchorEl,getPositionerEl,{...ctx2.positioning,defer:true,onComplete(data){ctx2.currentPlacement=data.placement}})},trackDismissableElement(ctx2,_evt,{send}){const getContentEl=()=>dom.getContentEl(ctx2);return(0,import_dismissable.trackDismissableElement)(getContentEl,{exclude:dom.getTriggerEl(ctx2),defer:true,onInteractOutside(event){ctx2.onInteractOutside?.(event);if(event.defaultPrevented)return;ctx2.restoreFocus=!(event.detail.focusable||event.detail.contextmenu)},onPointerDownOutside:ctx2.onPointerDownOutside,onFocusOutside:ctx2.onFocusOutside,onDismiss(){send({type:"INTERACT_OUTSIDE"})}})},trackFormControl(ctx2,_evt,{send,initialContext}){const inputEl=dom.getHiddenInputEl(ctx2);return(0,import_form_utils.trackFormControl)(inputEl,{onFieldsetDisabledChange(disabled){ctx2.fieldsetDisabled=disabled},onFormReset(){send({type:"VALUE.SET",value:initialContext.value,src:"form.reset"})}})},trackPointerMove(ctx2,_evt,{send}){return(0,import_dom_event3.trackPointerMove)(dom.getDoc(ctx2),{onPointerMove({point}){const type=ctx2.activeId==="area"?"AREA.POINTER_MOVE":"CHANNEL_SLIDER.POINTER_MOVE";send({type,point})},onPointerUp(){const type=ctx2.activeId==="area"?"AREA.POINTER_UP":"CHANNEL_SLIDER.POINTER_UP";send({type})}})},disableTextSelection(ctx2){return(0,import_text_selection.disableTextSelection)({doc:dom.getDoc(ctx2),target:dom.getContentEl(ctx2)})}},actions:{openEyeDropper(ctx2){const isSupported="EyeDropper"in dom.getWin(ctx2);if(!isSupported)return;const win=dom.getWin(ctx2);const picker=new win.EyeDropper;picker.open().then(({sRGBHex})=>{const format=ctx2.value.getFormat();const color=(0,import_color_utils5.parseColor)(sRGBHex).toFormat(format);set.value(ctx2,color);ctx2.onValueChangeEnd?.({value:ctx2.value,valueAsString:ctx2.valueAsString})}).catch(()=>void 0)},setActiveChannel(ctx2,evt){ctx2.activeId=evt.id;if(evt.channel)ctx2.activeChannel=evt.channel;if(evt.orientation)ctx2.activeOrientation=evt.orientation},clearActiveChannel(ctx2){ctx2.activeChannel=null;ctx2.activeId=null;ctx2.activeOrientation=null},setAreaColorFromPoint(ctx2,evt){const{xChannel,yChannel}=evt.channel||ctx2.activeChannel;const percent=dom.getAreaValueFromPoint(ctx2,evt.point);if(!percent)return;const xValue=ctx2.areaValue.getChannelPercentValue(xChannel,percent.x);const yValue=ctx2.areaValue.getChannelPercentValue(yChannel,1-percent.y);const color=ctx2.areaValue.withChannelValue(xChannel,xValue).withChannelValue(yChannel,yValue);set.value(ctx2,color)},setChannelColorFromPoint(ctx2,evt){const channel=evt.channel||ctx2.activeId;const percent=dom.getChannelSliderValueFromPoint(ctx2,evt.point,channel);if(!percent)return;const orientation=ctx2.activeOrientation||"horizontal";const channelPercent=orientation==="horizontal"?percent.x:percent.y;const value=ctx2.areaValue.getChannelPercentValue(channel,channelPercent);const color=ctx2.areaValue.withChannelValue(channel,value);set.value(ctx2,color)},setValue(ctx2,evt){set.value(ctx2,evt.value)},setFormat(ctx2,evt){set.format(ctx2,evt.format)},syncInputElements(ctx2){sync.inputs(ctx2)},invokeOnChangeEnd(ctx2){invoke.changeEnd(ctx2)},setChannelColorFromInput(ctx2,evt){const{channel,isTextField,value}=evt;const currentAlpha=ctx2.value.getChannelValue("alpha");let color;if(channel==="alpha"){let valueAsNumber=parseFloat(value);valueAsNumber=Number.isNaN(valueAsNumber)?currentAlpha:valueAsNumber;color=ctx2.value.withChannelValue("alpha",valueAsNumber)}else if(isTextField){color=(0,import_utils.tryCatch)(()=>parse(value).withChannelValue("alpha",currentAlpha),()=>ctx2.value)}else{const current=ctx2.value.toFormat(ctx2.format);const valueAsNumber=Number.isNaN(value)?current.getChannelValue(channel):value;color=current.withChannelValue(channel,valueAsNumber)}sync.inputs(ctx2,color);set.value(ctx2,color)},incrementChannel(ctx2,evt){const color=ctx2.value.incrementChannel(evt.channel,evt.step);set.value(ctx2,color)},decrementChannel(ctx2,evt){const color=ctx2.value.decrementChannel(evt.channel,evt.step);set.value(ctx2,color)},incrementXChannel(ctx2,evt){const{xChannel}=evt.channel;const color=ctx2.areaValue.incrementChannel(xChannel,evt.step);set.value(ctx2,color)},decrementXChannel(ctx2,evt){const{xChannel}=evt.channel;const color=ctx2.areaValue.decrementChannel(xChannel,evt.step);set.value(ctx2,color)},incrementYChannel(ctx2,evt){const{yChannel}=evt.channel;const color=ctx2.areaValue.incrementChannel(yChannel,evt.step);set.value(ctx2,color)},decrementYChannel(ctx2,evt){const{yChannel}=evt.channel;const color=ctx2.areaValue.decrementChannel(yChannel,evt.step);set.value(ctx2,color)},setChannelToMax(ctx2,evt){const range=ctx2.value.getChannelRange(evt.channel);const color=ctx2.value.withChannelValue(evt.channel,range.maxValue);set.value(ctx2,color)},setChannelToMin(ctx2,evt){const range=ctx2.value.getChannelRange(evt.channel);const color=ctx2.value.withChannelValue(evt.channel,range.minValue);set.value(ctx2,color)},focusAreaThumb(ctx2){(0,import_dom_query3.raf)(()=>{dom.getAreaThumbEl(ctx2)?.focus({preventScroll:true})})},focusChannelThumb(ctx2,evt){(0,import_dom_query3.raf)(()=>{dom.getChannelSliderThumbEl(ctx2,evt.channel)?.focus({preventScroll:true})})},setInitialFocus(ctx2){(0,import_dom_query3.raf)(()=>{const element=(0,import_dom_query3.getInitialFocus)(dom.getContentEl(ctx2),ctx2.initialFocusEl);element?.focus({preventScroll:true})})},setReturnFocus(ctx2){(0,import_dom_query3.raf)(()=>{dom.getTriggerEl(ctx2)?.focus({preventScroll:true})})},syncFormatSelectElement(ctx2){sync.formatSelect(ctx2)},invokeOnOpen(ctx2){ctx2.onOpenChange?.({open:true})},invokeOnClose(ctx2){ctx2.onOpenChange?.({open:false})},toggleVisibility(ctx2,evt,{send}){send({type:ctx2.open?"CONTROLLED.OPEN":"CONTROLLED.CLOSE",previousEvent:evt})}},compareFns:{value:(a,b)=>a.isEqual(b)}})}var sync={inputs(ctx,color){const channelInputs=dom.getChannelInputEls(ctx);(0,import_dom_query3.raf)(()=>{channelInputs.forEach(inputEl=>{const channel=inputEl.dataset.channel;dom.setValue(inputEl,getChannelValue(color||ctx.value,channel))})})},formatSelect(ctx){const selectEl=dom.getFormatSelectEl(ctx);(0,import_dom_query3.raf)(()=>{dom.setValue(selectEl,ctx.format)})}};var invoke={changeEnd(ctx){const value=ctx.value.toFormat(ctx.format);ctx.onValueChangeEnd?.({value,valueAsString:ctx.valueAsString})},change(ctx){const value=ctx.value.toFormat(ctx.format);ctx.onValueChange?.({value,valueAsString:ctx.valueAsString});(0,import_form_utils.dispatchInputValueEvent)(dom.getHiddenInputEl(ctx),{value:ctx.valueAsString})},formatChange(ctx){ctx.onFormatChange?.({format:ctx.format})}};var set={value(ctx,color){if(!color||ctx.value.isEqual(color))return;ctx.value=color;invoke.change(ctx)},format(ctx,format){if(ctx.format===format)return;ctx.format=format;invoke.formatChange(ctx)}};0&&(module.exports={anatomy,connect,machine,parse});
|
|
1403
2
|
//# sourceMappingURL=index.js.map
|