@proyecto-viviana/solid-stately 0.2.3 → 0.2.7
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/dist/autocomplete/createAutocompleteState.d.ts +2 -1
- package/dist/checkbox/createCheckboxGroupState.d.ts +10 -1
- package/dist/collections/types.d.ts +11 -0
- package/dist/color/getColorChannels.d.ts +20 -0
- package/dist/data/createAsyncList.d.ts +111 -0
- package/dist/data/createListData.d.ts +65 -0
- package/dist/data/createTreeData.d.ts +61 -0
- package/dist/data/index.d.ts +3 -0
- package/dist/datepicker/index.d.ts +10 -0
- package/dist/grid/types.d.ts +5 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +3737 -2697
- package/dist/index.js.map +1 -7
- package/dist/menu/index.d.ts +8 -0
- package/dist/radio/createRadioGroupState.d.ts +10 -1
- package/dist/select/createSelectState.d.ts +17 -0
- package/dist/selection/index.d.ts +11 -0
- package/dist/toast/createToastState.d.ts +7 -1
- package/dist/toggle/createToggleGroupState.d.ts +45 -0
- package/dist/toggle/index.d.ts +1 -0
- package/dist/tree/TreeCollection.d.ts +3 -2
- package/package.json +6 -5
- package/src/autocomplete/createAutocompleteState.ts +10 -11
- package/src/calendar/createDateFieldState.ts +24 -1
- package/src/checkbox/createCheckboxGroupState.ts +42 -6
- package/src/collections/ListCollection.ts +152 -146
- package/src/collections/createListState.ts +266 -264
- package/src/collections/createMenuState.ts +106 -106
- package/src/collections/createSelectionState.ts +336 -336
- package/src/collections/index.ts +46 -46
- package/src/collections/types.ts +181 -169
- package/src/color/Color.ts +951 -951
- package/src/color/createColorAreaState.ts +293 -293
- package/src/color/createColorFieldState.ts +292 -292
- package/src/color/createColorSliderState.ts +241 -241
- package/src/color/createColorWheelState.ts +211 -211
- package/src/color/getColorChannels.ts +34 -0
- package/src/color/index.ts +47 -47
- package/src/color/types.ts +127 -127
- package/src/combobox/createComboBoxState.ts +703 -703
- package/src/combobox/index.ts +13 -13
- package/src/data/createAsyncList.ts +377 -0
- package/src/data/createListData.ts +298 -0
- package/src/data/createTreeData.ts +433 -0
- package/src/data/index.ts +25 -0
- package/src/datepicker/index.ts +36 -0
- package/src/disclosure/createDisclosureState.ts +4 -4
- package/src/dnd/createDragState.ts +153 -153
- package/src/dnd/createDraggableCollectionState.ts +165 -165
- package/src/dnd/createDropState.ts +212 -212
- package/src/dnd/createDroppableCollectionState.ts +357 -357
- package/src/dnd/index.ts +76 -76
- package/src/dnd/types.ts +317 -317
- package/src/form/createFormValidationState.ts +389 -389
- package/src/form/index.ts +15 -15
- package/src/grid/types.ts +5 -0
- package/src/index.ts +49 -0
- package/src/menu/index.ts +19 -0
- package/src/numberfield/createNumberFieldState.ts +427 -383
- package/src/numberfield/index.ts +5 -5
- package/src/overlays/createOverlayTriggerState.ts +67 -67
- package/src/overlays/index.ts +5 -5
- package/src/radio/createRadioGroupState.ts +44 -6
- package/src/searchfield/createSearchFieldState.ts +62 -62
- package/src/searchfield/index.ts +5 -5
- package/src/select/createSelectState.ts +290 -181
- package/src/select/index.ts +5 -5
- package/src/selection/index.ts +28 -0
- package/src/slider/createSliderState.ts +211 -211
- package/src/slider/index.ts +6 -6
- package/src/tabs/createTabListState.ts +37 -11
- package/src/toast/createToastState.d.ts +6 -1
- package/src/toast/createToastState.ts +8 -1
- package/src/toggle/createToggleGroupState.ts +127 -0
- package/src/toggle/index.ts +6 -0
- package/src/tooltip/createTooltipTriggerState.ts +183 -183
- package/src/tooltip/index.ts +6 -6
- package/src/tree/TreeCollection.ts +208 -175
- package/src/tree/createTreeState.ts +392 -392
- package/src/tree/index.ts +13 -13
- package/src/tree/types.ts +174 -174
|
@@ -1,211 +1,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, ColorChannel } from './types';
|
|
8
|
-
import { 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
|
-
/** Whether the wheel is being dragged. */
|
|
27
|
-
readonly isDragging: boolean;
|
|
28
|
-
/** Whether the wheel is disabled. */
|
|
29
|
-
readonly isDisabled: boolean;
|
|
30
|
-
/** Step value for hue changes. */
|
|
31
|
-
readonly step: number;
|
|
32
|
-
/** Page step value for hue changes. */
|
|
33
|
-
readonly pageStep: number;
|
|
34
|
-
|
|
35
|
-
/** Get the current hue value (0-360). */
|
|
36
|
-
getHue(): number;
|
|
37
|
-
/** Set the hue value. */
|
|
38
|
-
setHue(value: number): void;
|
|
39
|
-
/** Set hue from an angle in radians. */
|
|
40
|
-
setHueFromAngle(angle: number): void;
|
|
41
|
-
/** Get the thumb angle in radians (0 = right, increases counterclockwise). */
|
|
42
|
-
getThumbAngle(): number;
|
|
43
|
-
/** Increment hue value. */
|
|
44
|
-
increment(stepSize?: number): void;
|
|
45
|
-
/** Decrement hue value. */
|
|
46
|
-
decrement(stepSize?: number): void;
|
|
47
|
-
/** Set the dragging state. */
|
|
48
|
-
setDragging(isDragging: boolean): void;
|
|
49
|
-
/** Get the display color (with full saturation/brightness for wheel). */
|
|
50
|
-
getDisplayColor(): Color;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Creates state for a color wheel (circular hue picker).
|
|
55
|
-
*/
|
|
56
|
-
export function createColorWheelState(
|
|
57
|
-
options: Accessor<ColorWheelStateOptions>
|
|
58
|
-
): ColorWheelState {
|
|
59
|
-
const getOptions = () => options();
|
|
60
|
-
|
|
61
|
-
// Internal value state
|
|
62
|
-
const [internalValue, setInternalValue] = createSignal<Color | null>(null);
|
|
63
|
-
const [isDragging, setIsDragging] = createSignal(false);
|
|
64
|
-
|
|
65
|
-
// Initialize internal value
|
|
66
|
-
const initValue = () => {
|
|
67
|
-
const opts = getOptions();
|
|
68
|
-
if (opts.defaultValue) {
|
|
69
|
-
return normalizeColor(opts.defaultValue);
|
|
70
|
-
}
|
|
71
|
-
return null;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
// Set initial value
|
|
75
|
-
if (internalValue() === null) {
|
|
76
|
-
const init = initValue();
|
|
77
|
-
if (init) {
|
|
78
|
-
setInternalValue(init);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Controlled vs uncontrolled value
|
|
83
|
-
const value = createMemo(() => {
|
|
84
|
-
const opts = getOptions();
|
|
85
|
-
if (opts.value !== undefined) {
|
|
86
|
-
return normalizeColor(opts.value);
|
|
87
|
-
}
|
|
88
|
-
return internalValue() ?? normalizeColor('#ff0000');
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
const isDisabled = createMemo(() => getOptions().isDisabled ?? false);
|
|
92
|
-
|
|
93
|
-
// Hue step and page step
|
|
94
|
-
const hueRange = createMemo(() => value().getChannelRange('hue'));
|
|
95
|
-
const step = createMemo(() => hueRange().step);
|
|
96
|
-
const pageStep = createMemo(() => hueRange().pageSize);
|
|
97
|
-
|
|
98
|
-
// Update value
|
|
99
|
-
const updateValue = (newColor: Color) => {
|
|
100
|
-
const opts = getOptions();
|
|
101
|
-
|
|
102
|
-
// Controlled mode
|
|
103
|
-
if (opts.value !== undefined) {
|
|
104
|
-
opts.onChange?.(newColor);
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Uncontrolled mode
|
|
109
|
-
setInternalValue(newColor);
|
|
110
|
-
opts.onChange?.(newColor);
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
// Get hue value (0-360)
|
|
114
|
-
const getHue = () => value().getChannelValue('hue');
|
|
115
|
-
|
|
116
|
-
// Set hue value
|
|
117
|
-
const setHue = (newValue: number) => {
|
|
118
|
-
// Wrap hue to 0-360 range
|
|
119
|
-
let hue = newValue % 360;
|
|
120
|
-
if (hue < 0) hue += 360;
|
|
121
|
-
|
|
122
|
-
// Round to step
|
|
123
|
-
const range = hueRange();
|
|
124
|
-
const rounded = Math.round(hue / range.step) * range.step;
|
|
125
|
-
|
|
126
|
-
const newColor = value().withChannelValue('hue', rounded);
|
|
127
|
-
updateValue(newColor);
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
// Set hue from angle (radians, 0 = right, counterclockwise)
|
|
131
|
-
const setHueFromAngle = (angle: number) => {
|
|
132
|
-
// Convert angle to degrees (0-360)
|
|
133
|
-
// angle 0 = right (3 o'clock) = hue 0
|
|
134
|
-
// angle increases counterclockwise
|
|
135
|
-
let degrees = (angle * 180) / Math.PI;
|
|
136
|
-
degrees = 360 - degrees; // Convert to clockwise
|
|
137
|
-
if (degrees < 0) degrees += 360;
|
|
138
|
-
if (degrees >= 360) degrees -= 360;
|
|
139
|
-
|
|
140
|
-
setHue(degrees);
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
// Get thumb angle in radians
|
|
144
|
-
const getThumbAngle = () => {
|
|
145
|
-
const hue = getHue();
|
|
146
|
-
// Convert hue to angle (radians)
|
|
147
|
-
// hue 0 = angle 0 (right)
|
|
148
|
-
// hue increases clockwise, angle increases counterclockwise
|
|
149
|
-
const degrees = 360 - hue;
|
|
150
|
-
return (degrees * Math.PI) / 180;
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
// Increment hue
|
|
154
|
-
const increment = (stepSize?: number) => {
|
|
155
|
-
const s = stepSize ?? step();
|
|
156
|
-
setHue(getHue() + s);
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
// Decrement hue
|
|
160
|
-
const decrement = (stepSize?: number) => {
|
|
161
|
-
const s = stepSize ?? step();
|
|
162
|
-
setHue(getHue() - s);
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
// Set dragging state
|
|
166
|
-
const setDraggingState = (dragging: boolean) => {
|
|
167
|
-
const wasDragging = isDragging();
|
|
168
|
-
setIsDragging(dragging);
|
|
169
|
-
|
|
170
|
-
// Call onChangeEnd when dragging ends
|
|
171
|
-
if (wasDragging && !dragging) {
|
|
172
|
-
getOptions().onChangeEnd?.(value());
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
// Get display color (full saturation and brightness for wheel preview)
|
|
177
|
-
const getDisplayColor = () => {
|
|
178
|
-
// For display, we want the color at full saturation and brightness
|
|
179
|
-
// to show the pure hue on the wheel
|
|
180
|
-
return value()
|
|
181
|
-
.withChannelValue('saturation', 100)
|
|
182
|
-
.withChannelValue('brightness', 100)
|
|
183
|
-
.withChannelValue('alpha', 1);
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
return {
|
|
187
|
-
get value() {
|
|
188
|
-
return value();
|
|
189
|
-
},
|
|
190
|
-
get isDragging() {
|
|
191
|
-
return isDragging();
|
|
192
|
-
},
|
|
193
|
-
get isDisabled() {
|
|
194
|
-
return isDisabled();
|
|
195
|
-
},
|
|
196
|
-
get step() {
|
|
197
|
-
return step();
|
|
198
|
-
},
|
|
199
|
-
get pageStep() {
|
|
200
|
-
return pageStep();
|
|
201
|
-
},
|
|
202
|
-
getHue,
|
|
203
|
-
setHue,
|
|
204
|
-
setHueFromAngle,
|
|
205
|
-
getThumbAngle,
|
|
206
|
-
increment,
|
|
207
|
-
decrement,
|
|
208
|
-
setDragging: setDraggingState,
|
|
209
|
-
getDisplayColor,
|
|
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, ColorChannel } from './types';
|
|
8
|
+
import { 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
|
+
/** Whether the wheel is being dragged. */
|
|
27
|
+
readonly isDragging: boolean;
|
|
28
|
+
/** Whether the wheel is disabled. */
|
|
29
|
+
readonly isDisabled: boolean;
|
|
30
|
+
/** Step value for hue changes. */
|
|
31
|
+
readonly step: number;
|
|
32
|
+
/** Page step value for hue changes. */
|
|
33
|
+
readonly pageStep: number;
|
|
34
|
+
|
|
35
|
+
/** Get the current hue value (0-360). */
|
|
36
|
+
getHue(): number;
|
|
37
|
+
/** Set the hue value. */
|
|
38
|
+
setHue(value: number): void;
|
|
39
|
+
/** Set hue from an angle in radians. */
|
|
40
|
+
setHueFromAngle(angle: number): void;
|
|
41
|
+
/** Get the thumb angle in radians (0 = right, increases counterclockwise). */
|
|
42
|
+
getThumbAngle(): number;
|
|
43
|
+
/** Increment hue value. */
|
|
44
|
+
increment(stepSize?: number): void;
|
|
45
|
+
/** Decrement hue value. */
|
|
46
|
+
decrement(stepSize?: number): void;
|
|
47
|
+
/** Set the dragging state. */
|
|
48
|
+
setDragging(isDragging: boolean): void;
|
|
49
|
+
/** Get the display color (with full saturation/brightness for wheel). */
|
|
50
|
+
getDisplayColor(): Color;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Creates state for a color wheel (circular hue picker).
|
|
55
|
+
*/
|
|
56
|
+
export function createColorWheelState(
|
|
57
|
+
options: Accessor<ColorWheelStateOptions>
|
|
58
|
+
): ColorWheelState {
|
|
59
|
+
const getOptions = () => options();
|
|
60
|
+
|
|
61
|
+
// Internal value state
|
|
62
|
+
const [internalValue, setInternalValue] = createSignal<Color | null>(null);
|
|
63
|
+
const [isDragging, setIsDragging] = createSignal(false);
|
|
64
|
+
|
|
65
|
+
// Initialize internal value
|
|
66
|
+
const initValue = () => {
|
|
67
|
+
const opts = getOptions();
|
|
68
|
+
if (opts.defaultValue) {
|
|
69
|
+
return normalizeColor(opts.defaultValue);
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// Set initial value
|
|
75
|
+
if (internalValue() === null) {
|
|
76
|
+
const init = initValue();
|
|
77
|
+
if (init) {
|
|
78
|
+
setInternalValue(init);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Controlled vs uncontrolled value
|
|
83
|
+
const value = createMemo(() => {
|
|
84
|
+
const opts = getOptions();
|
|
85
|
+
if (opts.value !== undefined) {
|
|
86
|
+
return normalizeColor(opts.value);
|
|
87
|
+
}
|
|
88
|
+
return internalValue() ?? normalizeColor('#ff0000');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const isDisabled = createMemo(() => getOptions().isDisabled ?? false);
|
|
92
|
+
|
|
93
|
+
// Hue step and page step
|
|
94
|
+
const hueRange = createMemo(() => value().getChannelRange('hue'));
|
|
95
|
+
const step = createMemo(() => hueRange().step);
|
|
96
|
+
const pageStep = createMemo(() => hueRange().pageSize);
|
|
97
|
+
|
|
98
|
+
// Update value
|
|
99
|
+
const updateValue = (newColor: Color) => {
|
|
100
|
+
const opts = getOptions();
|
|
101
|
+
|
|
102
|
+
// Controlled mode
|
|
103
|
+
if (opts.value !== undefined) {
|
|
104
|
+
opts.onChange?.(newColor);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Uncontrolled mode
|
|
109
|
+
setInternalValue(newColor);
|
|
110
|
+
opts.onChange?.(newColor);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// Get hue value (0-360)
|
|
114
|
+
const getHue = () => value().getChannelValue('hue');
|
|
115
|
+
|
|
116
|
+
// Set hue value
|
|
117
|
+
const setHue = (newValue: number) => {
|
|
118
|
+
// Wrap hue to 0-360 range
|
|
119
|
+
let hue = newValue % 360;
|
|
120
|
+
if (hue < 0) hue += 360;
|
|
121
|
+
|
|
122
|
+
// Round to step
|
|
123
|
+
const range = hueRange();
|
|
124
|
+
const rounded = Math.round(hue / range.step) * range.step;
|
|
125
|
+
|
|
126
|
+
const newColor = value().withChannelValue('hue', rounded);
|
|
127
|
+
updateValue(newColor);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// Set hue from angle (radians, 0 = right, counterclockwise)
|
|
131
|
+
const setHueFromAngle = (angle: number) => {
|
|
132
|
+
// Convert angle to degrees (0-360)
|
|
133
|
+
// angle 0 = right (3 o'clock) = hue 0
|
|
134
|
+
// angle increases counterclockwise
|
|
135
|
+
let degrees = (angle * 180) / Math.PI;
|
|
136
|
+
degrees = 360 - degrees; // Convert to clockwise
|
|
137
|
+
if (degrees < 0) degrees += 360;
|
|
138
|
+
if (degrees >= 360) degrees -= 360;
|
|
139
|
+
|
|
140
|
+
setHue(degrees);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// Get thumb angle in radians
|
|
144
|
+
const getThumbAngle = () => {
|
|
145
|
+
const hue = getHue();
|
|
146
|
+
// Convert hue to angle (radians)
|
|
147
|
+
// hue 0 = angle 0 (right)
|
|
148
|
+
// hue increases clockwise, angle increases counterclockwise
|
|
149
|
+
const degrees = 360 - hue;
|
|
150
|
+
return (degrees * Math.PI) / 180;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
// Increment hue
|
|
154
|
+
const increment = (stepSize?: number) => {
|
|
155
|
+
const s = stepSize ?? step();
|
|
156
|
+
setHue(getHue() + s);
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// Decrement hue
|
|
160
|
+
const decrement = (stepSize?: number) => {
|
|
161
|
+
const s = stepSize ?? step();
|
|
162
|
+
setHue(getHue() - s);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
// Set dragging state
|
|
166
|
+
const setDraggingState = (dragging: boolean) => {
|
|
167
|
+
const wasDragging = isDragging();
|
|
168
|
+
setIsDragging(dragging);
|
|
169
|
+
|
|
170
|
+
// Call onChangeEnd when dragging ends
|
|
171
|
+
if (wasDragging && !dragging) {
|
|
172
|
+
getOptions().onChangeEnd?.(value());
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
// Get display color (full saturation and brightness for wheel preview)
|
|
177
|
+
const getDisplayColor = () => {
|
|
178
|
+
// For display, we want the color at full saturation and brightness
|
|
179
|
+
// to show the pure hue on the wheel
|
|
180
|
+
return value()
|
|
181
|
+
.withChannelValue('saturation', 100)
|
|
182
|
+
.withChannelValue('brightness', 100)
|
|
183
|
+
.withChannelValue('alpha', 1);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
get value() {
|
|
188
|
+
return value();
|
|
189
|
+
},
|
|
190
|
+
get isDragging() {
|
|
191
|
+
return isDragging();
|
|
192
|
+
},
|
|
193
|
+
get isDisabled() {
|
|
194
|
+
return isDisabled();
|
|
195
|
+
},
|
|
196
|
+
get step() {
|
|
197
|
+
return step();
|
|
198
|
+
},
|
|
199
|
+
get pageStep() {
|
|
200
|
+
return pageStep();
|
|
201
|
+
},
|
|
202
|
+
getHue,
|
|
203
|
+
setHue,
|
|
204
|
+
setHueFromAngle,
|
|
205
|
+
getThumbAngle,
|
|
206
|
+
increment,
|
|
207
|
+
decrement,
|
|
208
|
+
setDragging: setDraggingState,
|
|
209
|
+
getDisplayColor,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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(colorSpace: ColorSpace): [ColorChannel, ColorChannel, ColorChannel] {
|
|
29
|
+
const channels = COLOR_SPACE_CHANNELS[colorSpace];
|
|
30
|
+
if (!channels) {
|
|
31
|
+
throw new Error(`Unknown color space: ${colorSpace}`);
|
|
32
|
+
}
|
|
33
|
+
return channels;
|
|
34
|
+
}
|
package/src/color/index.ts
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Color state management exports.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
// Types
|
|
6
|
-
export type {
|
|
7
|
-
Color,
|
|
8
|
-
ColorFormat,
|
|
9
|
-
ColorSpace,
|
|
10
|
-
ColorChannel,
|
|
11
|
-
ColorChannelRange,
|
|
12
|
-
ColorAxes,
|
|
13
|
-
} from './types';
|
|
14
|
-
|
|
15
|
-
// Color class and utilities
|
|
16
|
-
export {
|
|
17
|
-
parseColor,
|
|
18
|
-
normalizeColor,
|
|
19
|
-
createRGBColor,
|
|
20
|
-
createHSLColor,
|
|
21
|
-
createHSBColor,
|
|
22
|
-
} from './Color';
|
|
23
|
-
|
|
24
|
-
// State hooks
|
|
25
|
-
export {
|
|
26
|
-
createColorSliderState,
|
|
27
|
-
type ColorSliderStateOptions,
|
|
28
|
-
type ColorSliderState,
|
|
29
|
-
} from './createColorSliderState';
|
|
30
|
-
|
|
31
|
-
export {
|
|
32
|
-
createColorAreaState,
|
|
33
|
-
type ColorAreaStateOptions,
|
|
34
|
-
type ColorAreaState,
|
|
35
|
-
} from './createColorAreaState';
|
|
36
|
-
|
|
37
|
-
export {
|
|
38
|
-
createColorWheelState,
|
|
39
|
-
type ColorWheelStateOptions,
|
|
40
|
-
type ColorWheelState,
|
|
41
|
-
} from './createColorWheelState';
|
|
42
|
-
|
|
43
|
-
export {
|
|
44
|
-
createColorFieldState,
|
|
45
|
-
type ColorFieldStateOptions,
|
|
46
|
-
type ColorFieldState,
|
|
47
|
-
} from './createColorFieldState';
|
|
1
|
+
/**
|
|
2
|
+
* Color state management exports.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// Types
|
|
6
|
+
export type {
|
|
7
|
+
Color,
|
|
8
|
+
ColorFormat,
|
|
9
|
+
ColorSpace,
|
|
10
|
+
ColorChannel,
|
|
11
|
+
ColorChannelRange,
|
|
12
|
+
ColorAxes,
|
|
13
|
+
} from './types';
|
|
14
|
+
|
|
15
|
+
// Color class and utilities
|
|
16
|
+
export {
|
|
17
|
+
parseColor,
|
|
18
|
+
normalizeColor,
|
|
19
|
+
createRGBColor,
|
|
20
|
+
createHSLColor,
|
|
21
|
+
createHSBColor,
|
|
22
|
+
} from './Color';
|
|
23
|
+
|
|
24
|
+
// State hooks
|
|
25
|
+
export {
|
|
26
|
+
createColorSliderState,
|
|
27
|
+
type ColorSliderStateOptions,
|
|
28
|
+
type ColorSliderState,
|
|
29
|
+
} from './createColorSliderState';
|
|
30
|
+
|
|
31
|
+
export {
|
|
32
|
+
createColorAreaState,
|
|
33
|
+
type ColorAreaStateOptions,
|
|
34
|
+
type ColorAreaState,
|
|
35
|
+
} from './createColorAreaState';
|
|
36
|
+
|
|
37
|
+
export {
|
|
38
|
+
createColorWheelState,
|
|
39
|
+
type ColorWheelStateOptions,
|
|
40
|
+
type ColorWheelState,
|
|
41
|
+
} from './createColorWheelState';
|
|
42
|
+
|
|
43
|
+
export {
|
|
44
|
+
createColorFieldState,
|
|
45
|
+
type ColorFieldStateOptions,
|
|
46
|
+
type ColorFieldState,
|
|
47
|
+
} from './createColorFieldState';
|