@zag-js/color-picker 0.6.0 → 0.7.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.
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-2ERX54SV.mjs";
4
4
  import {
5
5
  dom
6
- } from "./chunk-ACSV4TXB.mjs";
6
+ } from "./chunk-JOGAQ7RL.mjs";
7
7
  import {
8
8
  getChannelDetails
9
9
  } from "./chunk-KLLIOTK6.mjs";
@@ -16,7 +16,7 @@ import {
16
16
  } from "./chunk-2ERX54SV.mjs";
17
17
  import {
18
18
  dom
19
- } from "./chunk-ACSV4TXB.mjs";
19
+ } from "./chunk-JOGAQ7RL.mjs";
20
20
  import {
21
21
  getChannelDetails
22
22
  } from "./chunk-KLLIOTK6.mjs";
@@ -2,13 +2,13 @@
2
2
  import { getRelativePointPercent } from "@zag-js/dom-event";
3
3
  import { createScope, queryAll } from "@zag-js/dom-query";
4
4
  var dom = createScope({
5
- getAreaId: (ctx) => `color-picker:${ctx.id}:area`,
6
- getAreaGradientId: (ctx) => `color-picker:${ctx.id}:area-gradient`,
7
- getAreaThumbId: (ctx) => `color-picker:${ctx.id}:area-thumb`,
8
- getChannelSliderTrackId: (ctx, channel) => `color-picker:${ctx.id}:slider-track:${channel}`,
9
- getChannelInputId: (ctx, channel) => `color-picker:${ctx.id}:input:${channel}`,
10
- getContentId: (ctx) => `color-picker:${ctx.id}:content`,
11
- getChannelSliderThumbId: (ctx, channel) => `color-picker:${ctx.id}:thumb:${channel}`,
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
12
  getContentEl: (ctx) => dom.queryById(ctx, dom.getContentId(ctx)),
13
13
  getAreaThumbEl: (ctx) => dom.queryById(ctx, dom.getAreaThumbId(ctx)),
14
14
  getChannelSliderThumbEl: (ctx, channel) => dom.queryById(ctx, dom.getChannelSliderThumbId(ctx, channel)),
@@ -1,6 +1,6 @@
1
1
  import { Color, ColorChannel, ColorFormat } from '@zag-js/color-utils';
2
2
  import { PropTypes, NormalizeProps } from '@zag-js/types';
3
- import { State, Send, AreaProps, ChannelProps, ChannelInputProps, SwatchProps } from './color-picker.types.js';
3
+ import { State, Send, ColorAreaProps, ColorChannelProps, ColorChannelInputProps, ColorSwatchProps } from './color-picker.types.js';
4
4
  import '@zag-js/core';
5
5
 
6
6
  declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
@@ -33,16 +33,16 @@ declare function connect<T extends PropTypes>(state: State, send: Send, normaliz
33
33
  */
34
34
  setFormat(format: ColorFormat): void;
35
35
  contentProps: T["element"];
36
- getAreaProps(props: AreaProps): T["element"];
37
- getAreaGradientProps(props: AreaProps): T["element"];
38
- getAreaThumbProps(props: AreaProps): T["element"];
39
- getChannelSliderTrackProps(props: ChannelProps): T["element"];
40
- getChannelSliderBackgroundProps(props: ChannelProps): T["element"];
41
- getChannelSliderThumbProps(props: ChannelProps): T["element"];
42
- getChannelInputProps(props: ChannelInputProps): T["input"];
36
+ getAreaProps(props: ColorAreaProps): T["element"];
37
+ getAreaGradientProps(props: ColorAreaProps): T["element"];
38
+ getAreaThumbProps(props: ColorAreaProps): T["element"];
39
+ getChannelSliderTrackProps(props: ColorChannelProps): T["element"];
40
+ getChannelSliderBackgroundProps(props: ColorChannelProps): T["element"];
41
+ getChannelSliderThumbProps(props: ColorChannelProps): T["element"];
42
+ getChannelInputProps(props: ColorChannelInputProps): T["input"];
43
43
  eyeDropperTriggerProps: T["button"];
44
- getSwatchBackgroundProps(props: SwatchProps): T["element"];
45
- getSwatchProps(props: SwatchProps): T["element"];
44
+ getSwatchBackgroundProps(props: ColorSwatchProps): T["element"];
45
+ getSwatchProps(props: ColorSwatchProps): T["element"];
46
46
  };
47
47
 
48
48
  export { connect };
@@ -49,13 +49,13 @@ var parts = anatomy.build();
49
49
  var import_dom_event = require("@zag-js/dom-event");
50
50
  var import_dom_query = require("@zag-js/dom-query");
51
51
  var dom = (0, import_dom_query.createScope)({
52
- getAreaId: (ctx) => `color-picker:${ctx.id}:area`,
53
- getAreaGradientId: (ctx) => `color-picker:${ctx.id}:area-gradient`,
54
- getAreaThumbId: (ctx) => `color-picker:${ctx.id}:area-thumb`,
55
- getChannelSliderTrackId: (ctx, channel) => `color-picker:${ctx.id}:slider-track:${channel}`,
56
- getChannelInputId: (ctx, channel) => `color-picker:${ctx.id}:input:${channel}`,
57
- getContentId: (ctx) => `color-picker:${ctx.id}:content`,
58
- getChannelSliderThumbId: (ctx, channel) => `color-picker:${ctx.id}:thumb:${channel}`,
52
+ getContentId: (ctx) => ctx.ids?.content ?? `color-picker:${ctx.id}:content`,
53
+ getAreaId: (ctx) => ctx.ids?.area ?? `color-picker:${ctx.id}:area`,
54
+ getAreaGradientId: (ctx) => ctx.ids?.areaGradient ?? `color-picker:${ctx.id}:area-gradient`,
55
+ getAreaThumbId: (ctx) => ctx.ids?.areaThumb ?? `color-picker:${ctx.id}:area-thumb`,
56
+ getChannelSliderTrackId: (ctx, channel) => ctx.ids?.channelSliderTrack?.(channel) ?? `color-picker:${ctx.id}:slider-track:${channel}`,
57
+ getChannelInputId: (ctx, channel) => ctx.ids?.channelInput?.(channel) ?? `color-picker:${ctx.id}:input:${channel}`,
58
+ getChannelSliderThumbId: (ctx, channel) => ctx.ids?.channelSliderThumb?.(channel) ?? `color-picker:${ctx.id}:slider-thumb:${channel}`,
59
59
  getContentEl: (ctx) => dom.queryById(ctx, dom.getContentId(ctx)),
60
60
  getAreaThumbEl: (ctx) => dom.queryById(ctx, dom.getAreaThumbId(ctx)),
61
61
  getChannelSliderThumbEl: (ctx, channel) => dom.queryById(ctx, dom.getChannelSliderThumbId(ctx, channel)),
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  connect
3
- } from "./chunk-CD6CID4K.mjs";
3
+ } from "./chunk-HSUD4DN3.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-ACSV4TXB.mjs";
9
+ import "./chunk-JOGAQ7RL.mjs";
10
10
  import "./chunk-OY3B7NXA.mjs";
11
11
  import "./chunk-KLLIOTK6.mjs";
12
12
  export {
@@ -27,12 +27,12 @@ declare const dom: {
27
27
  getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
28
28
  }, id: string) => T_1;
29
29
  } & {
30
+ getContentId: (ctx: MachineContext) => string;
30
31
  getAreaId: (ctx: MachineContext) => string;
31
32
  getAreaGradientId: (ctx: MachineContext) => string;
32
33
  getAreaThumbId: (ctx: MachineContext) => string;
33
34
  getChannelSliderTrackId: (ctx: MachineContext, channel: ColorChannel) => string;
34
35
  getChannelInputId: (ctx: MachineContext, channel: string) => string;
35
- getContentId: (ctx: MachineContext) => string;
36
36
  getChannelSliderThumbId: (ctx: MachineContext, channel: ColorChannel) => string;
37
37
  getContentEl: (ctx: MachineContext) => HTMLElement;
38
38
  getAreaThumbEl: (ctx: MachineContext) => HTMLElement;
@@ -26,13 +26,13 @@ module.exports = __toCommonJS(color_picker_dom_exports);
26
26
  var import_dom_event = require("@zag-js/dom-event");
27
27
  var import_dom_query = require("@zag-js/dom-query");
28
28
  var dom = (0, import_dom_query.createScope)({
29
- getAreaId: (ctx) => `color-picker:${ctx.id}:area`,
30
- getAreaGradientId: (ctx) => `color-picker:${ctx.id}:area-gradient`,
31
- getAreaThumbId: (ctx) => `color-picker:${ctx.id}:area-thumb`,
32
- getChannelSliderTrackId: (ctx, channel) => `color-picker:${ctx.id}:slider-track:${channel}`,
33
- getChannelInputId: (ctx, channel) => `color-picker:${ctx.id}:input:${channel}`,
34
- getContentId: (ctx) => `color-picker:${ctx.id}:content`,
35
- getChannelSliderThumbId: (ctx, channel) => `color-picker:${ctx.id}:thumb:${channel}`,
29
+ getContentId: (ctx) => ctx.ids?.content ?? `color-picker:${ctx.id}:content`,
30
+ getAreaId: (ctx) => ctx.ids?.area ?? `color-picker:${ctx.id}:area`,
31
+ getAreaGradientId: (ctx) => ctx.ids?.areaGradient ?? `color-picker:${ctx.id}:area-gradient`,
32
+ getAreaThumbId: (ctx) => ctx.ids?.areaThumb ?? `color-picker:${ctx.id}:area-thumb`,
33
+ getChannelSliderTrackId: (ctx, channel) => ctx.ids?.channelSliderTrack?.(channel) ?? `color-picker:${ctx.id}:slider-track:${channel}`,
34
+ getChannelInputId: (ctx, channel) => ctx.ids?.channelInput?.(channel) ?? `color-picker:${ctx.id}:input:${channel}`,
35
+ getChannelSliderThumbId: (ctx, channel) => ctx.ids?.channelSliderThumb?.(channel) ?? `color-picker:${ctx.id}:slider-thumb:${channel}`,
36
36
  getContentEl: (ctx) => dom.queryById(ctx, dom.getContentId(ctx)),
37
37
  getAreaThumbEl: (ctx) => dom.queryById(ctx, dom.getAreaThumbId(ctx)),
38
38
  getChannelSliderThumbEl: (ctx, channel) => dom.queryById(ctx, dom.getChannelSliderThumbId(ctx, channel)),
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  dom
3
- } from "./chunk-ACSV4TXB.mjs";
3
+ } from "./chunk-JOGAQ7RL.mjs";
4
4
  export {
5
5
  dom
6
6
  };
@@ -35,13 +35,13 @@ var import_utils = require("@zag-js/utils");
35
35
  var import_dom_event = require("@zag-js/dom-event");
36
36
  var import_dom_query = require("@zag-js/dom-query");
37
37
  var dom = (0, import_dom_query.createScope)({
38
- getAreaId: (ctx) => `color-picker:${ctx.id}:area`,
39
- getAreaGradientId: (ctx) => `color-picker:${ctx.id}:area-gradient`,
40
- getAreaThumbId: (ctx) => `color-picker:${ctx.id}:area-thumb`,
41
- getChannelSliderTrackId: (ctx, channel) => `color-picker:${ctx.id}:slider-track:${channel}`,
42
- getChannelInputId: (ctx, channel) => `color-picker:${ctx.id}:input:${channel}`,
43
- getContentId: (ctx) => `color-picker:${ctx.id}:content`,
44
- getChannelSliderThumbId: (ctx, channel) => `color-picker:${ctx.id}:thumb:${channel}`,
38
+ getContentId: (ctx) => ctx.ids?.content ?? `color-picker:${ctx.id}:content`,
39
+ getAreaId: (ctx) => ctx.ids?.area ?? `color-picker:${ctx.id}:area`,
40
+ getAreaGradientId: (ctx) => ctx.ids?.areaGradient ?? `color-picker:${ctx.id}:area-gradient`,
41
+ getAreaThumbId: (ctx) => ctx.ids?.areaThumb ?? `color-picker:${ctx.id}:area-thumb`,
42
+ getChannelSliderTrackId: (ctx, channel) => ctx.ids?.channelSliderTrack?.(channel) ?? `color-picker:${ctx.id}:slider-track:${channel}`,
43
+ getChannelInputId: (ctx, channel) => ctx.ids?.channelInput?.(channel) ?? `color-picker:${ctx.id}:input:${channel}`,
44
+ getChannelSliderThumbId: (ctx, channel) => ctx.ids?.channelSliderThumb?.(channel) ?? `color-picker:${ctx.id}:slider-thumb:${channel}`,
45
45
  getContentEl: (ctx) => dom.queryById(ctx, dom.getContentId(ctx)),
46
46
  getAreaThumbEl: (ctx) => dom.queryById(ctx, dom.getAreaThumbId(ctx)),
47
47
  getChannelSliderThumbEl: (ctx, channel) => dom.queryById(ctx, dom.getChannelSliderThumbId(ctx, channel)),
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  machine
3
- } from "./chunk-ZBNUATFY.mjs";
3
+ } from "./chunk-EUTH4EDN.mjs";
4
4
  import "./chunk-2ERX54SV.mjs";
5
- import "./chunk-ACSV4TXB.mjs";
5
+ import "./chunk-JOGAQ7RL.mjs";
6
6
  import "./chunk-KLLIOTK6.mjs";
7
7
  export {
8
8
  machine
@@ -2,20 +2,20 @@ import { ColorChannel, Color, ColorAxes } from '@zag-js/color-utils';
2
2
  import { StateMachine } from '@zag-js/core';
3
3
  import { Orientation, RequiredBy, CommonProperties, Context } from '@zag-js/types';
4
4
 
5
- type ChannelProps = {
5
+ type ColorChannelProps = {
6
6
  channel: ColorChannel;
7
7
  orientation?: Orientation;
8
8
  };
9
9
  type ExtendedColorChannel = ColorChannel | "hex" | "css";
10
- type ChannelInputProps = {
10
+ type ColorChannelInputProps = {
11
11
  channel: ExtendedColorChannel;
12
12
  orientation?: Orientation;
13
13
  };
14
- type AreaProps = {
14
+ type ColorAreaProps = {
15
15
  xChannel: ColorChannel;
16
16
  yChannel: ColorChannel;
17
17
  };
18
- type SwatchProps = {
18
+ type ColorSwatchProps = {
19
19
  readOnly?: boolean;
20
20
  value: string | Color;
21
21
  };
@@ -23,7 +23,20 @@ type ChangeDetails = {
23
23
  value: string;
24
24
  valueAsColor: Color;
25
25
  };
26
+ type ElementIds = Partial<{
27
+ content: string;
28
+ area: string;
29
+ areaGradient: string;
30
+ areaThumb: string;
31
+ channelInput(id: string): string;
32
+ channelSliderTrack(id: ColorChannel): string;
33
+ channelSliderThumb(id: ColorChannel): string;
34
+ }>;
26
35
  type PublicContext = CommonProperties & {
36
+ /**
37
+ * The ids of the elements in the color picker. Useful for composition.
38
+ */
39
+ ids?: ElementIds;
27
40
  /**
28
41
  * The direction of the color picker
29
42
  */
@@ -85,4 +98,4 @@ type MachineState = {
85
98
  type State = StateMachine.State<MachineContext, MachineState>;
86
99
  type Send = StateMachine.Send<StateMachine.AnyEventObject>;
87
100
 
88
- export { AreaProps, ChannelInputProps, ChannelProps, ExtendedColorChannel, MachineContext, MachineState, Send, State, SwatchProps, UserDefinedContext };
101
+ export { ColorAreaProps, ColorChannelInputProps, ColorChannelProps, ColorSwatchProps, ExtendedColorChannel, MachineContext, MachineState, Send, State, UserDefinedContext };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
+ export { anatomy } from './color-picker.anatomy.js';
1
2
  export { connect } from './color-picker.connect.js';
2
3
  export { machine } from './color-picker.machine.js';
3
- export { UserDefinedContext as Context } from './color-picker.types.js';
4
+ export { ColorAreaProps, ColorChannelProps, ColorSwatchProps, UserDefinedContext as Context } from './color-picker.types.js';
5
+ import '@zag-js/anatomy';
4
6
  import '@zag-js/color-utils';
5
7
  import '@zag-js/types';
6
8
  import '@zag-js/core';
package/dist/index.js CHANGED
@@ -20,16 +20,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
+ anatomy: () => anatomy,
23
24
  connect: () => connect,
24
25
  machine: () => machine
25
26
  });
26
27
  module.exports = __toCommonJS(src_exports);
27
28
 
28
- // src/color-picker.connect.ts
29
- var import_color_utils2 = require("@zag-js/color-utils");
30
- var import_dom_event2 = require("@zag-js/dom-event");
31
- var import_dom_query2 = require("@zag-js/dom-query");
32
-
33
29
  // src/color-picker.anatomy.ts
34
30
  var import_anatomy = require("@zag-js/anatomy");
35
31
  var anatomy = (0, import_anatomy.createAnatomy)("color-picker", [
@@ -48,17 +44,22 @@ var anatomy = (0, import_anatomy.createAnatomy)("color-picker", [
48
44
  ]);
49
45
  var parts = anatomy.build();
50
46
 
47
+ // src/color-picker.connect.ts
48
+ var import_color_utils2 = require("@zag-js/color-utils");
49
+ var import_dom_event2 = require("@zag-js/dom-event");
50
+ var import_dom_query2 = require("@zag-js/dom-query");
51
+
51
52
  // src/color-picker.dom.ts
52
53
  var import_dom_event = require("@zag-js/dom-event");
53
54
  var import_dom_query = require("@zag-js/dom-query");
54
55
  var dom = (0, import_dom_query.createScope)({
55
- getAreaId: (ctx) => `color-picker:${ctx.id}:area`,
56
- getAreaGradientId: (ctx) => `color-picker:${ctx.id}:area-gradient`,
57
- getAreaThumbId: (ctx) => `color-picker:${ctx.id}:area-thumb`,
58
- getChannelSliderTrackId: (ctx, channel) => `color-picker:${ctx.id}:slider-track:${channel}`,
59
- getChannelInputId: (ctx, channel) => `color-picker:${ctx.id}:input:${channel}`,
60
- getContentId: (ctx) => `color-picker:${ctx.id}:content`,
61
- getChannelSliderThumbId: (ctx, channel) => `color-picker:${ctx.id}:thumb:${channel}`,
56
+ getContentId: (ctx) => ctx.ids?.content ?? `color-picker:${ctx.id}:content`,
57
+ getAreaId: (ctx) => ctx.ids?.area ?? `color-picker:${ctx.id}:area`,
58
+ getAreaGradientId: (ctx) => ctx.ids?.areaGradient ?? `color-picker:${ctx.id}:area-gradient`,
59
+ getAreaThumbId: (ctx) => ctx.ids?.areaThumb ?? `color-picker:${ctx.id}:area-thumb`,
60
+ getChannelSliderTrackId: (ctx, channel) => ctx.ids?.channelSliderTrack?.(channel) ?? `color-picker:${ctx.id}:slider-track:${channel}`,
61
+ getChannelInputId: (ctx, channel) => ctx.ids?.channelInput?.(channel) ?? `color-picker:${ctx.id}:input:${channel}`,
62
+ getChannelSliderThumbId: (ctx, channel) => ctx.ids?.channelSliderThumb?.(channel) ?? `color-picker:${ctx.id}:slider-thumb:${channel}`,
62
63
  getContentEl: (ctx) => dom.queryById(ctx, dom.getContentId(ctx)),
63
64
  getAreaThumbEl: (ctx) => dom.queryById(ctx, dom.getAreaThumbId(ctx)),
64
65
  getChannelSliderThumbEl: (ctx, channel) => dom.queryById(ctx, dom.getChannelSliderThumbId(ctx, channel)),
@@ -1082,6 +1083,7 @@ var setColor = (ctx, color) => {
1082
1083
  };
1083
1084
  // Annotate the CommonJS export names for ESM import in node:
1084
1085
  0 && (module.exports = {
1086
+ anatomy,
1085
1087
  connect,
1086
1088
  machine
1087
1089
  });
package/dist/index.mjs CHANGED
@@ -1,18 +1,21 @@
1
1
  import {
2
2
  connect
3
- } from "./chunk-CD6CID4K.mjs";
3
+ } from "./chunk-HSUD4DN3.mjs";
4
4
  import "./chunk-JNBNPPMF.mjs";
5
5
  import "./chunk-KO4TBUXB.mjs";
6
6
  import "./chunk-3XH465XT.mjs";
7
- import "./chunk-75JXJMB5.mjs";
7
+ import {
8
+ anatomy
9
+ } from "./chunk-75JXJMB5.mjs";
8
10
  import {
9
11
  machine
10
- } from "./chunk-ZBNUATFY.mjs";
12
+ } from "./chunk-EUTH4EDN.mjs";
11
13
  import "./chunk-2ERX54SV.mjs";
12
- import "./chunk-ACSV4TXB.mjs";
14
+ import "./chunk-JOGAQ7RL.mjs";
13
15
  import "./chunk-OY3B7NXA.mjs";
14
16
  import "./chunk-KLLIOTK6.mjs";
15
17
  export {
18
+ anatomy,
16
19
  connect,
17
20
  machine
18
21
  };
@@ -1,8 +1,8 @@
1
- import { MachineContext, ChannelProps } from '../color-picker.types.js';
1
+ import { MachineContext, ColorChannelProps } from '../color-picker.types.js';
2
2
  import '@zag-js/color-utils';
3
3
  import '@zag-js/core';
4
4
  import '@zag-js/types';
5
5
 
6
- declare const getSliderBgImage: (ctx: MachineContext, props: Required<ChannelProps>) => string;
6
+ declare const getSliderBgImage: (ctx: MachineContext, props: Required<ColorChannelProps>) => string;
7
7
 
8
8
  export { getSliderBgImage };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/color-picker",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Core logic for the color-picker widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -27,7 +27,7 @@
27
27
  "url": "https://github.com/chakra-ui/zag/issues"
28
28
  },
29
29
  "dependencies": {
30
- "@zag-js/core": "0.5.0",
30
+ "@zag-js/core": "0.7.0",
31
31
  "@zag-js/anatomy": "0.1.4",
32
32
  "@zag-js/dom-query": "0.1.4",
33
33
  "@zag-js/dom-event": "0.6.0",