@zag-js/color-picker 0.10.2 → 0.10.4

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.
Files changed (54) hide show
  1. package/dist/color-picker.anatomy.d.ts +3 -6
  2. package/dist/color-picker.anatomy.js +10 -33
  3. package/dist/color-picker.anatomy.mjs +19 -8
  4. package/dist/color-picker.connect.d.ts +4 -8
  5. package/dist/color-picker.connect.js +56 -436
  6. package/dist/color-picker.connect.mjs +368 -14
  7. package/dist/color-picker.dom.d.ts +27 -32
  8. package/dist/color-picker.dom.js +12 -34
  9. package/dist/color-picker.dom.mjs +33 -6
  10. package/dist/color-picker.machine.d.ts +3 -8
  11. package/dist/color-picker.machine.js +46 -163
  12. package/dist/color-picker.machine.mjs +335 -8
  13. package/dist/color-picker.types.d.ts +14 -16
  14. package/dist/index.d.ts +4 -8
  15. package/dist/index.js +8 -1085
  16. package/dist/index.mjs +3 -21
  17. package/dist/utils/generate-format-background.d.ts +9 -11
  18. package/dist/utils/generate-format-background.js +22 -53
  19. package/dist/utils/generate-format-background.mjs +120 -21
  20. package/dist/utils/get-channel-details.d.ts +3 -7
  21. package/dist/utils/get-channel-details.js +15 -37
  22. package/dist/utils/get-channel-details.mjs +53 -6
  23. package/dist/utils/get-channel-display-color.d.ts +3 -5
  24. package/dist/utils/get-channel-display-color.js +8 -30
  25. package/dist/utils/get-channel-display-color.mjs +22 -6
  26. package/dist/utils/get-channel-input-value.d.ts +5 -10
  27. package/dist/utils/get-channel-input-value.js +6 -30
  28. package/dist/utils/get-channel-input-value.mjs +21 -8
  29. package/dist/utils/get-color-area-gradient.d.ts +6 -10
  30. package/dist/utils/get-color-area-gradient.js +14 -158
  31. package/dist/utils/get-color-area-gradient.mjs +61 -7
  32. package/dist/utils/get-slider-background.d.ts +2 -8
  33. package/dist/utils/get-slider-background.js +6 -29
  34. package/dist/utils/get-slider-background.mjs +38 -5
  35. package/package.json +11 -16
  36. package/src/color-picker.connect.ts +1 -1
  37. package/src/color-picker.dom.ts +1 -1
  38. package/src/color-picker.types.ts +3 -1
  39. package/src/index.ts +2 -0
  40. package/src/utils/get-channel-details.ts +2 -2
  41. package/src/utils/get-channel-display-color.ts +1 -1
  42. package/src/utils/get-color-area-gradient.ts +1 -1
  43. package/dist/chunk-2ERX54SV.mjs +0 -25
  44. package/dist/chunk-3XH465XT.mjs +0 -42
  45. package/dist/chunk-5QSFKCT5.mjs +0 -393
  46. package/dist/chunk-75JXJMB5.mjs +0 -22
  47. package/dist/chunk-JNBNPPMF.mjs +0 -24
  48. package/dist/chunk-KLLIOTK6.mjs +0 -55
  49. package/dist/chunk-KO4TBUXB.mjs +0 -74
  50. package/dist/chunk-ML3WX6YS.mjs +0 -345
  51. package/dist/chunk-OY3B7NXA.mjs +0 -132
  52. package/dist/chunk-SPSDVZCT.mjs +0 -35
  53. package/dist/color-picker.types.js +0 -18
  54. package/dist/color-picker.types.mjs +0 -0
