@zag-js/color-picker 0.9.1 → 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.
@@ -16,14 +16,21 @@ import {
16
16
  } from "./chunk-2ERX54SV.mjs";
17
17
  import {
18
18
  dom
19
- } from "./chunk-JOGAQ7RL.mjs";
19
+ } from "./chunk-SPSDVZCT.mjs";
20
20
  import {
21
21
  getChannelDetails
22
22
  } from "./chunk-KLLIOTK6.mjs";
23
23
 
24
24
  // src/color-picker.connect.ts
25
25
  import { normalizeColor } from "@zag-js/color-utils";
26
- import { getEventKey, getEventStep, getNativeEvent, isLeftClick, isModifiedEvent } from "@zag-js/dom-event";
26
+ import {
27
+ getEventKey,
28
+ getEventPoint,
29
+ getEventStep,
30
+ getNativeEvent,
31
+ isLeftClick,
32
+ isModifiedEvent
33
+ } from "@zag-js/dom-event";
27
34
  import { dataAttr } from "@zag-js/dom-query";
28
35
  function connect(state, send, normalize) {
29
36
  const valueAsColor = state.context.valueAsColor;
@@ -85,7 +92,7 @@ function connect(state, send, normalize) {
85
92
  const evt = getNativeEvent(event);
86
93
  if (!isLeftClick(evt) || isModifiedEvent(evt))
87
94
  return;
88
- const point = { x: evt.clientX, y: evt.clientY };
95
+ const point = getEventPoint(evt);
89
96
  const channel = { xChannel, yChannel };
90
97
  send({ type: "AREA.POINTER_DOWN", point, channel, id: "area" });
91
98
  },
@@ -180,7 +187,7 @@ function connect(state, send, normalize) {
180
187
  const evt = getNativeEvent(event);
181
188
  if (!isLeftClick(evt) || isModifiedEvent(evt))
182
189
  return;
183
- const point = { x: evt.clientX, y: evt.clientY };
190
+ const point = getEventPoint(evt);
184
191
  send({ type: "CHANNEL_SLIDER.POINTER_DOWN", channel, point, id: channel, orientation });
185
192
  },
186
193
  style: {
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-2ERX54SV.mjs";
4
4
  import {
5
5
  dom
6
- } from "./chunk-JOGAQ7RL.mjs";
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 position = ctx2.activeOrientation || "horizontal";
228
- const point = position === "horizontal" ? percent.x : percent.y;
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 { getRelativePointPercent } from "@zag-js/dom-event";
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 areaEl = dom.getAreaEl(ctx);
19
- return getRelativePointPercent(point, areaEl);
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 areaEl = dom.getChannelSliderTrackEl(ctx, channel);
26
- return getRelativePointPercent(point, areaEl);
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 areaEl = dom.getAreaEl(ctx);
66
- return (0, import_dom_event.getRelativePointPercent)(point, areaEl);
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 areaEl = dom.getChannelSliderTrackEl(ctx, channel);
73
- return (0, import_dom_event.getRelativePointPercent)(point, areaEl);
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]");
@@ -451,7 +451,7 @@ function connect(state, send, normalize) {
451
451
  const evt = (0, import_dom_event2.getNativeEvent)(event);
452
452
  if (!(0, import_dom_event2.isLeftClick)(evt) || (0, import_dom_event2.isModifiedEvent)(evt))
453
453
  return;
454
- const point = { x: evt.clientX, y: evt.clientY };
454
+ const point = (0, import_dom_event2.getEventPoint)(evt);
455
455
  const channel = { xChannel, yChannel };
456
456
  send({ type: "AREA.POINTER_DOWN", point, channel, id: "area" });
457
457
  },
@@ -546,7 +546,7 @@ function connect(state, send, normalize) {
546
546
  const evt = (0, import_dom_event2.getNativeEvent)(event);
547
547
  if (!(0, import_dom_event2.isLeftClick)(evt) || (0, import_dom_event2.isModifiedEvent)(evt))
548
548
  return;
549
- const point = { x: evt.clientX, y: evt.clientY };
549
+ const point = (0, import_dom_event2.getEventPoint)(evt);
550
550
  send({ type: "CHANNEL_SLIDER.POINTER_DOWN", channel, point, id: channel, orientation });
551
551
  },
552
552
  style: {
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  connect
3
- } from "./chunk-HSUD4DN3.mjs";
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-JOGAQ7RL.mjs";
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
  };
