@zag-js/color-picker 0.9.2 → 0.10.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/{chunk-KYNJURCY.mjs → chunk-5QSFKCT5.mjs} +1 -1
- package/dist/{chunk-EUTH4EDN.mjs → chunk-ML3WX6YS.mjs} +4 -3
- package/dist/{chunk-JOGAQ7RL.mjs → chunk-SPSDVZCT.mjs} +5 -5
- package/dist/color-picker.connect.js +4 -4
- package/dist/color-picker.connect.mjs +2 -2
- package/dist/color-picker.dom.d.ts +1 -12
- package/dist/color-picker.dom.js +4 -4
- package/dist/color-picker.dom.mjs +1 -1
- package/dist/color-picker.machine.js +7 -6
- package/dist/color-picker.machine.mjs +2 -2
- package/dist/index.js +7 -6
- package/dist/index.mjs +3 -3
- package/package.json +12 -11
- package/src/color-picker.anatomy.ts +18 -0
- package/src/color-picker.connect.ts +409 -0
- package/src/color-picker.dom.ts +41 -0
- package/src/color-picker.machine.ts +358 -0
- package/src/color-picker.types.ts +113 -0
- package/src/index.ts +9 -0
- package/src/utils/generate-format-background.ts +139 -0
- package/src/utils/get-channel-details.ts +60 -0
- package/src/utils/get-channel-display-color.ts +20 -0
- package/src/utils/get-channel-input-value.ts +23 -0
- package/src/utils/get-color-area-gradient.ts +84 -0
- package/src/utils/get-slider-background.ts +43 -0
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-2ERX54SV.mjs";
|
|
4
4
|
import {
|
|
5
5
|
dom
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-SPSDVZCT.mjs";
|
|
7
7
|
import {
|
|
8
8
|
getChannelDetails
|
|
9
9
|
} from "./chunk-KLLIOTK6.mjs";
|
|
@@ -40,6 +40,7 @@ function machine(userContext) {
|
|
|
40
40
|
actions: ["setValue"]
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
|
+
created: ["setValueAsColor"],
|
|
43
44
|
watch: {
|
|
44
45
|
value: ["setValueAsColor", "syncChannelInputs", "invokeOnChange"]
|
|
45
46
|
},
|
|
@@ -224,8 +225,8 @@ function machine(userContext) {
|
|
|
224
225
|
const channel = evt.channel || ctx2.activeId;
|
|
225
226
|
const percent = dom.getChannelSliderValueFromPoint(ctx2, evt.point, channel);
|
|
226
227
|
const { minValue, maxValue, step } = ctx2.valueAsColor.getChannelRange(channel);
|
|
227
|
-
const
|
|
228
|
-
const point =
|
|
228
|
+
const orientation = ctx2.activeOrientation || "horizontal";
|
|
229
|
+
const point = orientation === "horizontal" ? percent.x : percent.y;
|
|
229
230
|
const channelValue = getPercentValue(point, minValue, maxValue, step);
|
|
230
231
|
const value = snapValueToStep(channelValue - step, minValue, maxValue, step);
|
|
231
232
|
const newColor = ctx2.valueAsColor.withChannelValue(channel, value);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/color-picker.dom.ts
|
|
2
|
-
import {
|
|
2
|
+
import { getRelativePoint } from "@zag-js/dom-event";
|
|
3
3
|
import { createScope, queryAll } from "@zag-js/dom-query";
|
|
4
4
|
var dom = createScope({
|
|
5
5
|
getContentId: (ctx) => ctx.ids?.content ?? `color-picker:${ctx.id}:content`,
|
|
@@ -15,15 +15,15 @@ var dom = createScope({
|
|
|
15
15
|
getChannelInputEl: (ctx, channel) => dom.queryById(ctx, dom.getChannelInputId(ctx, channel)),
|
|
16
16
|
getAreaEl: (ctx) => dom.queryById(ctx, dom.getAreaId(ctx)),
|
|
17
17
|
getAreaValueFromPoint(ctx, point) {
|
|
18
|
-
const
|
|
19
|
-
return
|
|
18
|
+
const { percent } = getRelativePoint(point, dom.getAreaEl(ctx));
|
|
19
|
+
return percent;
|
|
20
20
|
},
|
|
21
21
|
getChannelSliderTrackEl: (ctx, channel) => {
|
|
22
22
|
return dom.queryById(ctx, dom.getChannelSliderTrackId(ctx, channel));
|
|
23
23
|
},
|
|
24
24
|
getChannelSliderValueFromPoint(ctx, point, channel) {
|
|
25
|
-
const
|
|
26
|
-
return
|
|
25
|
+
const { percent } = getRelativePoint(point, dom.getChannelSliderTrackEl(ctx, channel));
|
|
26
|
+
return percent;
|
|
27
27
|
},
|
|
28
28
|
getChannelInputEls: (ctx) => {
|
|
29
29
|
return queryAll(dom.getContentEl(ctx), "input[data-channel]");
|
|
@@ -62,15 +62,15 @@ var dom = (0, import_dom_query.createScope)({
|
|
|
62
62
|
getChannelInputEl: (ctx, channel) => dom.queryById(ctx, dom.getChannelInputId(ctx, channel)),
|
|
63
63
|
getAreaEl: (ctx) => dom.queryById(ctx, dom.getAreaId(ctx)),
|
|
64
64
|
getAreaValueFromPoint(ctx, point) {
|
|
65
|
-
const
|
|
66
|
-
return
|
|
65
|
+
const { percent } = (0, import_dom_event.getRelativePoint)(point, dom.getAreaEl(ctx));
|
|
66
|
+
return percent;
|
|
67
67
|
},
|
|
68
68
|
getChannelSliderTrackEl: (ctx, channel) => {
|
|
69
69
|
return dom.queryById(ctx, dom.getChannelSliderTrackId(ctx, channel));
|
|
70
70
|
},
|
|
71
71
|
getChannelSliderValueFromPoint(ctx, point, channel) {
|
|
72
|
-
const
|
|
73
|
-
return
|
|
72
|
+
const { percent } = (0, import_dom_event.getRelativePoint)(point, dom.getChannelSliderTrackEl(ctx, channel));
|
|
73
|
+
return percent;
|
|
74
74
|
},
|
|
75
75
|
getChannelInputEls: (ctx) => {
|
|
76
76
|
return (0, import_dom_query.queryAll)(dom.getContentEl(ctx), "input[data-channel]");
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
connect
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-5QSFKCT5.mjs";
|
|
4
4
|
import "./chunk-JNBNPPMF.mjs";
|
|
5
5
|
import "./chunk-KO4TBUXB.mjs";
|
|
6
6
|
import "./chunk-3XH465XT.mjs";
|
|
7
7
|
import "./chunk-75JXJMB5.mjs";
|
|
8
8
|
import "./chunk-2ERX54SV.mjs";
|
|
9
|
-
import "./chunk-
|
|
9
|
+
import "./chunk-SPSDVZCT.mjs";
|
|
10
10
|
import "./chunk-OY3B7NXA.mjs";
|
|
11
11
|
import "./chunk-KLLIOTK6.mjs";
|
|
12
12
|
export {
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { ColorChannel } from '@zag-js/color-utils';
|
|
2
|
+
import { Point } from '@zag-js/dom-event';
|
|
2
3
|
import { MachineContext } from './color-picker.types.js';
|
|
3
4
|
import '@zag-js/core';
|
|
4
5
|
import '@zag-js/types';
|
|
5
6
|
|
|
6
|
-
type Point = {
|
|
7
|
-
x: number;
|
|
8
|
-
y: number;
|
|
9
|
-
};
|
|
10
7
|
declare const dom: {
|
|
11
8
|
getRootNode: (ctx: {
|
|
12
9
|
getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
|
|
@@ -42,19 +39,11 @@ declare const dom: {
|
|
|
42
39
|
getAreaValueFromPoint(ctx: MachineContext, point: Point): {
|
|
43
40
|
x: number;
|
|
44
41
|
y: number;
|
|
45
|
-
normalize(options?: {
|
|
46
|
-
dir?: "ltr" | "rtl" | undefined;
|
|
47
|
-
orientation?: "horizontal" | "vertical" | undefined;
|
|
48
|
-
}): number;
|
|
49
42
|
};
|
|
50
43
|
getChannelSliderTrackEl: (ctx: MachineContext, channel: ColorChannel) => HTMLElement;
|
|
51
44
|
getChannelSliderValueFromPoint(ctx: MachineContext, point: Point, channel: ColorChannel): {
|
|
52
45
|
x: number;
|
|
53
46
|
y: number;
|
|
54
|
-
normalize(options?: {
|
|
55
|
-
dir?: "ltr" | "rtl" | undefined;
|
|
56
|
-
orientation?: "horizontal" | "vertical" | undefined;
|
|
57
|
-
}): number;
|
|
58
47
|
};
|
|
59
48
|
getChannelInputEls: (ctx: MachineContext) => HTMLInputElement[];
|
|
60
49
|
};
|
package/dist/color-picker.dom.js
CHANGED
|
@@ -39,15 +39,15 @@ var dom = (0, import_dom_query.createScope)({
|
|
|
39
39
|
getChannelInputEl: (ctx, channel) => dom.queryById(ctx, dom.getChannelInputId(ctx, channel)),
|
|
40
40
|
getAreaEl: (ctx) => dom.queryById(ctx, dom.getAreaId(ctx)),
|
|
41
41
|
getAreaValueFromPoint(ctx, point) {
|
|
42
|
-
const
|
|
43
|
-
return
|
|
42
|
+
const { percent } = (0, import_dom_event.getRelativePoint)(point, dom.getAreaEl(ctx));
|
|
43
|
+
return percent;
|
|
44
44
|
},
|
|
45
45
|
getChannelSliderTrackEl: (ctx, channel) => {
|
|
46
46
|
return dom.queryById(ctx, dom.getChannelSliderTrackId(ctx, channel));
|
|
47
47
|
},
|
|
48
48
|
getChannelSliderValueFromPoint(ctx, point, channel) {
|
|
49
|
-
const
|
|
50
|
-
return
|
|
49
|
+
const { percent } = (0, import_dom_event.getRelativePoint)(point, dom.getChannelSliderTrackEl(ctx, channel));
|
|
50
|
+
return percent;
|
|
51
51
|
},
|
|
52
52
|
getChannelInputEls: (ctx) => {
|
|
53
53
|
return (0, import_dom_query.queryAll)(dom.getContentEl(ctx), "input[data-channel]");
|
|
@@ -48,15 +48,15 @@ var dom = (0, import_dom_query.createScope)({
|
|
|
48
48
|
getChannelInputEl: (ctx, channel) => dom.queryById(ctx, dom.getChannelInputId(ctx, channel)),
|
|
49
49
|
getAreaEl: (ctx) => dom.queryById(ctx, dom.getAreaId(ctx)),
|
|
50
50
|
getAreaValueFromPoint(ctx, point) {
|
|
51
|
-
const
|
|
52
|
-
return
|
|
51
|
+
const { percent } = (0, import_dom_event.getRelativePoint)(point, dom.getAreaEl(ctx));
|
|
52
|
+
return percent;
|
|
53
53
|
},
|
|
54
54
|
getChannelSliderTrackEl: (ctx, channel) => {
|
|
55
55
|
return dom.queryById(ctx, dom.getChannelSliderTrackId(ctx, channel));
|
|
56
56
|
},
|
|
57
57
|
getChannelSliderValueFromPoint(ctx, point, channel) {
|
|
58
|
-
const
|
|
59
|
-
return
|
|
58
|
+
const { percent } = (0, import_dom_event.getRelativePoint)(point, dom.getChannelSliderTrackEl(ctx, channel));
|
|
59
|
+
return percent;
|
|
60
60
|
},
|
|
61
61
|
getChannelInputEls: (ctx) => {
|
|
62
62
|
return (0, import_dom_query.queryAll)(dom.getContentEl(ctx), "input[data-channel]");
|
|
@@ -152,6 +152,7 @@ function machine(userContext) {
|
|
|
152
152
|
actions: ["setValue"]
|
|
153
153
|
}
|
|
154
154
|
},
|
|
155
|
+
created: ["setValueAsColor"],
|
|
155
156
|
watch: {
|
|
156
157
|
value: ["setValueAsColor", "syncChannelInputs", "invokeOnChange"]
|
|
157
158
|
},
|
|
@@ -336,8 +337,8 @@ function machine(userContext) {
|
|
|
336
337
|
const channel = evt.channel || ctx2.activeId;
|
|
337
338
|
const percent = dom.getChannelSliderValueFromPoint(ctx2, evt.point, channel);
|
|
338
339
|
const { minValue, maxValue, step } = ctx2.valueAsColor.getChannelRange(channel);
|
|
339
|
-
const
|
|
340
|
-
const point =
|
|
340
|
+
const orientation = ctx2.activeOrientation || "horizontal";
|
|
341
|
+
const point = orientation === "horizontal" ? percent.x : percent.y;
|
|
341
342
|
const channelValue = (0, import_numeric_range2.getPercentValue)(point, minValue, maxValue, step);
|
|
342
343
|
const value = (0, import_numeric_range2.snapValueToStep)(channelValue - step, minValue, maxValue, step);
|
|
343
344
|
const newColor = ctx2.valueAsColor.withChannelValue(channel, value);
|
package/dist/index.js
CHANGED
|
@@ -66,15 +66,15 @@ var dom = (0, import_dom_query.createScope)({
|
|
|
66
66
|
getChannelInputEl: (ctx, channel) => dom.queryById(ctx, dom.getChannelInputId(ctx, channel)),
|
|
67
67
|
getAreaEl: (ctx) => dom.queryById(ctx, dom.getAreaId(ctx)),
|
|
68
68
|
getAreaValueFromPoint(ctx, point) {
|
|
69
|
-
const
|
|
70
|
-
return
|
|
69
|
+
const { percent } = (0, import_dom_event.getRelativePoint)(point, dom.getAreaEl(ctx));
|
|
70
|
+
return percent;
|
|
71
71
|
},
|
|
72
72
|
getChannelSliderTrackEl: (ctx, channel) => {
|
|
73
73
|
return dom.queryById(ctx, dom.getChannelSliderTrackId(ctx, channel));
|
|
74
74
|
},
|
|
75
75
|
getChannelSliderValueFromPoint(ctx, point, channel) {
|
|
76
|
-
const
|
|
77
|
-
return
|
|
76
|
+
const { percent } = (0, import_dom_event.getRelativePoint)(point, dom.getChannelSliderTrackEl(ctx, channel));
|
|
77
|
+
return percent;
|
|
78
78
|
},
|
|
79
79
|
getChannelInputEls: (ctx) => {
|
|
80
80
|
return (0, import_dom_query.queryAll)(dom.getContentEl(ctx), "input[data-channel]");
|
|
@@ -783,6 +783,7 @@ function machine(userContext) {
|
|
|
783
783
|
actions: ["setValue"]
|
|
784
784
|
}
|
|
785
785
|
},
|
|
786
|
+
created: ["setValueAsColor"],
|
|
786
787
|
watch: {
|
|
787
788
|
value: ["setValueAsColor", "syncChannelInputs", "invokeOnChange"]
|
|
788
789
|
},
|
|
@@ -967,8 +968,8 @@ function machine(userContext) {
|
|
|
967
968
|
const channel = evt.channel || ctx2.activeId;
|
|
968
969
|
const percent = dom.getChannelSliderValueFromPoint(ctx2, evt.point, channel);
|
|
969
970
|
const { minValue, maxValue, step } = ctx2.valueAsColor.getChannelRange(channel);
|
|
970
|
-
const
|
|
971
|
-
const point =
|
|
971
|
+
const orientation = ctx2.activeOrientation || "horizontal";
|
|
972
|
+
const point = orientation === "horizontal" ? percent.x : percent.y;
|
|
972
973
|
const channelValue = (0, import_numeric_range2.getPercentValue)(point, minValue, maxValue, step);
|
|
973
974
|
const value = (0, import_numeric_range2.snapValueToStep)(channelValue - step, minValue, maxValue, step);
|
|
974
975
|
const newColor = ctx2.valueAsColor.withChannelValue(channel, value);
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
connect
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-5QSFKCT5.mjs";
|
|
4
4
|
import "./chunk-JNBNPPMF.mjs";
|
|
5
5
|
import "./chunk-KO4TBUXB.mjs";
|
|
6
6
|
import "./chunk-3XH465XT.mjs";
|
|
@@ -9,9 +9,9 @@ import {
|
|
|
9
9
|
} from "./chunk-75JXJMB5.mjs";
|
|
10
10
|
import {
|
|
11
11
|
machine
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-ML3WX6YS.mjs";
|
|
13
13
|
import "./chunk-2ERX54SV.mjs";
|
|
14
|
-
import "./chunk-
|
|
14
|
+
import "./chunk-SPSDVZCT.mjs";
|
|
15
15
|
import "./chunk-OY3B7NXA.mjs";
|
|
16
16
|
import "./chunk-KLLIOTK6.mjs";
|
|
17
17
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/color-picker",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Core logic for the color-picker widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"repository": "https://github.com/chakra-ui/zag/tree/main/packages/color-picker",
|
|
19
19
|
"sideEffects": false,
|
|
20
20
|
"files": [
|
|
21
|
-
"dist
|
|
21
|
+
"dist",
|
|
22
|
+
"src"
|
|
22
23
|
],
|
|
23
24
|
"publishConfig": {
|
|
24
25
|
"access": "public"
|
|
@@ -27,15 +28,15 @@
|
|
|
27
28
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
28
29
|
},
|
|
29
30
|
"dependencies": {
|
|
30
|
-
"@zag-js/core": "0.
|
|
31
|
-
"@zag-js/anatomy": "0.
|
|
32
|
-
"@zag-js/dom-query": "0.
|
|
33
|
-
"@zag-js/dom-event": "0.
|
|
34
|
-
"@zag-js/utils": "0.
|
|
35
|
-
"@zag-js/color-utils": "0.
|
|
36
|
-
"@zag-js/numeric-range": "0.
|
|
37
|
-
"@zag-js/text-selection": "0.
|
|
38
|
-
"@zag-js/types": "0.
|
|
31
|
+
"@zag-js/core": "0.10.0",
|
|
32
|
+
"@zag-js/anatomy": "0.10.0",
|
|
33
|
+
"@zag-js/dom-query": "0.10.0",
|
|
34
|
+
"@zag-js/dom-event": "0.10.0",
|
|
35
|
+
"@zag-js/utils": "0.10.0",
|
|
36
|
+
"@zag-js/color-utils": "0.10.0",
|
|
37
|
+
"@zag-js/numeric-range": "0.10.0",
|
|
38
|
+
"@zag-js/text-selection": "0.10.0",
|
|
39
|
+
"@zag-js/types": "0.10.0"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"clean-package": "2.2.0"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createAnatomy } from "@zag-js/anatomy"
|
|
2
|
+
|
|
3
|
+
export const anatomy = createAnatomy("color-picker", [
|
|
4
|
+
"area",
|
|
5
|
+
"areaThumb",
|
|
6
|
+
"areaGradient",
|
|
7
|
+
"channelSliderTrack",
|
|
8
|
+
"channelSliderTrackBg",
|
|
9
|
+
"channelSliderThumb",
|
|
10
|
+
"channelInput",
|
|
11
|
+
"swatch",
|
|
12
|
+
"swatchBg",
|
|
13
|
+
"content",
|
|
14
|
+
"label",
|
|
15
|
+
"eyeDropTrigger",
|
|
16
|
+
])
|
|
17
|
+
|
|
18
|
+
export const parts = anatomy.build()
|