@proyecto-viviana/solid-stately 0.0.5 → 0.1.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.
Files changed (208) hide show
  1. package/README.md +312 -0
  2. package/dist/index.d.ts +3363 -6
  3. package/dist/index.js +6194 -19
  4. package/dist/index.js.map +1 -1
  5. package/package.json +52 -48
  6. package/src/autocomplete/createAutocompleteState.d.ts +46 -0
  7. package/src/autocomplete/createAutocompleteState.d.ts.map +1 -0
  8. package/src/autocomplete/createAutocompleteState.ts +90 -0
  9. package/src/autocomplete/index.d.ts +2 -0
  10. package/src/autocomplete/index.d.ts.map +1 -0
  11. package/src/autocomplete/index.ts +5 -0
  12. package/src/calendar/createCalendarState.d.ts +130 -0
  13. package/src/calendar/createCalendarState.d.ts.map +1 -0
  14. package/src/calendar/createCalendarState.ts +461 -0
  15. package/src/calendar/createDateFieldState.d.ts +110 -0
  16. package/src/calendar/createDateFieldState.d.ts.map +1 -0
  17. package/src/calendar/createDateFieldState.ts +562 -0
  18. package/src/calendar/createRangeCalendarState.d.ts +146 -0
  19. package/src/calendar/createRangeCalendarState.d.ts.map +1 -0
  20. package/src/calendar/createRangeCalendarState.ts +535 -0
  21. package/src/calendar/createTimeFieldState.d.ts +95 -0
  22. package/src/calendar/createTimeFieldState.d.ts.map +1 -0
  23. package/src/calendar/createTimeFieldState.ts +483 -0
  24. package/src/calendar/index.d.ts +7 -0
  25. package/src/calendar/index.d.ts.map +1 -0
  26. package/src/calendar/index.ts +81 -0
  27. package/{dist → src}/checkbox/createCheckboxGroupState.d.ts +1 -0
  28. package/src/checkbox/createCheckboxGroupState.d.ts.map +1 -0
  29. package/{dist → src}/checkbox/index.d.ts +1 -0
  30. package/src/checkbox/index.d.ts.map +1 -0
  31. package/src/collections/ListCollection.d.ts +37 -0
  32. package/src/collections/ListCollection.d.ts.map +1 -0
  33. package/src/collections/ListCollection.ts +146 -0
  34. package/src/collections/createListState.d.ts +79 -0
  35. package/src/collections/createListState.d.ts.map +1 -0
  36. package/src/collections/createListState.ts +264 -0
  37. package/src/collections/createMenuState.d.ts +50 -0
  38. package/src/collections/createMenuState.d.ts.map +1 -0
  39. package/src/collections/createMenuState.ts +106 -0
  40. package/src/collections/createSelectionState.d.ts +76 -0
  41. package/src/collections/createSelectionState.d.ts.map +1 -0
  42. package/src/collections/createSelectionState.ts +336 -0
  43. package/src/collections/index.d.ts +6 -0
  44. package/src/collections/index.d.ts.map +1 -0
  45. package/src/collections/index.ts +46 -0
  46. package/src/collections/types.d.ts +147 -0
  47. package/src/collections/types.d.ts.map +1 -0
  48. package/src/collections/types.ts +169 -0
  49. package/src/color/Color.d.ts +28 -0
  50. package/src/color/Color.d.ts.map +1 -0
  51. package/src/color/Color.ts +951 -0
  52. package/src/color/createColorAreaState.d.ts +76 -0
  53. package/src/color/createColorAreaState.d.ts.map +1 -0
  54. package/src/color/createColorAreaState.ts +293 -0
  55. package/src/color/createColorFieldState.d.ts +55 -0
  56. package/src/color/createColorFieldState.d.ts.map +1 -0
  57. package/src/color/createColorFieldState.ts +292 -0
  58. package/src/color/createColorSliderState.d.ts +67 -0
  59. package/src/color/createColorSliderState.d.ts.map +1 -0
  60. package/src/color/createColorSliderState.ts +241 -0
  61. package/src/color/createColorWheelState.d.ts +51 -0
  62. package/src/color/createColorWheelState.d.ts.map +1 -0
  63. package/src/color/createColorWheelState.ts +211 -0
  64. package/src/color/index.d.ts +10 -0
  65. package/src/color/index.d.ts.map +1 -0
  66. package/src/color/index.ts +47 -0
  67. package/src/color/types.d.ts +106 -0
  68. package/src/color/types.d.ts.map +1 -0
  69. package/src/color/types.ts +127 -0
  70. package/src/combobox/createComboBoxState.d.ts +125 -0
  71. package/src/combobox/createComboBoxState.d.ts.map +1 -0
  72. package/src/combobox/createComboBoxState.ts +703 -0
  73. package/src/combobox/index.d.ts +5 -0
  74. package/src/combobox/index.d.ts.map +1 -0
  75. package/src/combobox/index.ts +13 -0
  76. package/src/disclosure/createDisclosureState.d.ts +64 -0
  77. package/src/disclosure/createDisclosureState.d.ts.map +1 -0
  78. package/src/disclosure/createDisclosureState.ts +193 -0
  79. package/src/disclosure/index.d.ts +2 -0
  80. package/src/disclosure/index.d.ts.map +1 -0
  81. package/src/disclosure/index.ts +9 -0
  82. package/src/dnd/createDragState.d.ts +59 -0
  83. package/src/dnd/createDragState.d.ts.map +1 -0
  84. package/src/dnd/createDragState.ts +153 -0
  85. package/src/dnd/createDraggableCollectionState.d.ts +57 -0
  86. package/src/dnd/createDraggableCollectionState.d.ts.map +1 -0
  87. package/src/dnd/createDraggableCollectionState.ts +165 -0
  88. package/src/dnd/createDropState.d.ts +61 -0
  89. package/src/dnd/createDropState.d.ts.map +1 -0
  90. package/src/dnd/createDropState.ts +212 -0
  91. package/src/dnd/createDroppableCollectionState.d.ts +78 -0
  92. package/src/dnd/createDroppableCollectionState.d.ts.map +1 -0
  93. package/src/dnd/createDroppableCollectionState.ts +357 -0
  94. package/src/dnd/index.d.ts +11 -0
  95. package/src/dnd/index.d.ts.map +1 -0
  96. package/src/dnd/index.ts +76 -0
  97. package/src/dnd/types.d.ts +264 -0
  98. package/src/dnd/types.d.ts.map +1 -0
  99. package/src/dnd/types.ts +317 -0
  100. package/src/form/createFormValidationState.d.ts +100 -0
  101. package/src/form/createFormValidationState.d.ts.map +1 -0
  102. package/src/form/createFormValidationState.ts +389 -0
  103. package/src/form/index.d.ts +2 -0
  104. package/src/form/index.d.ts.map +1 -0
  105. package/src/form/index.ts +15 -0
  106. package/src/grid/createGridState.d.ts +12 -0
  107. package/src/grid/createGridState.d.ts.map +1 -0
  108. package/src/grid/createGridState.ts +327 -0
  109. package/src/grid/index.d.ts +7 -0
  110. package/src/grid/index.d.ts.map +1 -0
  111. package/src/grid/index.ts +13 -0
  112. package/src/grid/types.d.ts +156 -0
  113. package/src/grid/types.d.ts.map +1 -0
  114. package/src/grid/types.ts +179 -0
  115. package/src/index.d.ts +26 -0
  116. package/src/index.d.ts.map +1 -0
  117. package/src/index.ts +350 -1
  118. package/src/numberfield/createNumberFieldState.d.ts +65 -0
  119. package/src/numberfield/createNumberFieldState.d.ts.map +1 -0
  120. package/src/numberfield/createNumberFieldState.ts +383 -0
  121. package/src/numberfield/index.d.ts +2 -0
  122. package/src/numberfield/index.d.ts.map +1 -0
  123. package/src/numberfield/index.ts +5 -0
  124. package/src/overlays/createOverlayTriggerState.d.ts +32 -0
  125. package/src/overlays/createOverlayTriggerState.d.ts.map +1 -0
  126. package/src/overlays/createOverlayTriggerState.ts +67 -0
  127. package/src/overlays/index.d.ts +2 -0
  128. package/src/overlays/index.d.ts.map +1 -0
  129. package/src/overlays/index.ts +5 -0
  130. package/{dist → src}/radio/createRadioGroupState.d.ts +1 -0
  131. package/src/radio/createRadioGroupState.d.ts.map +1 -0
  132. package/{dist → src}/radio/index.d.ts +1 -0
  133. package/src/radio/index.d.ts.map +1 -0
  134. package/src/searchfield/createSearchFieldState.d.ts +25 -0
  135. package/src/searchfield/createSearchFieldState.d.ts.map +1 -0
  136. package/src/searchfield/createSearchFieldState.ts +62 -0
  137. package/src/searchfield/index.d.ts +3 -0
  138. package/src/searchfield/index.d.ts.map +1 -0
  139. package/src/searchfield/index.ts +5 -0
  140. package/src/select/createSelectState.d.ts +73 -0
  141. package/src/select/createSelectState.d.ts.map +1 -0
  142. package/src/select/createSelectState.ts +181 -0
  143. package/src/select/index.d.ts +2 -0
  144. package/src/select/index.d.ts.map +1 -0
  145. package/src/select/index.ts +5 -0
  146. package/src/slider/createSliderState.d.ts +72 -0
  147. package/src/slider/createSliderState.d.ts.map +1 -0
  148. package/src/slider/createSliderState.ts +211 -0
  149. package/src/slider/index.d.ts +3 -0
  150. package/src/slider/index.d.ts.map +1 -0
  151. package/src/slider/index.ts +6 -0
  152. package/{dist → src}/ssr/index.d.ts +5 -0
  153. package/src/ssr/index.d.ts.map +1 -0
  154. package/src/ssr/index.ts +6 -1
  155. package/src/table/TableCollection.d.ts +52 -0
  156. package/src/table/TableCollection.d.ts.map +1 -0
  157. package/src/table/TableCollection.ts +388 -0
  158. package/src/table/createTableState.d.ts +12 -0
  159. package/src/table/createTableState.d.ts.map +1 -0
  160. package/src/table/createTableState.ts +127 -0
  161. package/src/table/index.d.ts +8 -0
  162. package/src/table/index.d.ts.map +1 -0
  163. package/src/table/index.ts +18 -0
  164. package/src/table/types.d.ts +139 -0
  165. package/src/table/types.d.ts.map +1 -0
  166. package/src/table/types.ts +150 -0
  167. package/src/tabs/createTabListState.d.ts +68 -0
  168. package/src/tabs/createTabListState.d.ts.map +1 -0
  169. package/src/tabs/createTabListState.ts +240 -0
  170. package/src/tabs/index.d.ts +2 -0
  171. package/src/tabs/index.d.ts.map +1 -0
  172. package/src/tabs/index.ts +7 -0
  173. package/{dist → src}/textfield/createTextFieldState.d.ts +1 -0
  174. package/src/textfield/createTextFieldState.d.ts.map +1 -0
  175. package/{dist → src}/textfield/index.d.ts +1 -0
  176. package/src/textfield/index.d.ts.map +1 -0
  177. package/src/toast/createToastState.d.ts +118 -0
  178. package/src/toast/createToastState.d.ts.map +1 -0
  179. package/src/toast/createToastState.ts +316 -0
  180. package/src/toast/index.d.ts +2 -0
  181. package/src/toast/index.d.ts.map +1 -0
  182. package/src/toast/index.ts +11 -0
  183. package/{dist → src}/toggle/createToggleState.d.ts +1 -0
  184. package/src/toggle/createToggleState.d.ts.map +1 -0
  185. package/{dist → src}/toggle/index.d.ts +1 -0
  186. package/src/toggle/index.d.ts.map +1 -0
  187. package/src/tooltip/createTooltipTriggerState.d.ts +39 -0
  188. package/src/tooltip/createTooltipTriggerState.d.ts.map +1 -0
  189. package/src/tooltip/createTooltipTriggerState.ts +183 -0
  190. package/src/tooltip/index.d.ts +2 -0
  191. package/src/tooltip/index.d.ts.map +1 -0
  192. package/src/tooltip/index.ts +6 -0
  193. package/src/tree/TreeCollection.d.ts +40 -0
  194. package/src/tree/TreeCollection.d.ts.map +1 -0
  195. package/src/tree/TreeCollection.ts +175 -0
  196. package/src/tree/createTreeState.d.ts +14 -0
  197. package/src/tree/createTreeState.d.ts.map +1 -0
  198. package/src/tree/createTreeState.ts +392 -0
  199. package/src/tree/index.d.ts +7 -0
  200. package/src/tree/index.d.ts.map +1 -0
  201. package/src/tree/index.ts +13 -0
  202. package/src/tree/types.d.ts +157 -0
  203. package/src/tree/types.d.ts.map +1 -0
  204. package/src/tree/types.ts +174 -0
  205. package/{dist → src}/utils/index.d.ts +1 -0
  206. package/src/utils/index.d.ts.map +1 -0
  207. package/{dist → src}/utils/reactivity.d.ts +1 -0
  208. package/src/utils/reactivity.d.ts.map +1 -0
