@zag-js/color-picker 0.69.0 → 0.71.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.js +83 -133
- package/dist/index.mjs +17 -48
- package/package.json +13 -14
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/src/color-picker.anatomy.ts +0 -30
- package/src/color-picker.connect.ts +0 -680
- package/src/color-picker.dom.ts +0 -65
- package/src/color-picker.machine.ts +0 -638
- package/src/color-picker.parse.ts +0 -5
- package/src/color-picker.props.ts +0 -53
- package/src/color-picker.types.ts +0 -355
- package/src/index.ts +0 -28
- package/src/utils/get-channel-display-color.ts +0 -20
- package/src/utils/get-channel-input-value.ts +0 -79
- package/src/utils/get-slider-background.ts +0 -45
package/dist/index.js
CHANGED
|
@@ -1,35 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
3
|
+
var anatomy$1 = require('@zag-js/anatomy');
|
|
4
|
+
var colorUtils = require('@zag-js/color-utils');
|
|
5
|
+
var domEvent = require('@zag-js/dom-event');
|
|
6
|
+
var domQuery = require('@zag-js/dom-query');
|
|
7
|
+
var popper = require('@zag-js/popper');
|
|
8
|
+
var core = require('@zag-js/core');
|
|
9
|
+
var dismissable = require('@zag-js/dismissable');
|
|
10
|
+
var formUtils = require('@zag-js/form-utils');
|
|
11
|
+
var textSelection = require('@zag-js/text-selection');
|
|
12
|
+
var utils = require('@zag-js/utils');
|
|
29
13
|
|
|
30
14
|
// src/color-picker.anatomy.ts
|
|
31
|
-
var
|
|
32
|
-
var anatomy = (0, import_anatomy.createAnatomy)("color-picker", [
|
|
15
|
+
var anatomy = anatomy$1.createAnatomy("color-picker", [
|
|
33
16
|
"root",
|
|
34
17
|
"label",
|
|
35
18
|
"control",
|
|
@@ -56,17 +39,7 @@ var anatomy = (0, import_anatomy.createAnatomy)("color-picker", [
|
|
|
56
39
|
"formatSelect"
|
|
57
40
|
]);
|
|
58
41
|
var parts = anatomy.build();
|
|
59
|
-
|
|
60
|
-
// src/color-picker.connect.ts
|
|
61
|
-
var import_color_utils3 = require("@zag-js/color-utils");
|
|
62
|
-
var import_dom_event2 = require("@zag-js/dom-event");
|
|
63
|
-
var import_dom_query2 = require("@zag-js/dom-query");
|
|
64
|
-
var import_popper = require("@zag-js/popper");
|
|
65
|
-
|
|
66
|
-
// src/color-picker.dom.ts
|
|
67
|
-
var import_dom_event = require("@zag-js/dom-event");
|
|
68
|
-
var import_dom_query = require("@zag-js/dom-query");
|
|
69
|
-
var dom = (0, import_dom_query.createScope)({
|
|
42
|
+
var dom = domQuery.createScope({
|
|
70
43
|
getRootId: (ctx) => ctx.ids?.root ?? `color-picker:${ctx.id}`,
|
|
71
44
|
getLabelId: (ctx) => ctx.ids?.label ?? `color-picker:${ctx.id}:label`,
|
|
72
45
|
getHiddenInputId: (ctx) => ctx.ids?.hiddenInput ?? `color-picker:${ctx.id}:hidden-input`,
|
|
@@ -86,8 +59,8 @@ var dom = (0, import_dom_query.createScope)({
|
|
|
86
59
|
getChannelInputEl: (ctx, channel) => {
|
|
87
60
|
const selector = `input[data-channel="${channel}"]`;
|
|
88
61
|
return [
|
|
89
|
-
...
|
|
90
|
-
...
|
|
62
|
+
...domQuery.queryAll(dom.getContentEl(ctx), selector),
|
|
63
|
+
...domQuery.queryAll(dom.getControlEl(ctx), selector)
|
|
91
64
|
];
|
|
92
65
|
},
|
|
93
66
|
getFormatSelectEl: (ctx) => dom.getById(ctx, dom.getFormatSelectId(ctx)),
|
|
@@ -96,7 +69,7 @@ var dom = (0, import_dom_query.createScope)({
|
|
|
96
69
|
getAreaValueFromPoint(ctx, point) {
|
|
97
70
|
const areaEl = dom.getAreaEl(ctx);
|
|
98
71
|
if (!areaEl) return;
|
|
99
|
-
const { percent } =
|
|
72
|
+
const { percent } = domEvent.getRelativePoint(point, areaEl);
|
|
100
73
|
return percent;
|
|
101
74
|
},
|
|
102
75
|
getControlEl: (ctx) => dom.getById(ctx, dom.getControlId(ctx)),
|
|
@@ -108,23 +81,20 @@ var dom = (0, import_dom_query.createScope)({
|
|
|
108
81
|
getChannelSliderValueFromPoint(ctx, point, channel) {
|
|
109
82
|
const trackEl = dom.getChannelSliderTrackEl(ctx, channel);
|
|
110
83
|
if (!trackEl) return;
|
|
111
|
-
const { percent } =
|
|
84
|
+
const { percent } = domEvent.getRelativePoint(point, trackEl);
|
|
112
85
|
return percent;
|
|
113
86
|
},
|
|
114
87
|
getChannelInputEls: (ctx) => {
|
|
115
88
|
return [
|
|
116
|
-
...
|
|
117
|
-
...
|
|
89
|
+
...domQuery.queryAll(dom.getContentEl(ctx), "input[data-channel]"),
|
|
90
|
+
...domQuery.queryAll(dom.getControlEl(ctx), "input[data-channel]")
|
|
118
91
|
];
|
|
119
92
|
}
|
|
120
93
|
});
|
|
121
|
-
|
|
122
|
-
// src/utils/get-channel-display-color.ts
|
|
123
|
-
var import_color_utils = require("@zag-js/color-utils");
|
|
124
94
|
function getChannelDisplayColor(color, channel) {
|
|
125
95
|
switch (channel) {
|
|
126
96
|
case "hue":
|
|
127
|
-
return
|
|
97
|
+
return colorUtils.parseColor(`hsl(${color.getChannelValue("hue")}, 100%, 50%)`);
|
|
128
98
|
case "lightness":
|
|
129
99
|
case "brightness":
|
|
130
100
|
case "saturation":
|
|
@@ -139,9 +109,6 @@ function getChannelDisplayColor(color, channel) {
|
|
|
139
109
|
throw new Error("Unknown color channel: " + channel);
|
|
140
110
|
}
|
|
141
111
|
}
|
|
142
|
-
|
|
143
|
-
// src/utils/get-channel-input-value.ts
|
|
144
|
-
var import_color_utils2 = require("@zag-js/color-utils");
|
|
145
112
|
function getChannelValue(color, channel) {
|
|
146
113
|
if (channel == null) return "";
|
|
147
114
|
if (channel === "hex") {
|
|
@@ -174,8 +141,8 @@ function getChannelValue(color, channel) {
|
|
|
174
141
|
function getChannelRange(color, channel) {
|
|
175
142
|
switch (channel) {
|
|
176
143
|
case "hex":
|
|
177
|
-
const minColor =
|
|
178
|
-
const maxColor =
|
|
144
|
+
const minColor = colorUtils.parseColor("#000000");
|
|
145
|
+
const maxColor = colorUtils.parseColor("#FFFFFF");
|
|
179
146
|
return {
|
|
180
147
|
minValue: minColor.toHexInt(),
|
|
181
148
|
maxValue: maxColor.toHexInt(),
|
|
@@ -255,12 +222,12 @@ function connect(state, send, normalize) {
|
|
|
255
222
|
};
|
|
256
223
|
};
|
|
257
224
|
const currentPlacement = state.context.currentPlacement;
|
|
258
|
-
const popperStyles =
|
|
225
|
+
const popperStyles = popper.getPlacementStyles({
|
|
259
226
|
...state.context.positioning,
|
|
260
227
|
placement: currentPlacement
|
|
261
228
|
});
|
|
262
229
|
function getSwatchTriggerState(props) {
|
|
263
|
-
const color =
|
|
230
|
+
const color = colorUtils.normalizeColor(props.value).toFormat(state.context.format);
|
|
264
231
|
return {
|
|
265
232
|
value: color,
|
|
266
233
|
valueAsString: color.toString("hex"),
|
|
@@ -278,7 +245,7 @@ function connect(state, send, normalize) {
|
|
|
278
245
|
send({ type: nextOpen ? "OPEN" : "CLOSE" });
|
|
279
246
|
},
|
|
280
247
|
setValue(value2) {
|
|
281
|
-
send({ type: "VALUE.SET", value:
|
|
248
|
+
send({ type: "VALUE.SET", value: colorUtils.normalizeColor(value2), src: "set-color" });
|
|
282
249
|
},
|
|
283
250
|
getChannelValue(channel) {
|
|
284
251
|
return getChannelValue(value, channel);
|
|
@@ -305,8 +272,8 @@ function connect(state, send, normalize) {
|
|
|
305
272
|
...parts.root.attrs,
|
|
306
273
|
dir: state.context.dir,
|
|
307
274
|
id: dom.getRootId(state.context),
|
|
308
|
-
"data-disabled":
|
|
309
|
-
"data-readonly":
|
|
275
|
+
"data-disabled": domQuery.dataAttr(disabled),
|
|
276
|
+
"data-readonly": domQuery.dataAttr(state.context.readOnly),
|
|
310
277
|
style: {
|
|
311
278
|
"--value": value.toString("css")
|
|
312
279
|
}
|
|
@@ -318,12 +285,12 @@ function connect(state, send, normalize) {
|
|
|
318
285
|
dir: state.context.dir,
|
|
319
286
|
id: dom.getLabelId(state.context),
|
|
320
287
|
htmlFor: dom.getHiddenInputId(state.context),
|
|
321
|
-
"data-disabled":
|
|
322
|
-
"data-readonly":
|
|
323
|
-
"data-focus":
|
|
288
|
+
"data-disabled": domQuery.dataAttr(disabled),
|
|
289
|
+
"data-readonly": domQuery.dataAttr(state.context.readOnly),
|
|
290
|
+
"data-focus": domQuery.dataAttr(focused),
|
|
324
291
|
onClick(event) {
|
|
325
292
|
event.preventDefault();
|
|
326
|
-
const inputEl =
|
|
293
|
+
const inputEl = domQuery.query(dom.getControlEl(state.context), "[data-channel=hex]");
|
|
327
294
|
inputEl?.focus({ preventScroll: true });
|
|
328
295
|
}
|
|
329
296
|
});
|
|
@@ -333,10 +300,10 @@ function connect(state, send, normalize) {
|
|
|
333
300
|
...parts.control.attrs,
|
|
334
301
|
id: dom.getControlId(state.context),
|
|
335
302
|
dir: state.context.dir,
|
|
336
|
-
"data-disabled":
|
|
337
|
-
"data-readonly":
|
|
303
|
+
"data-disabled": domQuery.dataAttr(disabled),
|
|
304
|
+
"data-readonly": domQuery.dataAttr(state.context.readOnly),
|
|
338
305
|
"data-state": open ? "open" : "closed",
|
|
339
|
-
"data-focus":
|
|
306
|
+
"data-focus": domQuery.dataAttr(focused)
|
|
340
307
|
});
|
|
341
308
|
},
|
|
342
309
|
getTriggerProps() {
|
|
@@ -348,12 +315,12 @@ function connect(state, send, normalize) {
|
|
|
348
315
|
"aria-label": `select color. current color is ${valueAsString}`,
|
|
349
316
|
"aria-controls": dom.getContentId(state.context),
|
|
350
317
|
"aria-labelledby": dom.getLabelId(state.context),
|
|
351
|
-
"data-disabled":
|
|
352
|
-
"data-readonly":
|
|
318
|
+
"data-disabled": domQuery.dataAttr(disabled),
|
|
319
|
+
"data-readonly": domQuery.dataAttr(state.context.readOnly),
|
|
353
320
|
"data-placement": currentPlacement,
|
|
354
|
-
"aria-expanded":
|
|
321
|
+
"aria-expanded": domQuery.dataAttr(open),
|
|
355
322
|
"data-state": open ? "open" : "closed",
|
|
356
|
-
"data-focus":
|
|
323
|
+
"data-focus": domQuery.dataAttr(focused),
|
|
357
324
|
type: "button",
|
|
358
325
|
onClick() {
|
|
359
326
|
if (!interactive) return;
|
|
@@ -390,13 +357,13 @@ function connect(state, send, normalize) {
|
|
|
390
357
|
return normalize.element({
|
|
391
358
|
...parts.valueText.attrs,
|
|
392
359
|
dir: state.context.dir,
|
|
393
|
-
"data-disabled":
|
|
394
|
-
"data-focus":
|
|
360
|
+
"data-disabled": domQuery.dataAttr(disabled),
|
|
361
|
+
"data-focus": domQuery.dataAttr(focused)
|
|
395
362
|
});
|
|
396
363
|
},
|
|
397
364
|
getAreaProps(props = {}) {
|
|
398
365
|
const { xChannel, yChannel } = getAreaChannels(props);
|
|
399
|
-
const { areaStyles } =
|
|
366
|
+
const { areaStyles } = colorUtils.getColorAreaGradient(areaValue, {
|
|
400
367
|
xChannel,
|
|
401
368
|
yChannel,
|
|
402
369
|
dir: state.context.dir
|
|
@@ -407,9 +374,9 @@ function connect(state, send, normalize) {
|
|
|
407
374
|
role: "group",
|
|
408
375
|
onPointerDown(event) {
|
|
409
376
|
if (!interactive) return;
|
|
410
|
-
if (!
|
|
411
|
-
if (
|
|
412
|
-
const point =
|
|
377
|
+
if (!domEvent.isLeftClick(event)) return;
|
|
378
|
+
if (domEvent.isModifierKey(event)) return;
|
|
379
|
+
const point = domEvent.getEventPoint(event);
|
|
413
380
|
const channel = { xChannel, yChannel };
|
|
414
381
|
send({ type: "AREA.POINTER_DOWN", point, channel, id: "area" });
|
|
415
382
|
event.preventDefault();
|
|
@@ -424,7 +391,7 @@ function connect(state, send, normalize) {
|
|
|
424
391
|
},
|
|
425
392
|
getAreaBackgroundProps(props = {}) {
|
|
426
393
|
const { xChannel, yChannel } = getAreaChannels(props);
|
|
427
|
-
const { areaGradientStyles } =
|
|
394
|
+
const { areaGradientStyles } = colorUtils.getColorAreaGradient(areaValue, {
|
|
428
395
|
xChannel,
|
|
429
396
|
yChannel,
|
|
430
397
|
dir: state.context.dir
|
|
@@ -452,7 +419,7 @@ function connect(state, send, normalize) {
|
|
|
452
419
|
id: dom.getAreaThumbId(state.context),
|
|
453
420
|
dir: state.context.dir,
|
|
454
421
|
tabIndex: disabled ? void 0 : 0,
|
|
455
|
-
"data-disabled":
|
|
422
|
+
"data-disabled": domQuery.dataAttr(disabled),
|
|
456
423
|
role: "slider",
|
|
457
424
|
"aria-valuemin": 0,
|
|
458
425
|
"aria-valuemax": 100,
|
|
@@ -476,7 +443,7 @@ function connect(state, send, normalize) {
|
|
|
476
443
|
onKeyDown(event) {
|
|
477
444
|
if (event.defaultPrevented) return;
|
|
478
445
|
if (!interactive) return;
|
|
479
|
-
const step =
|
|
446
|
+
const step = domEvent.getEventStep(event);
|
|
480
447
|
const keyMap = {
|
|
481
448
|
ArrowUp() {
|
|
482
449
|
send({ type: "AREA.ARROW_UP", channel, step });
|
|
@@ -500,7 +467,7 @@ function connect(state, send, normalize) {
|
|
|
500
467
|
event2.stopPropagation();
|
|
501
468
|
}
|
|
502
469
|
};
|
|
503
|
-
const exec = keyMap[
|
|
470
|
+
const exec = keyMap[domEvent.getEventKey(event, state.context)];
|
|
504
471
|
if (exec) {
|
|
505
472
|
exec(event);
|
|
506
473
|
event.preventDefault();
|
|
@@ -535,9 +502,9 @@ function connect(state, send, normalize) {
|
|
|
535
502
|
role: "presentation",
|
|
536
503
|
onPointerDown(event) {
|
|
537
504
|
if (!interactive) return;
|
|
538
|
-
if (!
|
|
539
|
-
if (
|
|
540
|
-
const point =
|
|
505
|
+
if (!domEvent.isLeftClick(event)) return;
|
|
506
|
+
if (domEvent.isModifierKey(event)) return;
|
|
507
|
+
const point = domEvent.getEventPoint(event);
|
|
541
508
|
send({ type: "CHANNEL_SLIDER.POINTER_DOWN", channel, format, point, id: channel, orientation });
|
|
542
509
|
event.preventDefault();
|
|
543
510
|
},
|
|
@@ -605,9 +572,9 @@ function connect(state, send, normalize) {
|
|
|
605
572
|
"aria-label": channel,
|
|
606
573
|
tabIndex: disabled ? void 0 : 0,
|
|
607
574
|
"data-channel": channel,
|
|
608
|
-
"data-disabled":
|
|
575
|
+
"data-disabled": domQuery.dataAttr(disabled),
|
|
609
576
|
"data-orientation": orientation,
|
|
610
|
-
"aria-disabled":
|
|
577
|
+
"aria-disabled": domQuery.dataAttr(disabled),
|
|
611
578
|
"aria-orientation": orientation,
|
|
612
579
|
"aria-valuemax": channelRange.maxValue,
|
|
613
580
|
"aria-valuemin": channelRange.minValue,
|
|
@@ -626,7 +593,7 @@ function connect(state, send, normalize) {
|
|
|
626
593
|
onKeyDown(event) {
|
|
627
594
|
if (event.defaultPrevented) return;
|
|
628
595
|
if (!interactive) return;
|
|
629
|
-
const step =
|
|
596
|
+
const step = domEvent.getEventStep(event) * channelRange.step;
|
|
630
597
|
const keyMap = {
|
|
631
598
|
ArrowUp() {
|
|
632
599
|
send({ type: "CHANNEL_SLIDER.ARROW_UP", channel, step });
|
|
@@ -656,7 +623,7 @@ function connect(state, send, normalize) {
|
|
|
656
623
|
event2.stopPropagation();
|
|
657
624
|
}
|
|
658
625
|
};
|
|
659
|
-
const exec = keyMap[
|
|
626
|
+
const exec = keyMap[domEvent.getEventKey(event, state.context)];
|
|
660
627
|
if (exec) {
|
|
661
628
|
exec(event);
|
|
662
629
|
event.preventDefault();
|
|
@@ -677,7 +644,7 @@ function connect(state, send, normalize) {
|
|
|
677
644
|
spellCheck: false,
|
|
678
645
|
autoComplete: "off",
|
|
679
646
|
disabled,
|
|
680
|
-
"data-disabled":
|
|
647
|
+
"data-disabled": domQuery.dataAttr(disabled),
|
|
681
648
|
readOnly: state.context.readOnly,
|
|
682
649
|
defaultValue: getChannelValue(value, channel),
|
|
683
650
|
min: channelRange?.minValue,
|
|
@@ -724,7 +691,7 @@ function connect(state, send, normalize) {
|
|
|
724
691
|
readOnly: state.context.readOnly,
|
|
725
692
|
required: state.context.required,
|
|
726
693
|
id: dom.getHiddenInputId(state.context),
|
|
727
|
-
style:
|
|
694
|
+
style: domQuery.visuallyHiddenStyle,
|
|
728
695
|
defaultValue: valueAsString
|
|
729
696
|
});
|
|
730
697
|
},
|
|
@@ -734,7 +701,7 @@ function connect(state, send, normalize) {
|
|
|
734
701
|
type: "button",
|
|
735
702
|
dir: state.context.dir,
|
|
736
703
|
disabled,
|
|
737
|
-
"data-disabled":
|
|
704
|
+
"data-disabled": domQuery.dataAttr(disabled),
|
|
738
705
|
"aria-label": "Pick a color from the screen",
|
|
739
706
|
onClick() {
|
|
740
707
|
if (!interactive) return;
|
|
@@ -759,7 +726,7 @@ function connect(state, send, normalize) {
|
|
|
759
726
|
"aria-label": `select ${swatchState.valueAsString} as the color`,
|
|
760
727
|
"data-state": swatchState.checked ? "checked" : "unchecked",
|
|
761
728
|
"data-value": swatchState.valueAsString,
|
|
762
|
-
"data-disabled":
|
|
729
|
+
"data-disabled": domQuery.dataAttr(swatchState.disabled),
|
|
763
730
|
onClick() {
|
|
764
731
|
if (swatchState.disabled) return;
|
|
765
732
|
send({ type: "SWATCH_TRIGGER.CLICK", value: swatchState.value });
|
|
@@ -829,29 +796,15 @@ function assertFormat(format) {
|
|
|
829
796
|
if (formatRegex.test(format)) return format;
|
|
830
797
|
throw new Error(`Unsupported color format: ${format}`);
|
|
831
798
|
}
|
|
832
|
-
|
|
833
|
-
// src/color-picker.machine.ts
|
|
834
|
-
var import_color_utils5 = require("@zag-js/color-utils");
|
|
835
|
-
var import_core = require("@zag-js/core");
|
|
836
|
-
var import_dismissable = require("@zag-js/dismissable");
|
|
837
|
-
var import_dom_event3 = require("@zag-js/dom-event");
|
|
838
|
-
var import_dom_query3 = require("@zag-js/dom-query");
|
|
839
|
-
var import_form_utils = require("@zag-js/form-utils");
|
|
840
|
-
var import_popper2 = require("@zag-js/popper");
|
|
841
|
-
var import_text_selection = require("@zag-js/text-selection");
|
|
842
|
-
var import_utils = require("@zag-js/utils");
|
|
843
|
-
|
|
844
|
-
// src/color-picker.parse.ts
|
|
845
|
-
var import_color_utils4 = require("@zag-js/color-utils");
|
|
846
799
|
var parse = (colorString) => {
|
|
847
|
-
return
|
|
800
|
+
return colorUtils.parseColor(colorString);
|
|
848
801
|
};
|
|
849
802
|
|
|
850
803
|
// src/color-picker.machine.ts
|
|
851
|
-
var { and } =
|
|
804
|
+
var { and } = core.guards;
|
|
852
805
|
function machine(userContext) {
|
|
853
|
-
const ctx =
|
|
854
|
-
return
|
|
806
|
+
const ctx = utils.compact(userContext);
|
|
807
|
+
return core.createMachine(
|
|
855
808
|
{
|
|
856
809
|
id: "color-picker",
|
|
857
810
|
initial: ctx.open ? "open" : "idle",
|
|
@@ -1168,7 +1121,7 @@ function machine(userContext) {
|
|
|
1168
1121
|
ctx2.currentPlacement = ctx2.positioning.placement;
|
|
1169
1122
|
const anchorEl = dom.getTriggerEl(ctx2);
|
|
1170
1123
|
const getPositionerEl = () => dom.getPositionerEl(ctx2);
|
|
1171
|
-
return
|
|
1124
|
+
return popper.getPlacement(anchorEl, getPositionerEl, {
|
|
1172
1125
|
...ctx2.positioning,
|
|
1173
1126
|
defer: true,
|
|
1174
1127
|
onComplete(data) {
|
|
@@ -1178,7 +1131,7 @@ function machine(userContext) {
|
|
|
1178
1131
|
},
|
|
1179
1132
|
trackDismissableElement(ctx2, _evt, { send }) {
|
|
1180
1133
|
const getContentEl = () => dom.getContentEl(ctx2);
|
|
1181
|
-
return
|
|
1134
|
+
return dismissable.trackDismissableElement(getContentEl, {
|
|
1182
1135
|
exclude: dom.getTriggerEl(ctx2),
|
|
1183
1136
|
defer: true,
|
|
1184
1137
|
onInteractOutside(event) {
|
|
@@ -1195,7 +1148,7 @@ function machine(userContext) {
|
|
|
1195
1148
|
},
|
|
1196
1149
|
trackFormControl(ctx2, _evt, { send, initialContext }) {
|
|
1197
1150
|
const inputEl = dom.getHiddenInputEl(ctx2);
|
|
1198
|
-
return
|
|
1151
|
+
return formUtils.trackFormControl(inputEl, {
|
|
1199
1152
|
onFieldsetDisabledChange(disabled) {
|
|
1200
1153
|
ctx2.fieldsetDisabled = disabled;
|
|
1201
1154
|
},
|
|
@@ -1205,7 +1158,7 @@ function machine(userContext) {
|
|
|
1205
1158
|
});
|
|
1206
1159
|
},
|
|
1207
1160
|
trackPointerMove(ctx2, evt, { send }) {
|
|
1208
|
-
return
|
|
1161
|
+
return domEvent.trackPointerMove(dom.getDoc(ctx2), {
|
|
1209
1162
|
onPointerMove({ point }) {
|
|
1210
1163
|
const type = ctx2.activeId === "area" ? "AREA.POINTER_MOVE" : "CHANNEL_SLIDER.POINTER_MOVE";
|
|
1211
1164
|
send({ type, point, format: evt.format });
|
|
@@ -1217,7 +1170,7 @@ function machine(userContext) {
|
|
|
1217
1170
|
});
|
|
1218
1171
|
},
|
|
1219
1172
|
disableTextSelection(ctx2) {
|
|
1220
|
-
return
|
|
1173
|
+
return textSelection.disableTextSelection({ doc: dom.getDoc(ctx2), target: dom.getContentEl(ctx2) });
|
|
1221
1174
|
}
|
|
1222
1175
|
},
|
|
1223
1176
|
actions: {
|
|
@@ -1228,7 +1181,7 @@ function machine(userContext) {
|
|
|
1228
1181
|
const picker = new win.EyeDropper();
|
|
1229
1182
|
picker.open().then(({ sRGBHex }) => {
|
|
1230
1183
|
const format = ctx2.value.getFormat();
|
|
1231
|
-
const color =
|
|
1184
|
+
const color = colorUtils.parseColor(sRGBHex).toFormat(format);
|
|
1232
1185
|
set.value(ctx2, color);
|
|
1233
1186
|
ctx2.onValueChangeEnd?.({ value: ctx2.value, valueAsString: ctx2.valueAsString });
|
|
1234
1187
|
}).catch(() => void 0);
|
|
@@ -1285,7 +1238,7 @@ function machine(userContext) {
|
|
|
1285
1238
|
valueAsNumber = Number.isNaN(valueAsNumber) ? currentAlpha : valueAsNumber;
|
|
1286
1239
|
color = ctx2.value.withChannelValue("alpha", valueAsNumber);
|
|
1287
1240
|
} else if (isTextField) {
|
|
1288
|
-
color =
|
|
1241
|
+
color = utils.tryCatch(
|
|
1289
1242
|
() => parse(value).withChannelValue("alpha", currentAlpha),
|
|
1290
1243
|
() => ctx2.value
|
|
1291
1244
|
);
|
|
@@ -1336,18 +1289,18 @@ function machine(userContext) {
|
|
|
1336
1289
|
set.value(ctx2, color);
|
|
1337
1290
|
},
|
|
1338
1291
|
focusAreaThumb(ctx2) {
|
|
1339
|
-
|
|
1292
|
+
domQuery.raf(() => {
|
|
1340
1293
|
dom.getAreaThumbEl(ctx2)?.focus({ preventScroll: true });
|
|
1341
1294
|
});
|
|
1342
1295
|
},
|
|
1343
1296
|
focusChannelThumb(ctx2, evt) {
|
|
1344
|
-
|
|
1297
|
+
domQuery.raf(() => {
|
|
1345
1298
|
dom.getChannelSliderThumbEl(ctx2, evt.channel)?.focus({ preventScroll: true });
|
|
1346
1299
|
});
|
|
1347
1300
|
},
|
|
1348
1301
|
setInitialFocus(ctx2) {
|
|
1349
|
-
|
|
1350
|
-
const element =
|
|
1302
|
+
domQuery.raf(() => {
|
|
1303
|
+
const element = domQuery.getInitialFocus({
|
|
1351
1304
|
root: dom.getContentEl(ctx2),
|
|
1352
1305
|
getInitialEl: ctx2.initialFocusEl
|
|
1353
1306
|
});
|
|
@@ -1355,7 +1308,7 @@ function machine(userContext) {
|
|
|
1355
1308
|
});
|
|
1356
1309
|
},
|
|
1357
1310
|
setReturnFocus(ctx2) {
|
|
1358
|
-
|
|
1311
|
+
domQuery.raf(() => {
|
|
1359
1312
|
dom.getTriggerEl(ctx2)?.focus({ preventScroll: true });
|
|
1360
1313
|
});
|
|
1361
1314
|
},
|
|
@@ -1382,7 +1335,7 @@ var sync = {
|
|
|
1382
1335
|
// sync channel inputs
|
|
1383
1336
|
inputs(ctx, color) {
|
|
1384
1337
|
const channelInputs = dom.getChannelInputEls(ctx);
|
|
1385
|
-
|
|
1338
|
+
domQuery.raf(() => {
|
|
1386
1339
|
channelInputs.forEach((inputEl) => {
|
|
1387
1340
|
const channel = inputEl.dataset.channel;
|
|
1388
1341
|
dom.setValue(inputEl, getChannelValue(color || ctx.value, channel));
|
|
@@ -1392,7 +1345,7 @@ var sync = {
|
|
|
1392
1345
|
// sync format select
|
|
1393
1346
|
formatSelect(ctx) {
|
|
1394
1347
|
const selectEl = dom.getFormatSelectEl(ctx);
|
|
1395
|
-
|
|
1348
|
+
domQuery.raf(() => {
|
|
1396
1349
|
dom.setValue(selectEl, ctx.format);
|
|
1397
1350
|
});
|
|
1398
1351
|
}
|
|
@@ -1411,7 +1364,7 @@ var invoke = {
|
|
|
1411
1364
|
value,
|
|
1412
1365
|
valueAsString: ctx.valueAsString
|
|
1413
1366
|
});
|
|
1414
|
-
|
|
1367
|
+
formUtils.dispatchInputValueEvent(dom.getHiddenInputEl(ctx), { value: ctx.valueAsString });
|
|
1415
1368
|
},
|
|
1416
1369
|
formatChange(ctx) {
|
|
1417
1370
|
ctx.onFormatChange?.({ format: ctx.format });
|
|
@@ -1429,11 +1382,8 @@ var set = {
|
|
|
1429
1382
|
invoke.formatChange(ctx);
|
|
1430
1383
|
}
|
|
1431
1384
|
};
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
parse
|
|
1438
|
-
});
|
|
1439
|
-
//# sourceMappingURL=index.js.map
|
|
1385
|
+
|
|
1386
|
+
exports.anatomy = anatomy;
|
|
1387
|
+
exports.connect = connect;
|
|
1388
|
+
exports.machine = machine;
|
|
1389
|
+
exports.parse = parse;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
+
import { createAnatomy } from '@zag-js/anatomy';
|
|
2
|
+
import { normalizeColor, getColorAreaGradient, parseColor } from '@zag-js/color-utils';
|
|
3
|
+
import { getRelativePoint, isLeftClick, isModifierKey, getEventPoint, getEventStep, getEventKey, trackPointerMove } from '@zag-js/dom-event';
|
|
4
|
+
import { createScope, queryAll, dataAttr, query, visuallyHiddenStyle, raf, getInitialFocus } from '@zag-js/dom-query';
|
|
5
|
+
import { getPlacementStyles, getPlacement } from '@zag-js/popper';
|
|
6
|
+
import { createMachine, guards } from '@zag-js/core';
|
|
7
|
+
import { trackDismissableElement } from '@zag-js/dismissable';
|
|
8
|
+
import { trackFormControl, dispatchInputValueEvent } from '@zag-js/form-utils';
|
|
9
|
+
import { disableTextSelection } from '@zag-js/text-selection';
|
|
10
|
+
import { compact, tryCatch } from '@zag-js/utils';
|
|
11
|
+
|
|
1
12
|
// src/color-picker.anatomy.ts
|
|
2
|
-
import { createAnatomy } from "@zag-js/anatomy";
|
|
3
13
|
var anatomy = createAnatomy("color-picker", [
|
|
4
14
|
"root",
|
|
5
15
|
"label",
|
|
@@ -27,22 +37,6 @@ var anatomy = createAnatomy("color-picker", [
|
|
|
27
37
|
"formatSelect"
|
|
28
38
|
]);
|
|
29
39
|
var parts = anatomy.build();
|
|
30
|
-
|
|
31
|
-
// src/color-picker.connect.ts
|
|
32
|
-
import { getColorAreaGradient, normalizeColor } from "@zag-js/color-utils";
|
|
33
|
-
import {
|
|
34
|
-
getEventKey,
|
|
35
|
-
getEventPoint,
|
|
36
|
-
getEventStep,
|
|
37
|
-
isLeftClick,
|
|
38
|
-
isModifierKey
|
|
39
|
-
} from "@zag-js/dom-event";
|
|
40
|
-
import { dataAttr, query, visuallyHiddenStyle } from "@zag-js/dom-query";
|
|
41
|
-
import { getPlacementStyles } from "@zag-js/popper";
|
|
42
|
-
|
|
43
|
-
// src/color-picker.dom.ts
|
|
44
|
-
import { getRelativePoint } from "@zag-js/dom-event";
|
|
45
|
-
import { createScope, queryAll } from "@zag-js/dom-query";
|
|
46
40
|
var dom = createScope({
|
|
47
41
|
getRootId: (ctx) => ctx.ids?.root ?? `color-picker:${ctx.id}`,
|
|
48
42
|
getLabelId: (ctx) => ctx.ids?.label ?? `color-picker:${ctx.id}:label`,
|
|
@@ -95,9 +89,6 @@ var dom = createScope({
|
|
|
95
89
|
];
|
|
96
90
|
}
|
|
97
91
|
});
|
|
98
|
-
|
|
99
|
-
// src/utils/get-channel-display-color.ts
|
|
100
|
-
import { parseColor } from "@zag-js/color-utils";
|
|
101
92
|
function getChannelDisplayColor(color, channel) {
|
|
102
93
|
switch (channel) {
|
|
103
94
|
case "hue":
|
|
@@ -116,9 +107,6 @@ function getChannelDisplayColor(color, channel) {
|
|
|
116
107
|
throw new Error("Unknown color channel: " + channel);
|
|
117
108
|
}
|
|
118
109
|
}
|
|
119
|
-
|
|
120
|
-
// src/utils/get-channel-input-value.ts
|
|
121
|
-
import { parseColor as parseColor2 } from "@zag-js/color-utils";
|
|
122
110
|
function getChannelValue(color, channel) {
|
|
123
111
|
if (channel == null) return "";
|
|
124
112
|
if (channel === "hex") {
|
|
@@ -151,8 +139,8 @@ function getChannelValue(color, channel) {
|
|
|
151
139
|
function getChannelRange(color, channel) {
|
|
152
140
|
switch (channel) {
|
|
153
141
|
case "hex":
|
|
154
|
-
const minColor =
|
|
155
|
-
const maxColor =
|
|
142
|
+
const minColor = parseColor("#000000");
|
|
143
|
+
const maxColor = parseColor("#FFFFFF");
|
|
156
144
|
return {
|
|
157
145
|
minValue: minColor.toHexInt(),
|
|
158
146
|
maxValue: maxColor.toHexInt(),
|
|
@@ -806,22 +794,8 @@ function assertFormat(format) {
|
|
|
806
794
|
if (formatRegex.test(format)) return format;
|
|
807
795
|
throw new Error(`Unsupported color format: ${format}`);
|
|
808
796
|
}
|
|
809
|
-
|
|
810
|
-
// src/color-picker.machine.ts
|
|
811
|
-
import { parseColor as parseColor4 } from "@zag-js/color-utils";
|
|
812
|
-
import { createMachine, guards } from "@zag-js/core";
|
|
813
|
-
import { trackDismissableElement } from "@zag-js/dismissable";
|
|
814
|
-
import { trackPointerMove } from "@zag-js/dom-event";
|
|
815
|
-
import { getInitialFocus, raf } from "@zag-js/dom-query";
|
|
816
|
-
import { dispatchInputValueEvent, trackFormControl } from "@zag-js/form-utils";
|
|
817
|
-
import { getPlacement } from "@zag-js/popper";
|
|
818
|
-
import { disableTextSelection } from "@zag-js/text-selection";
|
|
819
|
-
import { compact, tryCatch } from "@zag-js/utils";
|
|
820
|
-
|
|
821
|
-
// src/color-picker.parse.ts
|
|
822
|
-
import { parseColor as parseColor3 } from "@zag-js/color-utils";
|
|
823
797
|
var parse = (colorString) => {
|
|
824
|
-
return
|
|
798
|
+
return parseColor(colorString);
|
|
825
799
|
};
|
|
826
800
|
|
|
827
801
|
// src/color-picker.machine.ts
|
|
@@ -1205,7 +1179,7 @@ function machine(userContext) {
|
|
|
1205
1179
|
const picker = new win.EyeDropper();
|
|
1206
1180
|
picker.open().then(({ sRGBHex }) => {
|
|
1207
1181
|
const format = ctx2.value.getFormat();
|
|
1208
|
-
const color =
|
|
1182
|
+
const color = parseColor(sRGBHex).toFormat(format);
|
|
1209
1183
|
set.value(ctx2, color);
|
|
1210
1184
|
ctx2.onValueChangeEnd?.({ value: ctx2.value, valueAsString: ctx2.valueAsString });
|
|
1211
1185
|
}).catch(() => void 0);
|
|
@@ -1406,10 +1380,5 @@ var set = {
|
|
|
1406
1380
|
invoke.formatChange(ctx);
|
|
1407
1381
|
}
|
|
1408
1382
|
};
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
connect,
|
|
1412
|
-
machine,
|
|
1413
|
-
parse
|
|
1414
|
-
};
|
|
1415
|
-
//# sourceMappingURL=index.mjs.map
|
|
1383
|
+
|
|
1384
|
+
export { anatomy, connect, machine, parse };
|