@@ -1,14 +1,368 @@
1
- import {
2
- connect
3
- } from "./chunk-5QSFKCT5.mjs";
4
- import "./chunk-JNBNPPMF.mjs";
5
- import "./chunk-KO4TBUXB.mjs";
6
- import "./chunk-3XH465XT.mjs";
7
- import "./chunk-75JXJMB5.mjs";
8
- import "./chunk-2ERX54SV.mjs";
9
- import "./chunk-SPSDVZCT.mjs";
10
- import "./chunk-OY3B7NXA.mjs";
11
- import "./chunk-KLLIOTK6.mjs";
12
- export {
13
- connect
14
- };
1
+ import { normalizeColor } from '@zag-js/color-utils';
2
+ import { getNativeEvent, isLeftClick, isModifiedEvent, getEventPoint, getEventStep, getEventKey } from '@zag-js/dom-event';
3
+ import { dataAttr } from '@zag-js/dom-query';
4
+ import { parts } from './color-picker.anatomy.mjs';
5
+ import { dom } from './color-picker.dom.mjs';
6
+ import { getChannelDetails } from './utils/get-channel-details.mjs';
7
+ import { getChannelDisplayColor } from './utils/get-channel-display-color.mjs';
8
+ import { getChannelInputRange, getChannelInputValue } from './utils/get-channel-input-value.mjs';
9
+ import { getColorAreaGradient } from './utils/get-color-area-gradient.mjs';
10
+ import { getSliderBgImage } from './utils/get-slider-background.mjs';
11
+
12
+ function connect(state, send, normalize) {
13
+ const valueAsColor = state.context.valueAsColor;
14
+ const isDisabled = state.context.disabled;
15
+ const isInteractive = state.context.isInteractive;
16
+ const isDragging = state.matches("dragging");
17
+ const channels = valueAsColor.getColorChannels();
18
+ return {
19
+ /**
20
+ * Whether the color picker is being dragged
21
+ */
22
+ isDragging,
23
+ /**
24
+ * The current color value (as a string)
25
+ */
26
+ value: state.context.value,
27
+ /**
28
+ * The current color value (as a Color object)
29
+ */
30
+ valueAsColor,
31
+ /**
32
+ * The current color channels of the color
33
+ */
34
+ channels,
35
+ /**
36
+ * Function to set the color value
37
+ */
38
+ setColor(value) {
39
+ send({ type: "VALUE.SET", value: normalizeColor(value), src: "set-color" });
40
+ },
41
+ /**
42
+ * Function to set the color value of a specific channel
43
+ */
44
+ setChannelValue(channel, value) {
45
+ const color = valueAsColor.withChannelValue(channel, value);
46
+ send({ type: "VALUE.SET", value: color, src: "set-channel" });
47
+ },
48
+ /**
49
+ * Function to set the color format
50
+ */
51
+ setFormat(format) {
52
+ const value = valueAsColor.toFormat(format);
53
+ send({ type: "VALUE.SET", value, src: "set-format" });
54
+ },
55
+ contentProps: normalize.element({
56
+ ...parts.content.attrs,
57
+ id: dom.getContentId(state.context)
58
+ }),
59
+ getAreaProps(props) {
60
+ const { xChannel, yChannel } = props;
61
+ const { areaStyles } = getColorAreaGradient(state.context, xChannel, yChannel);
62
+ return normalize.element({
63
+ ...parts.area.attrs,
64
+ id: dom.getAreaId(state.context),
65
+ role: "group",
66
+ onPointerDown(event) {
67
+ if (!isInteractive)
68
+ return;
69
+ const evt = getNativeEvent(event);
70
+ if (!isLeftClick(evt) || isModifiedEvent(evt))
71
+ return;
72
+ const point = getEventPoint(evt);
73
+ const channel = { xChannel, yChannel };
74
+ send({ type: "AREA.POINTER_DOWN", point, channel, id: "area" });
75
+ },
76
+ style: {
77
+ position: "relative",
78
+ touchAction: "none",
79
+ forcedColorAdjust: "none",
80
+ ...areaStyles
81
+ }
82
+ });
83
+ },
84
+ getAreaGradientProps(props) {
85
+ const { xChannel, yChannel } = props;
86
+ const { areaGradientStyles } = getColorAreaGradient(state.context, xChannel, yChannel);
87
+ return normalize.element({
88
+ ...parts.areaGradient.attrs,
89
+ id: dom.getAreaGradientId(state.context),
90
+ style: {
91
+ position: "relative",
92
+ touchAction: "none",
93
+ forcedColorAdjust: "none",
94
+ ...areaGradientStyles
95
+ }
96
+ });
97
+ },
98
+ getAreaThumbProps(props) {
99
+ const { xChannel, yChannel } = props;
100
+ const { getThumbPosition } = getChannelDetails(valueAsColor, xChannel, yChannel);
101
+ const { x, y } = getThumbPosition();
102
+ const channel = { xChannel, yChannel };
103
+ return normalize.element({
104
+ ...parts.areaThumb.attrs,
105
+ id: dom.getAreaThumbId(state.context),
106
+ tabIndex: isDisabled ? void 0 : 0,
107
+ "data-disabled": dataAttr(isDisabled),
108
+ role: "presentation",
109
+ style: {
110
+ position: "absolute",
111
+ left: `${x * 100}%`,
112
+ top: `${y * 100}%`,
113
+ transform: "translate(-50%, -50%)",
114
+ touchAction: "none",
115
+ forcedColorAdjust: "none",
116
+ background: valueAsColor.withChannelValue("alpha", 1).toString("css")
117
+ },
118
+ onBlur() {
119
+ send("AREA.BLUR");
120
+ },
121
+ onKeyDown(event) {
122
+ if (!isInteractive)
123
+ return;
124
+ const step = getEventStep(event);
125
+ const keyMap = {
126
+ ArrowUp() {
127
+ send({ type: "AREA.ARROW_UP", channel, step });
128
+ },
129
+ ArrowDown() {
130
+ send({ type: "AREA.ARROW_DOWN", channel, step });
131
+ },
132
+ ArrowLeft() {
133
+ send({ type: "AREA.ARROW_LEFT", channel, step });
134
+ },
135
+ ArrowRight() {
136
+ send({ type: "AREA.ARROW_RIGHT", channel, step });
137
+ },
138
+ PageUp() {
139
+ send({ type: "AREA.PAGE_UP", channel, step });
140
+ },
141
+ PageDown() {
142
+ send({ type: "AREA.PAGE_DOWN", channel, step });
143
+ }
144
+ };
145
+ const exec = keyMap[getEventKey(event, state.context)];
146
+ if (exec) {
147
+ exec(event);
148
+ event.preventDefault();
149
+ }
150
+ }
151
+ });
152
+ },
153
+ getChannelSliderTrackProps(props) {
154
+ const { orientation = "horizontal", channel } = props;
155
+ return normalize.element({
156
+ ...parts.channelSliderTrack.attrs,
157
+ id: dom.getChannelSliderTrackId(state.context, channel),
158
+ role: "group",
159
+ "data-channel": channel,
160
+ "data-orientation": orientation,
161
+ onPointerDown(event) {
162
+ if (!isInteractive)
163
+ return;
164
+ const evt = getNativeEvent(event);
165
+ if (!isLeftClick(evt) || isModifiedEvent(evt))
166
+ return;
167
+ const point = getEventPoint(evt);
168
+ send({ type: "CHANNEL_SLIDER.POINTER_DOWN", channel, point, id: channel, orientation });
169
+ },
170
+ style: {
171
+ position: "relative",
172
+ touchAction: "none",
173
+ forcedColorAdjust: "none",
174
+ backgroundImage: getSliderBgImage(state.context, { orientation, channel })
175
+ }
176
+ });
177
+ },
178
+ getChannelSliderBackgroundProps(props) {
179
+ const { orientation = "horizontal", channel } = props;
180
+ return normalize.element({
181
+ ...parts.channelSliderTrackBg.attrs,
182
+ "data-orientation": orientation,
183
+ "data-channel": channel,
184
+ style: {
185
+ position: "absolute",
186
+ backgroundColor: "#fff",
187
+ backgroundImage: [
188
+ "linear-gradient(-45deg,#0000 75.5%,#bcbcbc 75.5%)",
189
+ "linear-gradient(45deg,#0000 75.5%,#bcbcbc 75.5%)",
190
+ "linear-gradient(-45deg,#bcbcbc 25.5%,#0000 25.5%)",
191
+ "linear-gradient(45deg,#bcbcbc 25.5%,#0000 25.5%)"
192
+ ].join(","),
193
+ backgroundSize: "16px 16px",
194
+ backgroundPosition: "-2px -2px,-2px 6px,6px -10px,-10px -2px",
195
+ inset: 0,
196
+ zIndex: -1
197
+ }
198
+ });
199
+ },
200
+ getChannelSliderThumbProps(props) {
201
+ const { orientation = "horizontal", channel } = props;
202
+ const { minValue, maxValue, step: stepValue } = valueAsColor.getChannelRange(channel);
203
+ const channelValue = valueAsColor.getChannelValue(channel);
204
+ const offset = (channelValue - minValue) / (maxValue - minValue);
205
+ const placementStyles = orientation === "horizontal" ? { left: `${offset * 100}%`, top: "50%" } : { top: `${offset * 100}%`, left: "50%" };
206
+ return normalize.element({
207
+ ...parts.channelSliderThumb.attrs,
208
+ id: dom.getChannelSliderThumbId(state.context, channel),
209
+ role: "slider",
210
+ "aria-label": channel,
211
+ tabIndex: isDisabled ? void 0 : 0,
212
+ "data-channel": channel,
213
+ "data-disabled": dataAttr(isDisabled),
214
+ "data-orientation": orientation,
215
+ "aria-disabled": dataAttr(isDisabled),
216
+ "aria-orientation": orientation,
217
+ "aria-valuemax": maxValue,
218
+ "aria-valuemin": minValue,
219
+ "aria-valuenow": channelValue,
220
+ style: {
221
+ forcedColorAdjust: "none",
222
+ position: "absolute",
223
+ background: getChannelDisplayColor(valueAsColor, channel).toString("css"),
224
+ ...placementStyles
225
+ },
226
+ onFocus() {
227
+ if (!isInteractive)
228
+ return;
229
+ send({ type: "CHANNEL_SLIDER.FOCUS", channel });
230
+ },
231
+ onBlur() {
232
+ if (!isInteractive)
233
+ return;
234
+ send({ type: "CHANNEL_SLIDER.BLUR", channel });
235
+ },
236
+ onKeyDown(event) {
237
+ if (!isInteractive)
238
+ return;
239
+ const step = getEventStep(event) * stepValue;
240
+ const keyMap = {
241
+ ArrowUp() {
242
+ send({ type: "CHANNEL_SLIDER.ARROW_UP", channel, step });
243
+ },
244
+ ArrowDown() {
245
+ send({ type: "CHANNEL_SLIDER.ARROW_DOWN", channel, step });
246
+ },
247
+ ArrowLeft() {
248
+ send({ type: "CHANNEL_SLIDER.ARROW_LEFT", channel, step });
249
+ },
250
+ ArrowRight() {
251
+ send({ type: "CHANNEL_SLIDER.ARROW_RIGHT", channel, step });
252
+ },
253
+ PageUp() {
254
+ send({ type: "CHANNEL_SLIDER.PAGE_UP", channel });
255
+ },
256
+ PageDown() {
257
+ send({ type: "CHANNEL_SLIDER.PAGE_DOWN", channel });
258
+ },
259
+ Home() {
260
+ send({ type: "CHANNEL_SLIDER.HOME", channel });
261
+ },
262
+ End() {
263
+ send({ type: "CHANNEL_SLIDER.END", channel });
264
+ }
265
+ };
266
+ const exec = keyMap[getEventKey(event, state.context)];
267
+ if (exec) {
268
+ exec(event);
269
+ event.preventDefault();
270
+ }
271
+ }
272
+ });
273
+ },
274
+ getChannelInputProps(props) {
275
+ const { channel } = props;
276
+ const isTextField = channel === "hex" || channel === "css";
277
+ const range = getChannelInputRange(valueAsColor, channel);
278
+ return normalize.input({
279
+ ...parts.channelInput.attrs,
280
+ type: isTextField ? "text" : "number",
281
+ "data-channel": channel,
282
+ "aria-label": channel,
283
+ disabled: isDisabled,
284
+ "data-disabled": dataAttr(isDisabled),
285
+ readOnly: state.context.readOnly,
286
+ id: dom.getChannelInputId(state.context, channel),
287
+ defaultValue: getChannelInputValue(valueAsColor, channel),
288
+ min: range?.minValue,
289
+ max: range?.maxValue,
290
+ step: range?.step,
291
+ onFocus() {
292
+ send({ type: "CHANNEL_INPUT.FOCUS", channel });
293
+ },
294
+ onChange(event) {
295
+ if (isTextField)
296
+ return;
297
+ const value = event.currentTarget.value;
298
+ send({ type: "CHANNEL_INPUT.CHANGE", channel, value, isTextField });
299
+ },
300
+ onBlur(event) {
301
+ const value = event.currentTarget.value;
302
+ send({ type: "CHANNEL_INPUT.BLUR", channel, value, isTextField });
303
+ },
304
+ onKeyDown(event) {
305
+ if (!isTextField)
306
+ return;
307
+ if (event.key === "Enter") {
308
+ const value = event.currentTarget.value;
309
+ send({ type: "CHANNEL_INPUT.CHANGE", channel, value, isTextField });
310
+ }
311
+ },
312
+ style: {
313
+ appearance: "none",
314
+ WebkitAppearance: "none",
315
+ MozAppearance: "textfield"
316
+ }
317
+ });
318
+ },
319
+ eyeDropperTriggerProps: normalize.button({
320
+ ...parts.eyeDropTrigger.attrs,
321
+ onClick() {
322
+ send("EYEDROPPER.CLICK");
323
+ }
324
+ }),
325
+ getSwatchBackgroundProps(props) {
326
+ const { value } = props;
327
+ const alpha = normalizeColor(value).getChannelValue("alpha");
328
+ return normalize.element({
329
+ ...parts.swatchBg.attrs,
330
+ "data-alpha": alpha,
331
+ style: {
332
+ width: "100%",
333
+ height: "100%",
334
+ background: "#fff",
335
+ backgroundImage: [
336
+ "linear-gradient(-45deg,#0000 75.5%,#bcbcbc 75.5%)",
337
+ "linear-gradient(45deg,#0000 75.5%,#bcbcbc 75.5%)",
338
+ "linear-gradient(-45deg,#bcbcbc 25.5%,#0000 25.5%)",
339
+ "linear-gradient(45deg,#bcbcbc 25.5%,#0000 25.5%)"
340
+ ].join(","),
341
+ backgroundPosition: "-2px -2px,-2px 6px,6px -10px,-10px -2px",
342
+ backgroundSize: "16px 16px",
343
+ position: "absolute",
344
+ inset: "0px",
345
+ zIndex: -1
346
+ }
347
+ });
348
+ },
349
+ getSwatchProps(props) {
350
+ const { value, readOnly } = props;
351
+ const color = normalizeColor(value).toFormat(valueAsColor.getColorSpace());
352
+ return normalize.element({
353
+ ...parts.swatch.attrs,
354
+ onClick() {
355
+ if (readOnly)
356
+ return;
357
+ send({ type: "VALUE.SET", value: color });
358
+ },
359
+ style: {
360
+ position: "relative",
361
+ background: color.toString("css")
362
+ }
363
+ });
364
+ }
365
+ };
366
+ }
367
+
368
+ export { connect };
@@ -1,51 +1,46 @@
1
- import { ColorChannel } from '@zag-js/color-utils';
2
- import { Point } from '@zag-js/dom-event';
3
- import { MachineContext } from './color-picker.types.js';
4
- import '@zag-js/core';
5
- import '@zag-js/types';
6
-
7
- declare const dom: {
1
+ import { type ColorChannel } from "@zag-js/color-utils";
2
+ import { type Point } from "@zag-js/dom-event";
3
+ import type { MachineContext as Ctx } from "./color-picker.types";
4
+ export declare const dom: {
8
5
  getRootNode: (ctx: {
9
- getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
10
- }) => ShadowRoot | Document;
6
+ getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
7
+ }) => Document | ShadowRoot;
11
8
  getDoc: (ctx: {
12
- getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
9
+ getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
13
10
  }) => Document;