@@ -0,0 +1,76 @@
1
+ /**
2
+ * ColorArea state management.
3
+ * Based on @react-stately/color useColorAreaState.
4
+ */
5
+ import { type Accessor } from 'solid-js';
6
+ import type { Color, ColorChannel } from './types';
7
+ export interface ColorAreaStateOptions {
8
+ /** The current color value (controlled). */
9
+ value?: Color | string;
10
+ /** The default color value (uncontrolled). */
11
+ defaultValue?: Color | string;
12
+ /** Handler called when the color changes. */
13
+ onChange?: (color: Color) => void;
14
+ /** Handler called when dragging ends. */
15
+ onChangeEnd?: (color: Color) => void;
16
+ /** The color channel for the X axis. */
17
+ xChannel?: ColorChannel;
18
+ /** The color channel for the Y axis. */
19
+ yChannel?: ColorChannel;
20
+ /** Whether the area is disabled. */
21
+ isDisabled?: boolean;
22
+ }
23
+ export interface ColorAreaState {
24
+ /** The current color value. */
25
+ readonly value: Color;
26
+ /** The X axis channel. */
27
+ readonly xChannel: ColorChannel;
28
+ /** The Y axis channel. */
29
+ readonly yChannel: ColorChannel;
30
+ /** The Z axis channel (the third channel). */
31
+ readonly zChannel: ColorChannel;
32
+ /** Whether the area is being dragged. */
33
+ readonly isDragging: boolean;
34
+ /** Whether the area is disabled. */
35
+ readonly isDisabled: boolean;
36
+ /** Step for X channel. */
37
+ readonly xChannelStep: number;
38
+ /** Step for Y channel. */
39
+ readonly yChannelStep: number;
40
+ /** Page step for X channel. */
41
+ readonly xChannelPageStep: number;
42
+ /** Page step for Y channel. */
43
+ readonly yChannelPageStep: number;
44
+ /** Get the X channel value. */
45
+ getXValue(): number;
46
+ /** Get the Y channel value. */
47
+ getYValue(): number;
48
+ /** Set the X channel value. */
49
+ setXValue(value: number): void;
50
+ /** Set the Y channel value. */
51
+ setYValue(value: number): void;
52
+ /** Set color from a point (0-1, 0-1). */
53
+ setColorFromPoint(x: number, y: number): void;
54
+ /** Get the thumb position as percentages. */
55
+ getThumbPosition(): {
56
+ x: number;
57
+ y: number;
58
+ };
59
+ /** Increment X value. */
60
+ incrementX(stepSize?: number): void;
61
+ /** Decrement X value. */
62
+ decrementX(stepSize?: number): void;
63
+ /** Increment Y value. */
64
+ incrementY(stepSize?: number): void;
65
+ /** Decrement Y value. */
66
+ decrementY(stepSize?: number): void;
67
+ /** Set the dragging state. */
68
+ setDragging(isDragging: boolean): void;
69
+ /** Get the display color (with alpha = 1). */
70
+ getDisplayColor(): Color;
71
+ }
72
+ /**
73
+ * Creates state for a color area (2D color picker).
74
+ */
75
+ export declare function createColorAreaState(options: Accessor<ColorAreaStateOptions>): ColorAreaState;
76
+ //# sourceMappingURL=createColorAreaState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createColorAreaState.d.ts","sourceRoot":"","sources":["createColorAreaState.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAA4B,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AACnE,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAa,MAAM,SAAS,CAAC;AAG9D,MAAM,WAAW,qBAAqB;IACpC,4CAA4C;IAC5C,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IACvB,8CAA8C;IAC9C,YAAY,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IAC9B,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAClC,yCAAyC;IACzC,WAAW,CAAC,EAAE,CAAC,KAAK,EAA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AAA;KAAE,CAAC;IAC7C,yBAAyB;IACzB,UAAU,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,yBAAyB;IACzB,UAAU,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,yBAAyB;IACzB,UAAU,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,yBAAyB;IACzB,UAAU,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,8BAA8B;IAC9B,WAAW,CAAC,UAAU,EAAE,OAAO,GAAG,IAAI,CAAC;IACvC,8CAA8C;IAC9C,eAAe,IAAI,KAAK,CAAC;CAC1B;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,QAAQ,CAAC,qBAAqB,CAAC,GACvC,cAAc,CAqNhB"}
@@ -0,0 +1,293 @@
1
+ /**
2
+ * ColorArea state management.
3
+ * Based on @react-stately/color useColorAreaState.
4
+ */
5
+
6
+ import { createSignal, createMemo, type Accessor } from 'solid-js';
7
+ import type { Color, ColorChannel, ColorAxes } from './types';
8
+ import { normalizeColor } from './Color';
9
+
10
+ export interface ColorAreaStateOptions {
11
+ /** The current color value (controlled). */
12
+ value?: Color | string;
13
+ /** The default color value (uncontrolled). */
14
+ defaultValue?: Color | string;
15
+ /** Handler called when the color changes. */
16
+ onChange?: (color: Color) => void;
17
+ /** Handler called when dragging ends. */
18
+ onChangeEnd?: (color: Color) => void;
19
+ /** The color channel for the X axis. */
20
+ xChannel?: ColorChannel;
21
+ /** The color channel for the Y axis. */
22
+ yChannel?: ColorChannel;
23
+ /** Whether the area is disabled. */
24
+ isDisabled?: boolean;
25
+ }
26
+
27
+ export interface ColorAreaState {
28
+ /** The current color value. */
29
+ readonly value: Color;
30
+ /** The X axis channel. */
31
+ readonly xChannel: ColorChannel;
32
+ /** The Y axis channel. */
33
+ readonly yChannel: ColorChannel;
34
+ /** The Z axis channel (the third channel). */
35
+ readonly zChannel: ColorChannel;
36
+ /** Whether the area is being dragged. */
37
+ readonly isDragging: boolean;
38
+ /** Whether the area is disabled. */
39
+ readonly isDisabled: boolean;
40
+ /** Step for X channel. */
41
+ readonly xChannelStep: number;
42
+ /** Step for Y channel. */
43
+ readonly yChannelStep: number;
44
+ /** Page step for X channel. */
45
+ readonly xChannelPageStep: number;
46
+ /** Page step for Y channel. */
47
+ readonly yChannelPageStep: number;
48
+
49
+ /** Get the X channel value. */
50
+ getXValue(): number;
51
+ /** Get the Y channel value. */
52
+ getYValue(): number;
53
+ /** Set the X channel value. */
54
+ setXValue(value: number): void;
55
+ /** Set the Y channel value. */
56
+ setYValue(value: number): void;
57
+ /** Set color from a point (0-1, 0-1). */
58
+ setColorFromPoint(x: number, y: number): void;
59
+ /** Get the thumb position as percentages. */
60
+ getThumbPosition(): { x: number; y: number };
61
+ /** Increment X value. */
62
+ incrementX(stepSize?: number): void;
63
+ /** Decrement X value. */
64
+ decrementX(stepSize?: number): void;
65
+ /** Increment Y value. */
66
+ incrementY(stepSize?: number): void;
67
+ /** Decrement Y value. */
68
+ decrementY(stepSize?: number): void;
69
+ /** Set the dragging state. */
70
+ setDragging(isDragging: boolean): void;
71
+ /** Get the display color (with alpha = 1). */
72
+ getDisplayColor(): Color;
73
+ }
74
+
75
+ /**
76
+ * Creates state for a color area (2D color picker).
77
+ */
78
+ export function createColorAreaState(
79
+ options: Accessor<ColorAreaStateOptions>
80
+ ): ColorAreaState {
81
+ const getOptions = () => options();
82
+
83
+ // Internal value state
84
+ const [internalValue, setInternalValue] = createSignal<Color | null>(null);
85
+ const [isDragging, setIsDragging] = createSignal(false);
86
+
87
+ // Initialize internal value
88
+ const initValue = () => {
89
+ const opts = getOptions();
90
+ if (opts.defaultValue) {
91
+ return normalizeColor(opts.defaultValue);
92
+ }
93
+ return null;
94
+ };
95
+
96
+ // Set initial value
97
+ if (internalValue() === null) {
98
+ const init = initValue();
99
+ if (init) {
100
+ setInternalValue(init);
101
+ }
102
+ }
103
+
104
+ // Controlled vs uncontrolled value
105
+ const value = createMemo(() => {
106
+ const opts = getOptions();
107
+ if (opts.value !== undefined) {
108
+ return normalizeColor(opts.value);
109
+ }
110
+ return internalValue() ?? normalizeColor('#ff0000');
111
+ });
112
+
113
+ const isDisabled = createMemo(() => getOptions().isDisabled ?? false);
114
+
115
+ // Get color axes
116
+ const axes = createMemo<ColorAxes>(() => {
117
+ const opts = getOptions();
118
+ return value().getColorSpaceAxes({
119
+ xChannel: opts.xChannel,
120
+ yChannel: opts.yChannel,
121
+ });
122
+ });
123
+
124
+ const xChannel = createMemo(() => axes().xChannel);
125
+ const yChannel = createMemo(() => axes().yChannel);
126
+ const zChannel = createMemo(() => axes().zChannel);
127
+
128
+ // Get channel ranges
129
+ const xRange = createMemo(() => value().getChannelRange(xChannel()));
130
+ const yRange = createMemo(() => value().getChannelRange(yChannel()));
131
+
132
+ const xChannelStep = createMemo(() => xRange().step);
133
+ const yChannelStep = createMemo(() => yRange().step);
134
+ const xChannelPageStep = createMemo(() => xRange().pageSize);
135
+ const yChannelPageStep = createMemo(() => yRange().pageSize);
136
+
137
+ // Update value
138
+ const updateValue = (newColor: Color) => {
139
+ const opts = getOptions();
140
+
141
+ // Controlled mode
142
+ if (opts.value !== undefined) {
143
+ opts.onChange?.(newColor);
144
+ return;
145
+ }
146
+
147
+ // Uncontrolled mode
148
+ setInternalValue(newColor);
149
+ opts.onChange?.(newColor);
150
+ };
151
+
152
+ // Get X value
153
+ const getXValue = () => value().getChannelValue(xChannel());
154
+
155
+ // Get Y value
156
+ const getYValue = () => value().getChannelValue(yChannel());
157
+
158
+ // Set X value
159
+ const setXValue = (newValue: number) => {
160
+ const range = xRange();
161
+ const clamped = Math.max(range.minValue, Math.min(range.maxValue, newValue));
162
+ const rounded = Math.round(clamped / range.step) * range.step;
163
+ const newColor = value().withChannelValue(xChannel(), rounded);
164
+ updateValue(newColor);
165
+ };
166
+
167
+ // Set Y value
168
+ const setYValue = (newValue: number) => {
169
+ const range = yRange();
170
+ const clamped = Math.max(range.minValue, Math.min(range.maxValue, newValue));
171
+ const rounded = Math.round(clamped / range.step) * range.step;
172
+ const newColor = value().withChannelValue(yChannel(), rounded);
173
+ updateValue(newColor);
174
+ };
175
+
176
+ // Set color from point (x: 0-1, y: 0-1)
177
+ const setColorFromPoint = (x: number, y: number) => {
178
+ const xR = xRange();
179
+ const yR = yRange();
180
+
181
+ const xVal = xR.minValue + (xR.maxValue - xR.minValue) * x;
182
+ const yVal = yR.minValue + (yR.maxValue - yR.minValue) * (1 - y); // Y is inverted
183
+
184
+ const xClamped = Math.max(xR.minValue, Math.min(xR.maxValue, xVal));
185
+ const yClamped = Math.max(yR.minValue, Math.min(yR.maxValue, yVal));
186
+
187
+ const xRounded = Math.round(xClamped / xR.step) * xR.step;
188
+ const yRounded = Math.round(yClamped / yR.step) * yR.step;
189
+
190
+ const newColor = value()
191
+ .withChannelValue(xChannel(), xRounded)
192
+ .withChannelValue(yChannel(), yRounded);
193
+ updateValue(newColor);
194
+ };
195
+
196
+ // Get thumb position as percentages
197
+ const getThumbPosition = () => {
198
+ const xR = xRange();
199
+ const yR = yRange();
200
+ const xVal = getXValue();
201
+ const yVal = getYValue();
202
+
203
+ return {
204
+ x: (xVal - xR.minValue) / (xR.maxValue - xR.minValue),
205
+ y: 1 - (yVal - yR.minValue) / (yR.maxValue - yR.minValue), // Y is inverted
206
+ };
207
+ };
208
+
209
+ // Increment X
210
+ const incrementX = (stepSize?: number) => {
211
+ const s = stepSize ?? xChannelStep();
212
+ setXValue(getXValue() + s);
213
+ };
214
+
215
+ // Decrement X
216
+ const decrementX = (stepSize?: number) => {
217
+ const s = stepSize ?? xChannelStep();
218
+ setXValue(getXValue() - s);
219
+ };
220
+
221
+ // Increment Y
222
+ const incrementY = (stepSize?: number) => {
223
+ const s = stepSize ?? yChannelStep();
224
+ setYValue(getYValue() + s);
225
+ };
226
+
227
+ // Decrement Y
228
+ const decrementY = (stepSize?: number) => {
229
+ const s = stepSize ?? yChannelStep();
230
+ setYValue(getYValue() - s);
231
+ };
232
+
233
+ // Set dragging
234
+ const setDraggingState = (dragging: boolean) => {
235
+ const wasDragging = isDragging();
236
+ setIsDragging(dragging);
237
+
238
+ // Call onChangeEnd when dragging ends
239
+ if (wasDragging && !dragging) {
240
+ getOptions().onChangeEnd?.(value());
241
+ }
242
+ };
243
+
244
+ // Get display color (alpha = 1)
245
+ const getDisplayColor = () => {
246
+ return value().withChannelValue('alpha', 1);
247
+ };
248
+
249
+ return {
250
+ get value() {
251
+ return value();
252
+ },
253
+ get xChannel() {
254
+ return xChannel();
255
+ },
256
+ get yChannel() {
257
+ return yChannel();
258
+ },
259
+ get zChannel() {
260
+ return zChannel();
261
+ },
262
+ get isDragging() {
263
+ return isDragging();
264
+ },
265
+ get isDisabled() {
266
+ return isDisabled();
267
+ },
268
+ get xChannelStep() {
269
+ return xChannelStep();
270
+ },
271
+ get yChannelStep() {
272
+ return yChannelStep();
273
+ },
274
+ get xChannelPageStep() {
275
+ return xChannelPageStep();
276
+ },
277
+ get yChannelPageStep() {
278
+ return yChannelPageStep();
279
+ },
280
+ getXValue,
281
+ getYValue,
282
+ setXValue,
283
+ setYValue,
284
+ setColorFromPoint,
285
+ getThumbPosition,
286
+ incrementX,
287
+ decrementX,
288
+ incrementY,
289
+ decrementY,
290
+ setDragging: setDraggingState,
291
+ getDisplayColor,
292
+ };
293
+ }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * ColorField state management.
3
+ * Based on @react-stately/color useColorFieldState.
4
+ */
5
+ import { type Accessor } from 'solid-js';
6
+ import type { Color, ColorChannel, ColorFormat } from './types';
7
+ export interface ColorFieldStateOptions {
8
+ /** The current color value (controlled). */
9
+ value?: Color | string | null;
10
+ /** The default color value (uncontrolled). */
11
+ defaultValue?: Color | string;
12
+ /** Handler called when the color changes. */
13
+ onChange?: (color: Color | null) => void;
14
+ /** The color channel to edit (for single channel mode). */
15
+ channel?: ColorChannel;
16
+ /** The color format for parsing/displaying. */
17
+ colorFormat?: ColorFormat;
18
+ /** Whether the field is disabled. */
19
+ isDisabled?: boolean;
20
+ /** Whether the field is read-only. */
21
+ isReadOnly?: boolean;
22
+ }
23
+ export interface ColorFieldState {
24
+ /** The current color value (null if invalid). */
25
+ readonly value: Color | null;
26
+ /** The current input text. */
27
+ readonly inputValue: string;
28
+ /** Whether the input is invalid. */
29
+ readonly isInvalid: boolean;
30
+ /** Whether the field is disabled. */
31
+ readonly isDisabled: boolean;
32
+ /** Whether the field is read-only. */
33
+ readonly isReadOnly: boolean;
34
+ /** The color channel being edited (if single channel mode). */
35
+ readonly channel: ColorChannel | undefined;
36
+ /** Set the input text value. */
37
+ setInputValue(value: string): void;
38
+ /** Commit the current input value. */
39
+ commit(): void;
40
+ /** Increment the color channel value. */
41
+ increment(): void;
42
+ /** Decrement the color channel value. */
43
+ decrement(): void;
44
+ /** Increment by page size. */
45
+ incrementToMax(): void;
46
+ /** Decrement to minimum. */
47
+ decrementToMin(): void;
48
+ /** Validate the current input. */
49
+ validate(): boolean;
50
+ }
51
+ /**
52
+ * Creates state for a color field (text input for color values).
53
+ */
54
+ export declare function createColorFieldState(options: Accessor<ColorFieldStateOptions>): ColorFieldState;
55
+ //# sourceMappingURL=createColorFieldState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createColorFieldState.d.ts","sourceRoot":"","sources":["createColorFieldState.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAA4B,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AACnE,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGhE,MAAM,WAAW,sBAAsB;IACrC,4CAA4C;IAC5C,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,IAAI,CAAC;IAC9B,8CAA8C;IAC9C,YAAY,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IAC9B,6CAA6C;IAC7C,QAAQ,CA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