@proyecto-viviana/solid-stately 0.2.4 → 0.3.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/LICENSE +21 -0
- package/README.md +30 -283
- package/dist/autocomplete/createAutocompleteState.d.ts +3 -2
- package/dist/autocomplete/index.d.ts +1 -1
- package/dist/calendar/createCalendarState.d.ts +22 -7
- package/dist/calendar/createDateFieldState.d.ts +30 -7
- package/dist/calendar/createDatePickerState.d.ts +60 -0
- package/dist/calendar/createRangeCalendarState.d.ts +27 -8
- package/dist/calendar/createTimeFieldState.d.ts +34 -7
- package/dist/calendar/index.d.ts +7 -6
- package/dist/checkbox/createCheckboxGroupState.d.ts +12 -3
- package/dist/checkbox/index.d.ts +1 -1
- package/dist/collections/ListCollection.d.ts +1 -1
- package/dist/collections/createListState.d.ts +8 -8
- package/dist/collections/createMenuState.d.ts +7 -7
- package/dist/collections/createSelectionState.d.ts +5 -5
- package/dist/collections/index.d.ts +5 -5
- package/dist/collections/types.d.ts +23 -12
- package/dist/color/Color.d.ts +1 -1
- package/dist/color/createColorAreaState.d.ts +4 -2
- package/dist/color/createColorFieldState.d.ts +38 -12
- package/dist/color/createColorSliderState.d.ts +9 -2
- package/dist/color/createColorWheelState.d.ts +13 -2
- package/dist/color/getColorChannels.d.ts +20 -0
- package/dist/color/index.d.ts +6 -6
- package/dist/color/types.d.ts +4 -4
- package/dist/combobox/createComboBoxState.d.ts +27 -13
- package/dist/combobox/index.d.ts +1 -1
- package/dist/data/createAsyncList.d.ts +111 -0
- package/dist/data/createListData.d.ts +65 -0
- package/dist/data/createTreeData.d.ts +65 -0
- package/dist/data/index.d.ts +3 -0
- package/dist/datepicker/index.d.ts +8 -0
- package/dist/disclosure/createDisclosureState.d.ts +2 -2
- package/dist/disclosure/index.d.ts +1 -1
- package/dist/dnd/createDragState.d.ts +2 -2
- package/dist/dnd/createDraggableCollectionState.d.ts +2 -2
- package/dist/dnd/createDropState.d.ts +2 -2
- package/dist/dnd/createDroppableCollectionState.d.ts +3 -3
- package/dist/dnd/index.d.ts +5 -5
- package/dist/dnd/types.d.ts +16 -16
- package/dist/form/createFormValidationState.d.ts +3 -3
- package/dist/form/index.d.ts +1 -1
- package/dist/grid/createGridState.d.ts +2 -2
- package/dist/grid/index.d.ts +2 -2
- package/dist/grid/types.d.ts +17 -11
- package/dist/index.d.ts +31 -25
- package/dist/index.js +7990 -6264
- package/dist/index.js.map +1 -7
- package/dist/menu/index.d.ts +8 -0
- package/dist/numberfield/createNumberFieldState.d.ts +2 -2
- package/dist/numberfield/index.d.ts +1 -1
- package/dist/overlays/createOverlayTriggerState.d.ts +2 -2
- package/dist/overlays/index.d.ts +1 -1
- package/dist/radio/createRadioGroupState.d.ts +13 -4
- package/dist/radio/index.d.ts +1 -1
- package/dist/searchfield/createSearchFieldState.d.ts +2 -2
- package/dist/searchfield/index.d.ts +2 -2
- package/dist/select/createSelectState.d.ts +20 -3
- package/dist/select/index.d.ts +1 -1
- package/dist/selection/index.d.ts +11 -0
- package/dist/slider/createSliderState.d.ts +3 -3
- package/dist/slider/index.d.ts +2 -2
- package/dist/steplist/createStepListState.d.ts +48 -0
- package/dist/steplist/index.d.ts +1 -0
- package/dist/table/TableCollection.d.ts +3 -3
- package/dist/table/createTableColumnResizeState.d.ts +54 -0
- package/dist/table/createTableState.d.ts +2 -2
- package/dist/table/index.d.ts +5 -3
- package/dist/table/types.d.ts +10 -10
- package/dist/tabs/createTabListState.d.ts +5 -5
- package/dist/tabs/index.d.ts +1 -1
- package/dist/textfield/createTextFieldState.d.ts +2 -2
- package/dist/textfield/index.d.ts +1 -1
- package/dist/toast/createToastState.d.ts +15 -3
- package/dist/toast/index.d.ts +1 -1
- package/dist/toggle/createToggleGroupState.d.ts +45 -0
- package/dist/toggle/createToggleState.d.ts +2 -2
- package/dist/toggle/index.d.ts +2 -1
- package/dist/tooltip/createTooltipTriggerState.d.ts +2 -2
- package/dist/tooltip/index.d.ts +1 -1
- package/dist/tree/TreeCollection.d.ts +5 -4
- package/dist/tree/createTreeState.d.ts +2 -2
- package/dist/tree/index.d.ts +3 -3
- package/dist/tree/types.d.ts +19 -13
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/reactivity.d.ts +1 -1
- package/package.json +30 -30
- package/src/autocomplete/createAutocompleteState.d.ts +19 -17
- package/src/autocomplete/createAutocompleteState.ts +25 -32
- package/src/autocomplete/index.d.ts +6 -2
- package/src/autocomplete/index.ts +1 -1
- package/src/calendar/createCalendarState.d.ts +139 -117
- package/src/calendar/createCalendarState.ts +221 -74
- package/src/calendar/createDateFieldState.d.ts +130 -95
- package/src/calendar/createDateFieldState.ts +286 -151
- package/src/calendar/createDatePickerState.ts +347 -0
- package/src/calendar/createRangeCalendarState.d.ts +154 -129
- package/src/calendar/createRangeCalendarState.ts +293 -79
- package/src/calendar/createTimeFieldState.d.ts +81 -79
- package/src/calendar/createTimeFieldState.ts +187 -108
- package/src/calendar/index.d.ts +80 -7
- package/src/calendar/index.ts +21 -12
- package/src/checkbox/createCheckboxGroupState.d.ts +57 -55
- package/src/checkbox/createCheckboxGroupState.ts +57 -30
- package/src/checkbox/index.d.ts +6 -2
- package/src/checkbox/index.ts +1 -1
- package/src/collections/ListCollection.d.ts +25 -22
- package/src/collections/ListCollection.ts +152 -146
- package/src/collections/createListState.d.ts +73 -58
- package/src/collections/createListState.ts +267 -264
- package/src/collections/createMenuState.d.ts +36 -31
- package/src/collections/createMenuState.ts +112 -106
- package/src/collections/createSelectionState.d.ts +78 -65
- package/src/collections/createSelectionState.ts +340 -336
- package/src/collections/index.d.ts +38 -6
- package/src/collections/index.ts +41 -46
- package/src/collections/types.d.ts +101 -101
- package/src/collections/types.ts +181 -169
- package/src/color/Color.d.ts +20 -5
- package/src/color/Color.ts +1054 -951
- package/src/color/createColorAreaState.d.ts +67 -65
- package/src/color/createColorAreaState.ts +301 -293
- package/src/color/createColorFieldState.d.ts +46 -44
- package/src/color/createColorFieldState.ts +428 -292
- package/src/color/createColorSliderState.d.ts +58 -56
- package/src/color/createColorSliderState.ts +272 -241
- package/src/color/createColorWheelState.d.ts +42 -40
- package/src/color/createColorWheelState.ts +248 -211
- package/src/color/getColorChannels.ts +36 -0
- package/src/color/index.d.ts +36 -7
- package/src/color/index.ts +44 -47
- package/src/color/types.d.ts +68 -63
- package/src/color/types.ts +119 -127
- package/src/combobox/createComboBoxState.d.ts +107 -105
- package/src/combobox/createComboBoxState.ts +790 -703
- package/src/combobox/index.d.ts +10 -2
- package/src/combobox/index.ts +13 -13
- package/src/data/createAsyncList.ts +403 -0
- package/src/data/createListData.ts +298 -0
- package/src/data/createTreeData.ts +646 -0
- package/src/data/index.ts +25 -0
- package/src/datepicker/index.ts +32 -0
- package/src/disclosure/createDisclosureState.d.ts +47 -43
- package/src/disclosure/createDisclosureState.ts +9 -23
- package/src/disclosure/index.d.ts +10 -2
- package/src/disclosure/index.ts +1 -1
- package/src/dnd/createDragState.d.ts +51 -42
- package/src/dnd/createDragState.ts +151 -153
- package/src/dnd/createDraggableCollectionState.d.ts +52 -41
- package/src/dnd/createDraggableCollectionState.ts +158 -165
- package/src/dnd/createDropState.d.ts +64 -45
- package/src/dnd/createDropState.ts +202 -212
- package/src/dnd/createDroppableCollectionState.d.ts +88 -59
- package/src/dnd/createDroppableCollectionState.ts +354 -357
- package/src/dnd/index.d.ts +54 -6
- package/src/dnd/index.ts +63 -76
- package/src/dnd/types.d.ts +167 -156
- package/src/dnd/types.ts +316 -317
- package/src/form/createFormValidationState.d.ts +47 -45
- package/src/form/createFormValidationState.ts +356 -389
- package/src/form/index.d.ts +16 -2
- package/src/form/index.ts +15 -15
- package/src/grid/createGridState.d.ts +7 -4
- package/src/grid/createGridState.ts +44 -51
- package/src/grid/index.d.ts +3 -3
- package/src/grid/index.ts +2 -8
- package/src/grid/types.d.ts +136 -129
- package/src/grid/types.ts +24 -17
- package/src/index.d.ts +310 -26
- package/src/index.ts +87 -79
- package/src/menu/index.ts +17 -0
- package/src/numberfield/createNumberFieldState.d.ts +56 -54
- package/src/numberfield/createNumberFieldState.ts +422 -383
- package/src/numberfield/index.d.ts +6 -2
- package/src/numberfield/index.ts +5 -5
- package/src/overlays/createOverlayTriggerState.d.ts +22 -20
- package/src/overlays/createOverlayTriggerState.ts +66 -67
- package/src/overlays/index.d.ts +6 -2
- package/src/overlays/index.ts +5 -5
- package/src/radio/createRadioGroupState.d.ts +54 -52
- package/src/radio/createRadioGroupState.ts +66 -30
- package/src/radio/index.d.ts +7 -2
- package/src/radio/index.ts +1 -1
- package/src/searchfield/createSearchFieldState.d.ts +16 -14
- package/src/searchfield/createSearchFieldState.ts +56 -62
- package/src/searchfield/index.d.ts +3 -3
- package/src/searchfield/index.ts +2 -5
- package/src/select/createSelectState.d.ts +63 -61
- package/src/select/createSelectState.ts +290 -181
- package/src/select/index.d.ts +2 -2
- package/src/select/index.ts +1 -5
- package/src/selection/index.ts +27 -0
- package/src/slider/createSliderState.d.ts +60 -60
- package/src/slider/createSliderState.ts +233 -211
- package/src/slider/index.d.ts +3 -3
- package/src/slider/index.ts +2 -6
- package/src/ssr/index.d.ts +1 -1
- package/src/ssr/index.ts +2 -2
- package/src/steplist/createStepListState.ts +191 -0
- package/src/steplist/index.ts +5 -0
- package/src/table/TableCollection.d.ts +42 -40
- package/src/table/TableCollection.ts +61 -64
- package/src/table/createTableColumnResizeState.ts +242 -0
- package/src/table/createTableState.d.ts +7 -4
- package/src/table/createTableState.ts +10 -7
- package/src/table/index.d.ts +14 -4
- package/src/table/index.ts +10 -3
- package/src/table/types.d.ts +98 -92
- package/src/table/types.ts +17 -13
- package/src/tabs/createTabListState.d.ts +59 -57
- package/src/tabs/createTabListState.ts +58 -39
- package/src/tabs/index.d.ts +8 -2
- package/src/tabs/index.ts +1 -1
- package/src/textfield/createTextFieldState.d.ts +16 -14
- package/src/textfield/createTextFieldState.ts +7 -18
- package/src/textfield/index.d.ts +6 -2
- package/src/textfield/index.ts +1 -1
- package/src/toast/createToastState.d.ts +92 -81
- package/src/toast/createToastState.ts +56 -44
- package/src/toast/index.d.ts +12 -2
- package/src/toast/index.ts +1 -1
- package/src/toggle/createToggleGroupState.ts +117 -0
- package/src/toggle/createToggleState.d.ts +19 -19
- package/src/toggle/createToggleState.ts +2 -16
- package/src/toggle/index.d.ts +2 -2
- package/src/toggle/index.ts +6 -4
- package/src/tooltip/createTooltipTriggerState.d.ts +17 -17
- package/src/tooltip/createTooltipTriggerState.ts +184 -183
- package/src/tooltip/index.d.ts +7 -2
- package/src/tooltip/index.ts +6 -6
- package/src/tree/TreeCollection.d.ts +26 -23
- package/src/tree/TreeCollection.ts +215 -175
- package/src/tree/createTreeState.d.ts +7 -4
- package/src/tree/createTreeState.ts +390 -392
- package/src/tree/index.d.ts +10 -4
- package/src/tree/index.ts +13 -13
- package/src/tree/types.d.ts +131 -126
- package/src/tree/types.ts +183 -174
- package/src/utils/index.d.ts +2 -2
- package/src/utils/index.ts +1 -1
- package/src/utils/reactivity.d.ts +2 -2
- package/src/utils/reactivity.ts +3 -3
|
@@ -2,50 +2,52 @@
|
|
|
2
2
|
* ColorWheel state management.
|
|
3
3
|
* Based on @react-stately/color useColorWheelState.
|
|
4
4
|
*/
|
|
5
|
-
import { type Accessor } from
|
|
6
|
-
import type { Color } from
|
|
5
|
+
import { type Accessor } from "solid-js";
|
|
6
|
+
import type { Color } from "./types";
|
|
7
7
|
export interface ColorWheelStateOptions {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
+
/** Whether the wheel is disabled. */
|
|
17
|
+
isDisabled?: boolean;
|
|
18
18
|
}
|
|
19
19
|
export interface ColorWheelState {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
20
|
+
/** The current color value. */
|
|
21
|
+
readonly value: Color;
|
|
22
|
+
/** Whether the wheel is being dragged. */
|
|
23
|
+
readonly isDragging: boolean;
|
|
24
|
+
/** Whether the wheel is disabled. */
|
|
25
|
+
readonly isDisabled: boolean;
|
|
26
|
+
/** Step value for hue changes. */
|
|
27
|
+
readonly step: number;
|
|
28
|
+
/** Page step value for hue changes. */
|
|
29
|
+
readonly pageStep: number;
|
|
30
|
+
/** Get the current hue value (0-360). */
|
|
31
|
+
getHue(): number;
|
|
32
|
+
/** Set the hue value. */
|
|
33
|
+
setHue(value: number): void;
|
|
34
|
+
/** Set hue from an angle in radians. */
|
|
35
|
+
setHueFromAngle(angle: number): void;
|
|
36
|
+
/** Get the thumb angle in radians (0 = right, increases counterclockwise). */
|
|
37
|
+
getThumbAngle(): number;
|
|
38
|
+
/** Increment hue value. */
|
|
39
|
+
increment(stepSize?: number): void;
|
|
40
|
+
/** Decrement hue value. */
|
|
41
|
+
decrement(stepSize?: number): void;
|
|
42
|
+
/** Set the dragging state. */
|
|
43
|
+
setDragging(isDragging: boolean): void;
|
|
44
|
+
/** Get the display color (with full saturation/brightness for wheel). */
|
|
45
|
+
getDisplayColor(): Color;
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* Creates state for a color wheel (circular hue picker).
|
|
49
49
|
*/
|
|
50
|
-
export declare function createColorWheelState(
|
|
51
|
-
|
|
50
|
+
export declare function createColorWheelState(
|
|
51
|
+
options: Accessor<ColorWheelStateOptions>,
|
|
52
|
+
): ColorWheelState;
|
|
53
|
+
//# sourceMappingURL=createColorWheelState.d.ts.map
|
|
@@ -1,211 +1,248 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ColorWheel state management.
|
|
3
|
-
* Based on @react-stately/color useColorWheelState.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { createSignal, createMemo, type Accessor } from
|
|
7
|
-
import type { Color
|
|
8
|
-
import { normalizeColor } from
|
|
9
|
-
|
|
10
|
-
export interface ColorWheelStateOptions {
|
|
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
|
-
/** Whether the wheel is disabled. */
|
|
20
|
-
isDisabled?: boolean;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface ColorWheelState {
|
|
24
|
-
/** The current color value. */
|
|
25
|
-
readonly value: Color;
|
|
26
|
-
/**
|
|
27
|
-
readonly
|
|
28
|
-
/** Whether the wheel is
|
|
29
|
-
readonly
|
|
30
|
-
/**
|
|
31
|
-
readonly
|
|
32
|
-
/**
|
|
33
|
-
readonly
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
|
|
39
|
-
/** Set
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
|
|
49
|
-
/** Get the
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
|
|
55
|
-
*/
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
):
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
//
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const rounded = Math.
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
setHue(
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
//
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
1
|
+
/**
|
|
2
|
+
* ColorWheel state management.
|
|
3
|
+
* Based on @react-stately/color useColorWheelState.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { createSignal, createMemo, type Accessor } from "solid-js";
|
|
7
|
+
import type { Color } from "./types";
|
|
8
|
+
import { createHSLColor, normalizeColor } from "./Color";
|
|
9
|
+
|
|
10
|
+
export interface ColorWheelStateOptions {
|
|
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
|
+
/** Whether the wheel is disabled. */
|
|
20
|
+
isDisabled?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface ColorWheelState {
|
|
24
|
+
/** The current color value. */
|
|
25
|
+
readonly value: Color;
|
|
26
|
+
/** The initial color value. */
|
|
27
|
+
readonly defaultValue: Color;
|
|
28
|
+
/** Whether the wheel is being dragged. */
|
|
29
|
+
readonly isDragging: boolean;
|
|
30
|
+
/** Whether the wheel is disabled. */
|
|
31
|
+
readonly isDisabled: boolean;
|
|
32
|
+
/** Step value for hue changes. */
|
|
33
|
+
readonly step: number;
|
|
34
|
+
/** Page step value for hue changes. */
|
|
35
|
+
readonly pageStep: number;
|
|
36
|
+
|
|
37
|
+
/** Get the current hue value (0-360). */
|
|
38
|
+
getHue(): number;
|
|
39
|
+
/** Set the full color value. */
|
|
40
|
+
setValue(value: Color | string): void;
|
|
41
|
+
/** Set the hue value. */
|
|
42
|
+
setHue(value: number): void;
|
|
43
|
+
/** Set hue from an angle in radians. */
|
|
44
|
+
setHueFromAngle(angle: number): void;
|
|
45
|
+
/** Set hue from a point relative to the wheel center. */
|
|
46
|
+
setHueFromPoint(x: number, y: number, radius: number): void;
|
|
47
|
+
/** Get the thumb angle in radians (0 = right, increases counterclockwise). */
|
|
48
|
+
getThumbAngle(): number;
|
|
49
|
+
/** Get the thumb position relative to the wheel center. */
|
|
50
|
+
getThumbPosition(radius: number): { x: number; y: number };
|
|
51
|
+
/** Increment hue value. */
|
|
52
|
+
increment(stepSize?: number): void;
|
|
53
|
+
/** Decrement hue value. */
|
|
54
|
+
decrement(stepSize?: number): void;
|
|
55
|
+
/** Set the dragging state. */
|
|
56
|
+
setDragging(isDragging: boolean): void;
|
|
57
|
+
/** Get the display color (with full saturation/brightness for wheel). */
|
|
58
|
+
getDisplayColor(): Color;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Creates state for a color wheel (circular hue picker).
|
|
63
|
+
*/
|
|
64
|
+
export function createColorWheelState(options: Accessor<ColorWheelStateOptions>): ColorWheelState {
|
|
65
|
+
const getOptions = () => options();
|
|
66
|
+
const defaultColor = createHSLColor(0, 100, 50);
|
|
67
|
+
|
|
68
|
+
const normalizeWheelValue = (color: Color | string) => {
|
|
69
|
+
const value = normalizeColor(color);
|
|
70
|
+
return value.toFormat(value.getColorSpace() === "hsb" ? "hsb" : "hsl");
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const initialValue = normalizeWheelValue(getOptions().defaultValue ?? defaultColor);
|
|
74
|
+
const [internalValue, setInternalValue] = createSignal<Color>(initialValue);
|
|
75
|
+
const [isDragging, setIsDragging] = createSignal(false);
|
|
76
|
+
let valueRef = initialValue;
|
|
77
|
+
|
|
78
|
+
// Controlled vs uncontrolled value
|
|
79
|
+
const value = createMemo(() => {
|
|
80
|
+
const opts = getOptions();
|
|
81
|
+
const nextValue = opts.value !== undefined ? normalizeWheelValue(opts.value) : internalValue();
|
|
82
|
+
valueRef = nextValue;
|
|
83
|
+
return nextValue;
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const isDisabled = createMemo(() => getOptions().isDisabled ?? false);
|
|
87
|
+
|
|
88
|
+
// Hue step and page step
|
|
89
|
+
const hueRange = createMemo(() => value().getChannelRange("hue"));
|
|
90
|
+
const step = createMemo(() => hueRange().step);
|
|
91
|
+
const pageStep = createMemo(() => hueRange().pageSize);
|
|
92
|
+
|
|
93
|
+
// Update value
|
|
94
|
+
const updateValue = (newColor: Color) => {
|
|
95
|
+
const opts = getOptions();
|
|
96
|
+
const nextColor = normalizeWheelValue(newColor);
|
|
97
|
+
valueRef = nextColor;
|
|
98
|
+
|
|
99
|
+
// Controlled mode
|
|
100
|
+
if (opts.value !== undefined) {
|
|
101
|
+
opts.onChange?.(nextColor);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Uncontrolled mode
|
|
106
|
+
setInternalValue(nextColor);
|
|
107
|
+
opts.onChange?.(nextColor);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// Get hue value (0-360)
|
|
111
|
+
const getHue = () => value().getChannelValue("hue");
|
|
112
|
+
|
|
113
|
+
const setValue = (newValue: Color | string) => {
|
|
114
|
+
updateValue(normalizeWheelValue(newValue));
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const roundToStep = (num: number, stepValue: number) => {
|
|
118
|
+
const rounded = Math.round(num / stepValue) * stepValue;
|
|
119
|
+
const precision = `${stepValue}`.split(".")[1]?.length ?? 0;
|
|
120
|
+
return Number(rounded.toFixed(precision));
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const roundDown = (num: number) => {
|
|
124
|
+
const rounded = Math.floor(num);
|
|
125
|
+
return rounded === num ? num - 1 : rounded;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const mod = (n: number, m: number) => ((n % m) + m) % m;
|
|
129
|
+
|
|
130
|
+
const radToDeg = (rad: number) => (rad * 180) / Math.PI;
|
|
131
|
+
const degToRad = (deg: number) => (deg * Math.PI) / 180;
|
|
132
|
+
|
|
133
|
+
const cartesianToAngle = (x: number, y: number, radius: number) => {
|
|
134
|
+
const clampedX = Math.max(-radius, Math.min(radius, x));
|
|
135
|
+
const clampedY = Math.max(-radius, Math.min(radius, y));
|
|
136
|
+
return mod(radToDeg(Math.atan2(clampedY, clampedX)), 360);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const angleToCartesian = (angle: number, radius: number) => ({
|
|
140
|
+
x: radius * Math.cos(degToRad(angle)),
|
|
141
|
+
y: radius * Math.sin(degToRad(angle)),
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// Set hue value
|
|
145
|
+
const setHue = (newValue: number) => {
|
|
146
|
+
const currentHue = getHue();
|
|
147
|
+
const range = hueRange();
|
|
148
|
+
const hue = newValue > range.maxValue ? range.minValue : newValue;
|
|
149
|
+
const rounded = roundToStep(mod(hue, range.maxValue), range.step);
|
|
150
|
+
if (rounded === currentHue) return;
|
|
151
|
+
|
|
152
|
+
const newColor = value().withChannelValue("hue", rounded);
|
|
153
|
+
updateValue(newColor);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
// Set hue from angle (radians, 0 = right, counterclockwise)
|
|
157
|
+
const setHueFromAngle = (angle: number) => {
|
|
158
|
+
setHue(mod(360 - radToDeg(angle), 360));
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const setHueFromPoint = (x: number, y: number, radius: number) => {
|
|
162
|
+
setHue(cartesianToAngle(x, y, radius));
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
// Get thumb angle in radians
|
|
166
|
+
const getThumbAngle = () => {
|
|
167
|
+
return degToRad(360 - getHue());
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const getThumbPosition = (radius: number) => {
|
|
171
|
+
return angleToCartesian(getHue(), radius);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// Increment hue
|
|
175
|
+
const increment = (stepSize?: number) => {
|
|
176
|
+
const range = hueRange();
|
|
177
|
+
const s = Math.max(stepSize ?? range.step, range.step);
|
|
178
|
+
const nextValue = getHue() + s;
|
|
179
|
+
if (nextValue >= range.maxValue) {
|
|
180
|
+
setHue(range.minValue);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
setHue(roundToStep(mod(nextValue, range.maxValue), s));
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// Decrement hue
|
|
187
|
+
const decrement = (stepSize?: number) => {
|
|
188
|
+
const range = hueRange();
|
|
189
|
+
const s = Math.max(stepSize ?? range.step, range.step);
|
|
190
|
+
if (getHue() === range.minValue) {
|
|
191
|
+
setHue(roundDown(range.maxValue / s) * s);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
setHue(roundToStep(mod(getHue() - s, range.maxValue), s));
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
// Set dragging state
|
|
198
|
+
const setDraggingState = (dragging: boolean) => {
|
|
199
|
+
const wasDragging = isDragging();
|
|
200
|
+
setIsDragging(dragging);
|
|
201
|
+
|
|
202
|
+
// Call onChangeEnd when dragging ends
|
|
203
|
+
if (wasDragging && !dragging) {
|
|
204
|
+
getOptions().onChangeEnd?.(valueRef);
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
// Get display color (full saturation and brightness for wheel preview)
|
|
209
|
+
const getDisplayColor = () => {
|
|
210
|
+
return value()
|
|
211
|
+
.toFormat("hsl")
|
|
212
|
+
.withChannelValue("saturation", 100)
|
|
213
|
+
.withChannelValue("lightness", 50)
|
|
214
|
+
.withChannelValue("alpha", 1);
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
return {
|
|
218
|
+
get value() {
|
|
219
|
+
return value();
|
|
220
|
+
},
|
|
221
|
+
get defaultValue() {
|
|
222
|
+
return initialValue;
|
|
223
|
+
},
|
|
224
|
+
get isDragging() {
|
|
225
|
+
return isDragging();
|
|
226
|
+
},
|
|
227
|
+
get isDisabled() {
|
|
228
|
+
return isDisabled();
|
|
229
|
+
},
|
|
230
|
+
get step() {
|
|
231
|
+
return step();
|
|
232
|
+
},
|
|
233
|
+
get pageStep() {
|
|
234
|
+
return pageStep();
|
|
235
|
+
},
|
|
236
|
+
getHue,
|
|
237
|
+
setValue,
|
|
238
|
+
setHue,
|
|
239
|
+
setHueFromAngle,
|
|
240
|
+
setHueFromPoint,
|
|
241
|
+
getThumbAngle,
|
|
242
|
+
getThumbPosition,
|
|
243
|
+
increment,
|
|
244
|
+
decrement,
|
|
245
|
+
setDragging: setDraggingState,
|
|
246
|
+
getDisplayColor,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* getColorChannels - Standalone function to get color channels for a color space.
|
|
3
|
+
*
|
|
4
|
+
* Returns the three channels for a given color space.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { ColorChannel, ColorSpace } from "./types";
|
|
8
|
+
|
|
9
|
+
const COLOR_SPACE_CHANNELS: Record<ColorSpace, [ColorChannel, ColorChannel, ColorChannel]> = {
|
|
10
|
+
rgb: ["red", "green", "blue"],
|
|
11
|
+
hsl: ["hue", "saturation", "lightness"],
|
|
12
|
+
hsb: ["hue", "saturation", "brightness"],
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Returns the color channels for a given color space.
|
|
17
|
+
*
|
|
18
|
+
* @param colorSpace - The color space to get channels for.
|
|
19
|
+
* @returns A tuple of three color channels.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* getColorChannels('rgb') // ['red', 'green', 'blue']
|
|
24
|
+
* getColorChannels('hsl') // ['hue', 'saturation', 'lightness']
|
|
25
|
+
* getColorChannels('hsb') // ['hue', 'saturation', 'brightness']
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function getColorChannels(
|
|
29
|
+
colorSpace: ColorSpace,
|
|
30
|
+
): [ColorChannel, ColorChannel, ColorChannel] {
|
|
31
|
+
const channels = COLOR_SPACE_CHANNELS[colorSpace];
|
|
32
|
+
if (!channels) {
|
|
33
|
+
throw new Error(`Unknown color space: ${colorSpace}`);
|
|
34
|
+
}
|
|
35
|
+
return channels;
|
|
36
|
+
}
|
package/src/color/index.d.ts
CHANGED
|
@@ -1,10 +1,39 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Color state management exports.
|
|
3
3
|
*/
|
|
4
|
-
export type {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
export type {
|
|
5
|
+
Color,
|
|
6
|
+
ColorFormat,
|
|
7
|
+
ColorSpace,
|
|
8
|
+
ColorChannel,
|
|
9
|
+
ColorChannelRange,
|
|
10
|
+
ColorAxes,
|
|
11
|
+
} from "./types";
|
|
12
|
+
export {
|
|
13
|
+
parseColor,
|
|
14
|
+
normalizeColor,
|
|
15
|
+
createRGBColor,
|
|
16
|
+
createHSLColor,
|
|
17
|
+
createHSBColor,
|
|
18
|
+
} from "./Color";
|
|
19
|
+
export {
|
|
20
|
+
createColorSliderState,
|
|
21
|
+
type ColorSliderStateOptions,
|
|
22
|
+
type ColorSliderState,
|
|
23
|
+
} from "./createColorSliderState";
|
|
24
|
+
export {
|
|
25
|
+
createColorAreaState,
|
|
26
|
+
type ColorAreaStateOptions,
|
|
27
|
+
type ColorAreaState,
|
|
28
|
+
} from "./createColorAreaState";
|
|
29
|
+
export {
|
|
30
|
+
createColorWheelState,
|
|
31
|
+
type ColorWheelStateOptions,
|
|
32
|
+
type ColorWheelState,
|
|
33
|
+
} from "./createColorWheelState";
|
|
34
|
+
export {
|
|
35
|
+
createColorFieldState,
|
|
36
|
+
type ColorFieldStateOptions,
|
|
37
|
+
type ColorFieldState,
|
|
38
|
+
} from "./createColorFieldState";
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|