14
11
  getWin: (ctx: {
15
- getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
12
+ getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
16
13
  }) => Window & typeof globalThis;
17
14
  getActiveElement: (ctx: {
18
- getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
15
+ getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
19
16
  }) => HTMLElement | null;
20
17
  getById: <T extends HTMLElement = HTMLElement>(ctx: {
21
- getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
18
+ getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
22
19
  }, id: string) => T | null;
23
20
  queryById: <T_1 extends HTMLElement = HTMLElement>(ctx: {
24
- getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
21
+ getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
25
22
  }, id: string) => T_1;
26
23
  } & {
27
- getContentId: (ctx: MachineContext) => string;
28
- getAreaId: (ctx: MachineContext) => string;
29
- getAreaGradientId: (ctx: MachineContext) => string;
30
- getAreaThumbId: (ctx: MachineContext) => string;
31
- getChannelSliderTrackId: (ctx: MachineContext, channel: ColorChannel) => string;
32
- getChannelInputId: (ctx: MachineContext, channel: string) => string;
33
- getChannelSliderThumbId: (ctx: MachineContext, channel: ColorChannel) => string;
34
- getContentEl: (ctx: MachineContext) => HTMLElement;
35
- getAreaThumbEl: (ctx: MachineContext) => HTMLElement;
36
- getChannelSliderThumbEl: (ctx: MachineContext, channel: ColorChannel) => HTMLElement;
37
- getChannelInputEl: (ctx: MachineContext, channel: string) => HTMLInputElement;
38
- getAreaEl: (ctx: MachineContext) => HTMLElement;
39
- getAreaValueFromPoint(ctx: MachineContext, point: Point): {
24
+ getContentId: (ctx: Ctx) => string;
25
+ getAreaId: (ctx: Ctx) => string;
26
+ getAreaGradientId: (ctx: Ctx) => string;
27
+ getAreaThumbId: (ctx: Ctx) => string;
28
+ getChannelSliderTrackId: (ctx: Ctx, channel: ColorChannel) => string;
29
+ getChannelInputId: (ctx: Ctx, channel: string) => string;
30
+ getChannelSliderThumbId: (ctx: Ctx, channel: ColorChannel) => string;
31
+ getContentEl: (ctx: Ctx) => HTMLElement;
32
+ getAreaThumbEl: (ctx: Ctx) => HTMLElement;
33
+ getChannelSliderThumbEl: (ctx: Ctx, channel: ColorChannel) => HTMLElement;
34
+ getChannelInputEl: (ctx: Ctx, channel: string) => HTMLInputElement;
35
+ getAreaEl: (ctx: Ctx) => HTMLElement;
36
+ getAreaValueFromPoint(ctx: Ctx, point: Point): {
40
37
  x: number;
41
38
  y: number;
42
39
  };
43
- getChannelSliderTrackEl: (ctx: MachineContext, channel: ColorChannel) => HTMLElement;
44
- getChannelSliderValueFromPoint(ctx: MachineContext, point: Point, channel: ColorChannel): {
40
+ getChannelSliderTrackEl: (ctx: Ctx, channel: ColorChannel) => HTMLElement;
41
+ getChannelSliderValueFromPoint(ctx: Ctx, point: Point, channel: ColorChannel): {
45
42
  x: number;
46
43
  y: number;
47
44
  };
48
- getChannelInputEls: (ctx: MachineContext) => HTMLInputElement[];
45
+ getChannelInputEls: (ctx: Ctx) => HTMLInputElement[];
49
46
  };
50
-
51
- export { dom };
@@ -1,31 +1,11 @@
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);
1
+ 'use strict';
19
2
 
20
- // src/color-picker.dom.ts
21
- var color_picker_dom_exports = {};
22
- __export(color_picker_dom_exports, {
23
- dom: () => dom
24
- });
25
- module.exports = __toCommonJS(color_picker_dom_exports);
26
- var import_dom_event = require("@zag-js/dom-event");
27
- var import_dom_query = require("@zag-js/dom-query");
28
- var dom = (0, import_dom_query.createScope)({
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const domEvent = require('@zag-js/dom-event');
6
+ const domQuery = require('@zag-js/dom-query');
7
+
8
+ const dom = domQuery.createScope({
29
9
  getContentId: (ctx) => ctx.ids?.content ?? `color-picker:${ctx.id}:content`,
30
10
  getAreaId: (ctx) => ctx.ids?.area ?? `color-picker:${ctx.id}:area`,
31
11
  getAreaGradientId: (ctx) => ctx.ids?.areaGradient ?? `color-picker:${ctx.id}:area-gradient`,
@@ -39,21 +19,19 @@ var dom = (0, import_dom_query.createScope)({
39
19
  getChannelInputEl: (ctx, channel) => dom.queryById(ctx, dom.getChannelInputId(ctx, channel)),
40
20
  getAreaEl: (ctx) => dom.queryById(ctx, dom.getAreaId(ctx)),
41
21
  getAreaValueFromPoint(ctx, point) {
42
- const { percent } = (0, import_dom_event.getRelativePoint)(point, dom.getAreaEl(ctx));
22
+ const { percent } = domEvent.getRelativePoint(point, dom.getAreaEl(ctx));
43
23
  return percent;
44
24
  },
45
25
  getChannelSliderTrackEl: (ctx, channel) => {
46
26
  return dom.queryById(ctx, dom.getChannelSliderTrackId(ctx, channel));
47
27
  },
48
28
  getChannelSliderValueFromPoint(ctx, point, channel) {
49
- const { percent } = (0, import_dom_event.getRelativePoint)(point, dom.getChannelSliderTrackEl(ctx, channel));
29
+ const { percent } = domEvent.getRelativePoint(point, dom.getChannelSliderTrackEl(ctx, channel));
50
30
  return percent;
51
31
  },
52
32
  getChannelInputEls: (ctx) => {
53
- return (0, import_dom_query.queryAll)(dom.getContentEl(ctx), "input[data-channel]");
33
+ return domQuery.queryAll(dom.getContentEl(ctx), "input[data-channel]");
54
34
  }
55
35
  });
56
- // Annotate the CommonJS export names for ESM import in node:
57
- 0 && (module.exports = {
58
- dom
59
- });
36
+
37
+ exports.dom = dom;
@@ -1,6 +1,33 @@
1
- import {
2
- dom
3
- } from "./chunk-SPSDVZCT.mjs";
4
- export {
5
- dom
6
- };
1
+ import { getRelativePoint } from '@zag-js/dom-event';
2
+ import { createScope, queryAll } from '@zag-js/dom-query';
3
+
4
+ const dom = createScope({
5
+ getContentId: (ctx) => ctx.ids?.content ?? `color-picker:${ctx.id}:content`,
6
+ getAreaId: (ctx) => ctx.ids?.area ?? `color-picker:${ctx.id}:area`,
7
+ getAreaGradientId: (ctx) => ctx.ids?.areaGradient ?? `color-picker:${ctx.id}:area-gradient`,
8
+ getAreaThumbId: (ctx) => ctx.ids?.areaThumb ?? `color-picker:${ctx.id}:area-thumb`,
9
+ getChannelSliderTrackId: (ctx, channel) => ctx.ids?.channelSliderTrack?.(channel) ?? `color-picker:${ctx.id}:slider-track:${channel}`,
10
+ getChannelInputId: (ctx, channel) => ctx.ids?.channelInput?.(channel) ?? `color-picker:${ctx.id}:input:${channel}`,
11
+ getChannelSliderThumbId: (ctx, channel) => ctx.ids?.channelSliderThumb?.(channel) ?? `color-picker:${ctx.id}:slider-thumb:${channel}`,
12
+ getContentEl: (ctx) => dom.queryById(ctx, dom.getContentId(ctx)),
13
+ getAreaThumbEl: (ctx) => dom.queryById(ctx, dom.getAreaThumbId(ctx)),
14
+ getChannelSliderThumbEl: (ctx, channel) => dom.queryById(ctx, dom.getChannelSliderThumbId(ctx, channel)),
15
+ getChannelInputEl: (ctx, channel) => dom.queryById(ctx, dom.getChannelInputId(ctx, channel)),
16
+ getAreaEl: (ctx) => dom.queryById(ctx, dom.getAreaId(ctx)),
17
+ getAreaValueFromPoint(ctx, point) {
18
+ const { percent } = getRelativePoint(point, dom.getAreaEl(ctx));
19
+ return percent;
20
+ },
21
+ getChannelSliderTrackEl: (ctx, channel) => {
22
+ return dom.queryById(ctx, dom.getChannelSliderTrackId(ctx, channel));
23
+ },
24
+ getChannelSliderValueFromPoint(ctx, point, channel) {
25
+ const { percent } = getRelativePoint(point, dom.getChannelSliderTrackEl(ctx, channel));
26
+ return percent;
27
+ },
28
+ getChannelInputEls: (ctx) => {
29
+ return queryAll(dom.getContentEl(ctx), "input[data-channel]");
30
+ }
31
+ });
32
+
33
+ export { dom };
@@ -1,8 +1,3 @@
1
- import * as _zag_js_core from '@zag-js/core';
2
- import { UserDefinedContext, MachineContext, MachineState } from './color-picker.types.js';
3
- import '@zag-js/color-utils';
4
- import '@zag-js/types';
5
-
6
- declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
7
-
8
- export { machine };
1
+ import { Machine, StateMachine } from '@zag-js/core';
2
+ import { MachineContext, MachineState, UserDefinedContext } from "./color-picker.types";
3
+ export declare function machine(userContext: UserDefinedContext): Machine<MachineContext, MachineState, StateMachine.AnyEventObject>;