@zag-js/color-picker 2.0.0-next.1 → 2.0.0-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/color-picker.connect.js +3 -4
- package/dist/color-picker.connect.mjs +4 -5
- package/dist/color-picker.types.d.mts +21 -20
- package/dist/color-picker.types.d.ts +21 -20
- package/dist/utils/get-area-format.js +0 -1
- package/dist/utils/get-area-format.mjs +0 -1
- package/dist/utils/get-slider-background.js +2 -1
- package/dist/utils/get-slider-background.mjs +2 -1
- package/package.json +10 -10
|
@@ -126,9 +126,7 @@ function connect(service, normalize) {
|
|
|
126
126
|
inline: !!prop("inline"),
|
|
127
127
|
setOpen(nextOpen) {
|
|
128
128
|
if (prop("inline")) return;
|
|
129
|
-
|
|
130
|
-
if (open2 === nextOpen) return;
|
|
131
|
-
send({ type: nextOpen ? "OPEN" : "CLOSE" });
|
|
129
|
+
send({ type: nextOpen ? "OPEN" : "CLOSE", replaces: "open" });
|
|
132
130
|
},
|
|
133
131
|
setValue(value2) {
|
|
134
132
|
send({ type: "VALUE.SET", value: (0, import_color_utils.normalizeColor)(value2), src: "set-color" });
|
|
@@ -361,6 +359,7 @@ function connect(service, normalize) {
|
|
|
361
359
|
"data-invalid": (0, import_dom_query2.dataAttr)(invalid),
|
|
362
360
|
"data-readonly": (0, import_dom_query2.dataAttr)(readOnly),
|
|
363
361
|
role: "slider",
|
|
362
|
+
"aria-disabled": (0, import_dom_query2.ariaAttr)(disabled),
|
|
364
363
|
"aria-valuemin": 0,
|
|
365
364
|
"aria-valuemax": 100,
|
|
366
365
|
"aria-valuenow": xValue,
|
|
@@ -518,7 +517,7 @@ function connect(service, normalize) {
|
|
|
518
517
|
"data-channel": channel,
|
|
519
518
|
"data-disabled": (0, import_dom_query2.dataAttr)(disabled),
|
|
520
519
|
"data-orientation": orientation,
|
|
521
|
-
"aria-disabled": (0, import_dom_query2.
|
|
520
|
+
"aria-disabled": (0, import_dom_query2.ariaAttr)(disabled),
|
|
522
521
|
"aria-orientation": orientation,
|
|
523
522
|
"aria-valuemax": channelRange.maxValue,
|
|
524
523
|
"aria-valuemin": channelRange.minValue,
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
isLeftClick,
|
|
10
10
|
isModifierKey
|
|
11
11
|
} from "@zag-js/dom-query";
|
|
12
|
-
import { dataAttr, query, visuallyHiddenStyle } from "@zag-js/dom-query";
|
|
12
|
+
import { ariaAttr, dataAttr, query, visuallyHiddenStyle } from "@zag-js/dom-query";
|
|
13
13
|
import { getPlacementSide, getPlacementStyles } from "@zag-js/popper";
|
|
14
14
|
import { parts } from "./color-picker.anatomy.mjs";
|
|
15
15
|
import * as dom from "./color-picker.dom.mjs";
|
|
@@ -99,9 +99,7 @@ function connect(service, normalize) {
|
|
|
99
99
|
inline: !!prop("inline"),
|
|
100
100
|
setOpen(nextOpen) {
|
|
101
101
|
if (prop("inline")) return;
|
|
102
|
-
|
|
103
|
-
if (open2 === nextOpen) return;
|
|
104
|
-
send({ type: nextOpen ? "OPEN" : "CLOSE" });
|
|
102
|
+
send({ type: nextOpen ? "OPEN" : "CLOSE", replaces: "open" });
|
|
105
103
|
},
|
|
106
104
|
setValue(value2) {
|
|
107
105
|
send({ type: "VALUE.SET", value: normalizeColor(value2), src: "set-color" });
|
|
@@ -334,6 +332,7 @@ function connect(service, normalize) {
|
|
|
334
332
|
"data-invalid": dataAttr(invalid),
|
|
335
333
|
"data-readonly": dataAttr(readOnly),
|
|
336
334
|
role: "slider",
|
|
335
|
+
"aria-disabled": ariaAttr(disabled),
|
|
337
336
|
"aria-valuemin": 0,
|
|
338
337
|
"aria-valuemax": 100,
|
|
339
338
|
"aria-valuenow": xValue,
|
|
@@ -491,7 +490,7 @@ function connect(service, normalize) {
|
|
|
491
490
|
"data-channel": channel,
|
|
492
491
|
"data-disabled": dataAttr(disabled),
|
|
493
492
|
"data-orientation": orientation,
|
|
494
|
-
"aria-disabled":
|
|
493
|
+
"aria-disabled": ariaAttr(disabled),
|
|
495
494
|
"aria-orientation": orientation,
|
|
496
495
|
"aria-valuemax": channelRange.maxValue,
|
|
497
496
|
"aria-valuemin": channelRange.minValue,
|
|
@@ -5,7 +5,7 @@ import { Service, EventObject, Machine } from '@zag-js/core';
|
|
|
5
5
|
import { InteractOutsideHandlers, LayerSnapshot } from '@zag-js/dismissable';
|
|
6
6
|
import { PositioningOptions, Placement, PlacementSide } from '@zag-js/popper';
|
|
7
7
|
export { PositioningOptions } from '@zag-js/popper';
|
|
8
|
-
import {
|
|
8
|
+
import { CommonProperties, DirectionProperty, Orientation, PropTypes } from '@zag-js/types';
|
|
9
9
|
|
|
10
10
|
type ExtendedColorChannel = ColorChannel | "hex" | "css";
|
|
11
11
|
interface EyeDropper {
|
|
@@ -33,23 +33,23 @@ interface OpenChangeDetails {
|
|
|
33
33
|
interface FormatChangeDetails {
|
|
34
34
|
format: ColorFormat;
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
root
|
|
38
|
-
control
|
|
39
|
-
trigger
|
|
40
|
-
label
|
|
41
|
-
input
|
|
42
|
-
hiddenInput
|
|
43
|
-
content
|
|
44
|
-
area
|
|
45
|
-
areaGradient
|
|
46
|
-
positioner
|
|
47
|
-
formatSelect
|
|
48
|
-
areaThumb
|
|
49
|
-
channelInput
|
|
50
|
-
channelSliderTrack
|
|
51
|
-
channelSliderThumb
|
|
52
|
-
}
|
|
36
|
+
interface ElementIds {
|
|
37
|
+
root?: string | undefined;
|
|
38
|
+
control?: string | undefined;
|
|
39
|
+
trigger?: string | undefined;
|
|
40
|
+
label?: string | undefined;
|
|
41
|
+
input?: string | undefined;
|
|
42
|
+
hiddenInput?: string | undefined;
|
|
43
|
+
content?: string | undefined;
|
|
44
|
+
area?: string | undefined;
|
|
45
|
+
areaGradient?: string | undefined;
|
|
46
|
+
positioner?: string | undefined;
|
|
47
|
+
formatSelect?: string | undefined;
|
|
48
|
+
areaThumb?: string | undefined;
|
|
49
|
+
channelInput?: ((id: string) => string) | undefined;
|
|
50
|
+
channelSliderTrack?: ((id: ColorChannel) => string) | undefined;
|
|
51
|
+
channelSliderThumb?: ((id: ColorChannel) => string) | undefined;
|
|
52
|
+
}
|
|
53
53
|
interface ColorPickerProps extends CommonProperties, DirectionProperty, InteractOutsideHandlers {
|
|
54
54
|
/**
|
|
55
55
|
* The ids of the elements in the color picker. Useful for composition.
|
|
@@ -104,7 +104,7 @@ interface ColorPickerProps extends CommonProperties, DirectionProperty, Interact
|
|
|
104
104
|
/**
|
|
105
105
|
* The initial focus element when the color picker is opened.
|
|
106
106
|
*/
|
|
107
|
-
initialFocusEl?: (() => HTMLElement | null) | undefined;
|
|
107
|
+
initialFocusEl?: (() => HTMLElement | null) | null | undefined;
|
|
108
108
|
/**
|
|
109
109
|
* The controlled open state of the color picker
|
|
110
110
|
*/
|
|
@@ -147,7 +147,8 @@ type PropsWithDefault = "defaultFormat" | "defaultValue" | "openAutoFocus" | "di
|
|
|
147
147
|
type ColorPickerSchema = {
|
|
148
148
|
tag: "open" | "closed" | "dragging" | "focused";
|
|
149
149
|
state: "idle" | "focused" | "open" | "open.idle" | "open.dragging";
|
|
150
|
-
props:
|
|
150
|
+
props: ColorPickerProps;
|
|
151
|
+
defaultPropKey: PropsWithDefault;
|
|
151
152
|
computed: {
|
|
152
153
|
disabled: boolean;
|
|
153
154
|
rtl: boolean;
|
|
@@ -5,7 +5,7 @@ import { Service, EventObject, Machine } from '@zag-js/core';
|
|
|
5
5
|
import { InteractOutsideHandlers, LayerSnapshot } from '@zag-js/dismissable';
|
|
6
6
|
import { PositioningOptions, Placement, PlacementSide } from '@zag-js/popper';
|
|
7
7
|
export { PositioningOptions } from '@zag-js/popper';
|
|
8
|
-
import {
|
|
8
|
+
import { CommonProperties, DirectionProperty, Orientation, PropTypes } from '@zag-js/types';
|
|
9
9
|
|
|
10
10
|
type ExtendedColorChannel = ColorChannel | "hex" | "css";
|
|
11
11
|
interface EyeDropper {
|
|
@@ -33,23 +33,23 @@ interface OpenChangeDetails {
|
|
|
33
33
|
interface FormatChangeDetails {
|
|
34
34
|
format: ColorFormat;
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
root
|
|
38
|
-
control
|
|
39
|
-
trigger
|
|
40
|
-
label
|
|
41
|
-
input
|
|
42
|
-
hiddenInput
|
|
43
|
-
content
|
|
44
|
-
area
|
|
45
|
-
areaGradient
|
|
46
|
-
positioner
|
|
47
|
-
formatSelect
|
|
48
|
-
areaThumb
|
|
49
|
-
channelInput
|
|
50
|
-
channelSliderTrack
|
|
51
|
-
channelSliderThumb
|
|
52
|
-
}
|
|
36
|
+
interface ElementIds {
|
|
37
|
+
root?: string | undefined;
|
|
38
|
+
control?: string | undefined;
|
|
39
|
+
trigger?: string | undefined;
|
|
40
|
+
label?: string | undefined;
|
|
41
|
+
input?: string | undefined;
|
|
42
|
+
hiddenInput?: string | undefined;
|
|
43
|
+
content?: string | undefined;
|
|
44
|
+
area?: string | undefined;
|
|
45
|
+
areaGradient?: string | undefined;
|
|
46
|
+
positioner?: string | undefined;
|
|
47
|
+
formatSelect?: string | undefined;
|
|
48
|
+
areaThumb?: string | undefined;
|
|
49
|
+
channelInput?: ((id: string) => string) | undefined;
|
|
50
|
+
channelSliderTrack?: ((id: ColorChannel) => string) | undefined;
|
|
51
|
+
channelSliderThumb?: ((id: ColorChannel) => string) | undefined;
|
|
52
|
+
}
|
|
53
53
|
interface ColorPickerProps extends CommonProperties, DirectionProperty, InteractOutsideHandlers {
|
|
54
54
|
/**
|
|
55
55
|
* The ids of the elements in the color picker. Useful for composition.
|
|
@@ -104,7 +104,7 @@ interface ColorPickerProps extends CommonProperties, DirectionProperty, Interact
|
|
|
104
104
|
/**
|
|
105
105
|
* The initial focus element when the color picker is opened.
|
|
106
106
|
*/
|
|
107
|
-
initialFocusEl?: (() => HTMLElement | null) | undefined;
|
|
107
|
+
initialFocusEl?: (() => HTMLElement | null) | null | undefined;
|
|
108
108
|
/**
|
|
109
109
|
* The controlled open state of the color picker
|
|
110
110
|
*/
|
|
@@ -147,7 +147,8 @@ type PropsWithDefault = "defaultFormat" | "defaultValue" | "openAutoFocus" | "di
|
|
|
147
147
|
type ColorPickerSchema = {
|
|
148
148
|
tag: "open" | "closed" | "dragging" | "focused";
|
|
149
149
|
state: "idle" | "focused" | "open" | "open.idle" | "open.dragging";
|
|
150
|
-
props:
|
|
150
|
+
props: ColorPickerProps;
|
|
151
|
+
defaultPropKey: PropsWithDefault;
|
|
151
152
|
computed: {
|
|
152
153
|
disabled: boolean;
|
|
153
154
|
rtl: boolean;
|
|
@@ -26,7 +26,6 @@ module.exports = __toCommonJS(get_area_format_exports);
|
|
|
26
26
|
function getAreaFormat(format) {
|
|
27
27
|
if (format.startsWith("hsl")) return "hsla";
|
|
28
28
|
if (format.startsWith("hsb")) return "hsba";
|
|
29
|
-
if (format.startsWith("rgb")) return "rgba";
|
|
30
29
|
if (format === "oklab") return "hsba";
|
|
31
30
|
if (format === "oklch") return "hsba";
|
|
32
31
|
return "hsba";
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
function getAreaFormat(format) {
|
|
3
3
|
if (format.startsWith("hsl")) return "hsla";
|
|
4
4
|
if (format.startsWith("hsb")) return "hsba";
|
|
5
|
-
if (format.startsWith("rgb")) return "rgba";
|
|
6
5
|
if (format === "oklab") return "hsba";
|
|
7
6
|
if (format === "oklch") return "hsba";
|
|
8
7
|
return "hsba";
|
|
@@ -35,7 +35,6 @@ function getSliderBackgroundDirection(orientation, dir) {
|
|
|
35
35
|
var getSliderBackground = (props) => {
|
|
36
36
|
const { channel, value, dir, orientation } = props;
|
|
37
37
|
const bgDirection = getSliderBackgroundDirection(orientation, dir);
|
|
38
|
-
const { minValue, maxValue } = value.getChannelRange(channel);
|
|
39
38
|
const fmt = value.getFormat();
|
|
40
39
|
switch (channel) {
|
|
41
40
|
case "hue":
|
|
@@ -46,6 +45,7 @@ var getSliderBackground = (props) => {
|
|
|
46
45
|
}
|
|
47
46
|
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%)`;
|
|
48
47
|
case "lightness": {
|
|
48
|
+
const { minValue, maxValue } = value.getChannelRange(channel);
|
|
49
49
|
let start = value.withChannelValue(channel, minValue).toString("css");
|
|
50
50
|
let middle = value.withChannelValue(channel, (maxValue - minValue) / 2).toString("css");
|
|
51
51
|
let end = value.withChannelValue(channel, maxValue).toString("css");
|
|
@@ -60,6 +60,7 @@ var getSliderBackground = (props) => {
|
|
|
60
60
|
case "a":
|
|
61
61
|
case "b":
|
|
62
62
|
case "chroma": {
|
|
63
|
+
const { minValue, maxValue } = value.getChannelRange(channel);
|
|
63
64
|
let start = value.withChannelValue(channel, minValue).toString("css");
|
|
64
65
|
let end = value.withChannelValue(channel, maxValue).toString("css");
|
|
65
66
|
if (fmt === "oklab" && (channel === "a" || channel === "b")) {
|
|
@@ -11,7 +11,6 @@ function getSliderBackgroundDirection(orientation, dir) {
|
|
|
11
11
|
var getSliderBackground = (props) => {
|
|
12
12
|
const { channel, value, dir, orientation } = props;
|
|
13
13
|
const bgDirection = getSliderBackgroundDirection(orientation, dir);
|
|
14
|
-
const { minValue, maxValue } = value.getChannelRange(channel);
|
|
15
14
|
const fmt = value.getFormat();
|
|
16
15
|
switch (channel) {
|
|
17
16
|
case "hue":
|
|
@@ -22,6 +21,7 @@ var getSliderBackground = (props) => {
|
|
|
22
21
|
}
|
|
23
22
|
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%)`;
|
|
24
23
|
case "lightness": {
|
|
24
|
+
const { minValue, maxValue } = value.getChannelRange(channel);
|
|
25
25
|
let start = value.withChannelValue(channel, minValue).toString("css");
|
|
26
26
|
let middle = value.withChannelValue(channel, (maxValue - minValue) / 2).toString("css");
|
|
27
27
|
let end = value.withChannelValue(channel, maxValue).toString("css");
|
|
@@ -36,6 +36,7 @@ var getSliderBackground = (props) => {
|
|
|
36
36
|
case "a":
|
|
37
37
|
case "b":
|
|
38
38
|
case "chroma": {
|
|
39
|
+
const { minValue, maxValue } = value.getChannelRange(channel);
|
|
39
40
|
let start = value.withChannelValue(channel, minValue).toString("css");
|
|
40
41
|
let end = value.withChannelValue(channel, maxValue).toString("css");
|
|
41
42
|
if (fmt === "oklab" && (channel === "a" || channel === "b")) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/color-picker",
|
|
3
|
-
"version": "2.0.0-next.
|
|
3
|
+
"version": "2.0.0-next.3",
|
|
4
4
|
"description": "Core logic for the color-picker widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -30,14 +30,14 @@
|
|
|
30
30
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@zag-js/core": "2.0.0-next.
|
|
34
|
-
"@zag-js/anatomy": "2.0.0-next.
|
|
35
|
-
"@zag-js/dom-query": "2.0.0-next.
|
|
36
|
-
"@zag-js/dismissable": "2.0.0-next.
|
|
37
|
-
"@zag-js/utils": "2.0.0-next.
|
|
38
|
-
"@zag-js/color-utils": "2.0.0-next.
|
|
39
|
-
"@zag-js/popper": "2.0.0-next.
|
|
40
|
-
"@zag-js/types": "2.0.0-next.
|
|
33
|
+
"@zag-js/core": "2.0.0-next.3",
|
|
34
|
+
"@zag-js/anatomy": "2.0.0-next.3",
|
|
35
|
+
"@zag-js/dom-query": "2.0.0-next.3",
|
|
36
|
+
"@zag-js/dismissable": "2.0.0-next.3",
|
|
37
|
+
"@zag-js/utils": "2.0.0-next.3",
|
|
38
|
+
"@zag-js/color-utils": "2.0.0-next.3",
|
|
39
|
+
"@zag-js/popper": "2.0.0-next.3",
|
|
40
|
+
"@zag-js/types": "2.0.0-next.3"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"clean-package": "2.2.0"
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|
|
72
72
|
"build": "tsup",
|
|
73
|
-
"lint": "
|
|
73
|
+
"lint": "oxlint src",
|
|
74
74
|
"typecheck": "tsc --noEmit"
|
|
75
75
|
}
|
|
76
76
|
}
|