@@ -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 areaEl = dom.getAreaEl(ctx);
43
- return (0, import_dom_event.getRelativePointPercent)(point, areaEl);
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 areaEl = dom.getChannelSliderTrackEl(ctx, channel);
50
- return (0, import_dom_event.getRelativePointPercent)(point, areaEl);
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]");
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  dom
3
- } from "./chunk-JOGAQ7RL.mjs";
3
+ } from "./chunk-SPSDVZCT.mjs";
4
4
  export {
5
5
  dom
6
6
  };
@@ -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 areaEl = dom.getAreaEl(ctx);
52
- return (0, import_dom_event.getRelativePointPercent)(point, areaEl);
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 areaEl = dom.getChannelSliderTrackEl(ctx, channel);
59
- return (0, import_dom_event.getRelativePointPercent)(point, areaEl);
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 position = ctx2.activeOrientation || "horizontal";
340
- const point = position === "horizontal" ? percent.x : percent.y;
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);
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  machine
3
- } from "./chunk-EUTH4EDN.mjs";
3
+ } from "./chunk-ML3WX6YS.mjs";
4
4
  import "./chunk-2ERX54SV.mjs";
5
- import "./chunk-JOGAQ7RL.mjs";
5
+ import "./chunk-SPSDVZCT.mjs";
6
6
  import "./chunk-KLLIOTK6.mjs";
7
7
  export {
8
8
  machine
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 areaEl = dom.getAreaEl(ctx);
70
- return (0, import_dom_event.getRelativePointPercent)(point, areaEl);
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 areaEl = dom.getChannelSliderTrackEl(ctx, channel);
77
- return (0, import_dom_event.getRelativePointPercent)(point, areaEl);
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]");
@@ -455,7 +455,7 @@ function connect(state, send, normalize) {
455
455
  const evt = (0, import_dom_event2.getNativeEvent)(event);
456
456
  if (!(0, import_dom_event2.isLeftClick)(evt) || (0, import_dom_event2.isModifiedEvent)(evt))
457
457
  return;
458
- const point = { x: evt.clientX, y: evt.clientY };
458
+ const point = (0, import_dom_event2.getEventPoint)(evt);
459
459
  const channel = { xChannel, yChannel };
460
460
  send({ type: "AREA.POINTER_DOWN", point, channel, id: "area" });
461
461
  },
@@ -550,7 +550,7 @@ function connect(state, send, normalize) {
550
550
  const evt = (0, import_dom_event2.getNativeEvent)(event);
551
551
  if (!(0, import_dom_event2.isLeftClick)(evt) || (0, import_dom_event2.isModifiedEvent)(evt))
552
552
  return;
553
- const point = { x: evt.clientX, y: evt.clientY };
553
+ const point = (0, import_dom_event2.getEventPoint)(evt);
554
554
  send({ type: "CHANNEL_SLIDER.POINTER_DOWN", channel, point, id: channel, orientation });
555
555
  },
556
556
  style: {
@@ -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 position = ctx2.activeOrientation || "horizontal";
971
- const point = position === "horizontal" ? percent.x : percent.y;
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-HSUD4DN3.mjs";
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-EUTH4EDN.mjs";
12
+ } from "./chunk-ML3WX6YS.mjs";
13
13
  import "./chunk-2ERX54SV.mjs";
14
- import "./chunk-JOGAQ7RL.mjs";
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.9.1",
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.9.1",
31
- "@zag-js/anatomy": "0.9.1",
32
- "@zag-js/dom-query": "0.9.1",
33
- "@zag-js/dom-event": "0.9.1",
34
- "@zag-js/utils": "0.9.1",
35
- "@zag-js/color-utils": "0.9.1",
36
- "@zag-js/numeric-range": "0.9.1",
37
- "@zag-js/text-selection": "0.9.1",
38
- "@zag-js/types": "0.9.1"
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()