@proyecto-viviana/solidaria 0.2.4 → 0.2.8
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/actiongroup/createActionGroup.d.ts +29 -0
- package/dist/actiongroup/createActionGroup.d.ts.map +1 -0
- package/dist/actiongroup/index.d.ts +2 -0
- package/dist/actiongroup/index.d.ts.map +1 -0
- package/dist/autocomplete/createAutocomplete.d.ts +6 -2
- package/dist/autocomplete/createAutocomplete.d.ts.map +1 -1
- package/dist/breadcrumbs/createBreadcrumbs.d.ts +2 -0
- package/dist/breadcrumbs/createBreadcrumbs.d.ts.map +1 -1
- package/dist/button/createToggleButtonGroup.d.ts +32 -0
- package/dist/button/createToggleButtonGroup.d.ts.map +1 -0
- package/dist/button/index.d.ts +2 -0
- package/dist/button/index.d.ts.map +1 -1
- package/dist/calendar/createCalendarCell.d.ts +2 -0
- package/dist/calendar/createCalendarCell.d.ts.map +1 -1
- package/dist/calendar/createCalendarGrid.d.ts.map +1 -1
- package/dist/calendar/createRangeCalendarCell.d.ts +3 -1
- package/dist/calendar/createRangeCalendarCell.d.ts.map +1 -1
- package/dist/checkbox/createCheckboxGroup.d.ts +5 -1
- package/dist/checkbox/createCheckboxGroup.d.ts.map +1 -1
- package/dist/collections/index.d.ts +56 -0
- package/dist/collections/index.d.ts.map +1 -0
- package/dist/color/createColorArea.d.ts.map +1 -1
- package/dist/color/createColorSlider.d.ts.map +1 -1
- package/dist/color/createColorWheel.d.ts.map +1 -1
- package/dist/combobox/createComboBox.d.ts +6 -0
- package/dist/combobox/createComboBox.d.ts.map +1 -1
- package/dist/datepicker/createDatePicker.d.ts +6 -0
- package/dist/datepicker/createDatePicker.d.ts.map +1 -1
- package/dist/datepicker/createDateRangePicker.d.ts +40 -0
- package/dist/datepicker/createDateRangePicker.d.ts.map +1 -0
- package/dist/datepicker/createDateSegment.d.ts +1 -1
- package/dist/datepicker/createDateSegment.d.ts.map +1 -1
- package/dist/datepicker/createTimeSegment.d.ts +29 -0
- package/dist/datepicker/createTimeSegment.d.ts.map +1 -0
- package/dist/datepicker/index.d.ts +2 -0
- package/dist/datepicker/index.d.ts.map +1 -1
- package/dist/disclosure/createDisclosureGroup.d.ts +2 -1
- package/dist/disclosure/createDisclosureGroup.d.ts.map +1 -1
- package/dist/dnd/createDrag.d.ts.map +1 -1
- package/dist/dnd/createDraggableCollection.d.ts +4 -0
- package/dist/dnd/createDraggableCollection.d.ts.map +1 -1
- package/dist/dnd/createDraggableItem.d.ts.map +1 -1
- package/dist/dnd/createDrop.d.ts.map +1 -1
- package/dist/dnd/createDroppableCollection.d.ts +32 -1
- package/dist/dnd/createDroppableCollection.d.ts.map +1 -1
- package/dist/dnd/createDroppableItem.d.ts.map +1 -1
- package/dist/dnd/index.d.ts +1 -1
- package/dist/dnd/index.d.ts.map +1 -1
- package/dist/grid/createGrid.d.ts.map +1 -1
- package/dist/gridlist/createGridList.d.ts.map +1 -1
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4659 -3452
- package/dist/index.js.map +1 -7
- package/dist/index.ssr.js +4659 -3452
- package/dist/index.ssr.js.map +1 -7
- package/dist/interactions/createFocus.d.ts.map +1 -1
- package/dist/interactions/createFocusWithin.d.ts.map +1 -1
- package/dist/link/createLink.d.ts +10 -0
- package/dist/link/createLink.d.ts.map +1 -1
- package/dist/listbox/createListBox.d.ts +1 -0
- package/dist/listbox/createListBox.d.ts.map +1 -1
- package/dist/listbox/createOption.d.ts.map +1 -1
- package/dist/menu/createMenu.d.ts +1 -0
- package/dist/menu/createMenu.d.ts.map +1 -1
- package/dist/meter/createMeter.d.ts.map +1 -1
- package/dist/numberfield/createNumberField.d.ts +18 -0
- package/dist/numberfield/createNumberField.d.ts.map +1 -1
- package/dist/overlays/createModal.d.ts +16 -0
- package/dist/overlays/createModal.d.ts.map +1 -1
- package/dist/overlays/createOverlay.d.ts.map +1 -1
- package/dist/overlays/index.d.ts +1 -1
- package/dist/overlays/index.d.ts.map +1 -1
- package/dist/popover/createOverlayPosition.d.ts.map +1 -1
- package/dist/popover/createPopover.d.ts.map +1 -1
- package/dist/progress/createProgressBar.d.ts.map +1 -1
- package/dist/radio/createRadioGroup.d.ts +2 -2
- package/dist/radio/createRadioGroup.d.ts.map +1 -1
- package/dist/searchfield/createSearchField.d.ts.map +1 -1
- package/dist/select/createHiddenSelect.d.ts.map +1 -1
- package/dist/select/createSelect.d.ts.map +1 -1
- package/dist/slider/createSlider.d.ts.map +1 -1
- package/dist/table/createTable.d.ts.map +1 -1
- package/dist/tabs/createTabs.d.ts +1 -1
- package/dist/tabs/createTabs.d.ts.map +1 -1
- package/dist/tag/createTag.d.ts.map +1 -1
- package/dist/tag/createTagGroup.d.ts.map +1 -1
- package/dist/toast/createToast.d.ts +4 -0
- package/dist/toast/createToast.d.ts.map +1 -1
- package/dist/toast/createToastRegion.d.ts.map +1 -1
- package/dist/toolbar/createToolbar.d.ts.map +1 -1
- package/dist/tooltip/createTooltipTrigger.d.ts.map +1 -1
- package/dist/tree/createTree.d.ts.map +1 -1
- package/dist/tree/createTreeItem.d.ts.map +1 -1
- package/dist/tree/types.d.ts +4 -0
- package/dist/tree/types.d.ts.map +1 -1
- package/dist/utils/env.d.ts +1 -1
- package/dist/utils/env.d.ts.map +1 -1
- package/dist/utils/platform.d.ts.map +1 -1
- package/dist/visually-hidden/createVisuallyHidden.d.ts.map +1 -1
- package/package.json +8 -6
- package/src/actiongroup/createActionGroup.ts +324 -0
- package/src/actiongroup/index.ts +8 -0
- package/src/autocomplete/createAutocomplete.ts +32 -9
- package/src/breadcrumbs/createBreadcrumbs.ts +10 -15
- package/src/button/createButton.ts +1 -1
- package/src/button/createToggleButtonGroup.ts +128 -0
- package/src/button/index.ts +9 -0
- package/src/calendar/createCalendarCell.ts +6 -4
- package/src/calendar/createCalendarGrid.ts +27 -18
- package/src/calendar/createRangeCalendarCell.ts +26 -9
- package/src/checkbox/createCheckboxGroup.ts +21 -4
- package/src/collections/index.ts +242 -0
- package/src/color/createColorArea.ts +380 -314
- package/src/color/createColorField.ts +137 -137
- package/src/color/createColorSlider.ts +286 -197
- package/src/color/createColorSwatch.ts +40 -40
- package/src/color/createColorWheel.ts +218 -208
- package/src/color/index.ts +24 -24
- package/src/color/types.ts +116 -116
- package/src/combobox/createComboBox.ts +670 -647
- package/src/combobox/index.ts +6 -6
- package/src/datepicker/createDatePicker.ts +54 -16
- package/src/datepicker/createDateRangePicker.ts +246 -0
- package/src/datepicker/createDateSegment.ts +185 -31
- package/src/datepicker/createTimeSegment.ts +370 -0
- package/src/datepicker/index.ts +14 -0
- package/src/dialog/createDialog.ts +120 -120
- package/src/dialog/index.ts +2 -2
- package/src/dialog/types.ts +19 -19
- package/src/disclosure/createDisclosureGroup.ts +5 -2
- package/src/dnd/createDrag.ts +224 -209
- package/src/dnd/createDraggableCollection.ts +96 -63
- package/src/dnd/createDraggableItem.ts +259 -243
- package/src/dnd/createDrop.ts +322 -321
- package/src/dnd/createDroppableCollection.ts +682 -293
- package/src/dnd/createDroppableItem.ts +215 -213
- package/src/dnd/index.ts +55 -47
- package/src/dnd/types.ts +89 -89
- package/src/dnd/utils.ts +294 -294
- package/src/focus/createAutoFocus.ts +321 -321
- package/src/focus/createFocusRestore.ts +313 -313
- package/src/focus/createVirtualFocus.ts +396 -396
- package/src/form/createFormValidation.ts +224 -224
- package/src/form/index.ts +11 -11
- package/src/grid/createGrid.ts +3 -1
- package/src/gridlist/createGridList.ts +16 -0
- package/src/gridlist/createGridListItem.ts +1 -1
- package/src/i18n/NumberFormatter.ts +266 -266
- package/src/i18n/createCollator.ts +79 -79
- package/src/i18n/createDateFormatter.ts +83 -83
- package/src/i18n/createFilter.ts +131 -131
- package/src/i18n/createNumberFormatter.ts +52 -52
- package/src/i18n/index.ts +40 -40
- package/src/i18n/locale.tsx +188 -188
- package/src/i18n/utils.ts +99 -99
- package/src/index.ts +51 -0
- package/src/interactions/createFocus.ts +6 -5
- package/src/interactions/createFocusWithin.ts +6 -5
- package/src/interactions/createLongPress.ts +174 -174
- package/src/interactions/createMove.ts +289 -289
- package/src/interactions/createPress.ts +5 -5
- package/src/landmark/createLandmark.ts +377 -377
- package/src/landmark/index.ts +8 -8
- package/src/link/createLink.ts +23 -8
- package/src/listbox/createListBox.ts +308 -269
- package/src/listbox/createOption.ts +162 -151
- package/src/listbox/index.ts +12 -12
- package/src/live-announcer/announce.ts +322 -322
- package/src/live-announcer/index.ts +9 -9
- package/src/menu/createMenu.ts +405 -396
- package/src/menu/createMenuItem.ts +149 -149
- package/src/menu/createMenuTrigger.ts +88 -88
- package/src/menu/index.ts +18 -18
- package/src/meter/createMeter.ts +1 -6
- package/src/numberfield/createNumberField.ts +311 -268
- package/src/numberfield/index.ts +5 -5
- package/src/overlays/ariaHideOutside.ts +219 -219
- package/src/overlays/createInteractOutside.ts +149 -149
- package/src/overlays/createModal.tsx +238 -202
- package/src/overlays/createOverlay.ts +165 -155
- package/src/overlays/createOverlayTrigger.ts +85 -85
- package/src/overlays/createPreventScroll.ts +266 -266
- package/src/overlays/index.ts +48 -44
- package/src/popover/calculatePosition.ts +6 -6
- package/src/popover/createOverlayPosition.ts +7 -4
- package/src/popover/createPopover.ts +21 -7
- package/src/progress/createProgressBar.ts +6 -1
- package/src/radio/createRadioGroup.ts +88 -14
- package/src/searchfield/createSearchField.ts +241 -186
- package/src/searchfield/index.ts +2 -2
- package/src/select/createHiddenSelect.tsx +263 -236
- package/src/select/createSelect.ts +373 -395
- package/src/select/index.ts +14 -14
- package/src/slider/createSlider.ts +364 -349
- package/src/slider/index.ts +2 -2
- package/src/ssr/index.tsx +370 -370
- package/src/table/createTable.ts +3 -1
- package/src/table/createTableColumnHeader.ts +1 -1
- package/src/table/createTableRow.ts +1 -1
- package/src/tabs/createTabs.ts +80 -51
- package/src/tag/createTag.ts +135 -6
- package/src/tag/createTagGroup.ts +7 -2
- package/src/toast/createToast.ts +8 -2
- package/src/toast/createToastRegion.ts +0 -1
- package/src/toolbar/createToolbar.ts +75 -1
- package/src/tooltip/createTooltip.ts +79 -79
- package/src/tooltip/createTooltipTrigger.ts +226 -222
- package/src/tooltip/index.ts +6 -6
- package/src/tree/createTree.ts +261 -246
- package/src/tree/createTreeItem.ts +282 -233
- package/src/tree/createTreeSelectionCheckbox.ts +68 -68
- package/src/tree/index.ts +16 -16
- package/src/tree/types.ts +91 -87
- package/src/utils/env.ts +55 -54
- package/src/utils/platform.ts +16 -6
- package/src/visually-hidden/createVisuallyHidden.ts +139 -124
- package/src/visually-hidden/index.ts +6 -6
|
@@ -1,314 +1,380 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* createColorArea hook.
|
|
3
|
-
*
|
|
4
|
-
* Provides ARIA attributes and keyboard/pointer handling for a 2D color area.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { createMemo, type Accessor } from 'solid-js';
|
|
8
|
-
import type { ColorAreaState } from '@proyecto-viviana/solid-stately';
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
getState().
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
s.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
s.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
e.
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
e.
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
'aria-
|
|
174
|
-
'aria-
|
|
175
|
-
'aria-
|
|
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
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
'
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
'
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
1
|
+
/**
|
|
2
|
+
* createColorArea hook.
|
|
3
|
+
*
|
|
4
|
+
* Provides ARIA attributes and keyboard/pointer handling for a 2D color area.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { createMemo, type Accessor } from 'solid-js';
|
|
8
|
+
import type { Color, ColorAreaState, ColorChannel } from '@proyecto-viviana/solid-stately';
|
|
9
|
+
import { parseColor } from '@proyecto-viviana/solid-stately';
|
|
10
|
+
import { createId } from '../ssr';
|
|
11
|
+
import type { AriaColorAreaOptions, ColorAreaAria } from './types';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Creates ARIA props for a color area.
|
|
15
|
+
*/
|
|
16
|
+
export function createColorArea(
|
|
17
|
+
props: Accessor<AriaColorAreaOptions>,
|
|
18
|
+
state: Accessor<ColorAreaState>,
|
|
19
|
+
areaRef: Accessor<HTMLDivElement | null>
|
|
20
|
+
): ColorAreaAria {
|
|
21
|
+
const getProps = () => props();
|
|
22
|
+
const getState = () => state();
|
|
23
|
+
|
|
24
|
+
// Generate IDs
|
|
25
|
+
const xInputId = createId();
|
|
26
|
+
const yInputId = createId();
|
|
27
|
+
|
|
28
|
+
// Calculate position from pointer event
|
|
29
|
+
const getPositionFromEvent = (e: MouseEvent | PointerEvent) => {
|
|
30
|
+
const area = areaRef();
|
|
31
|
+
if (!area) return null;
|
|
32
|
+
|
|
33
|
+
const rect = area.getBoundingClientRect();
|
|
34
|
+
const x = Math.max(0, Math.min(1, (e.clientX - rect.left) / rect.width));
|
|
35
|
+
const y = Math.max(0, Math.min(1, (e.clientY - rect.top) / rect.height));
|
|
36
|
+
|
|
37
|
+
return { x, y };
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// Handle pointer down
|
|
41
|
+
const onPointerDown = (e: PointerEvent) => {
|
|
42
|
+
if (getProps().isDisabled || getState().isDisabled) return;
|
|
43
|
+
|
|
44
|
+
const pos = getPositionFromEvent(e);
|
|
45
|
+
if (!pos) return;
|
|
46
|
+
|
|
47
|
+
getState().setColorFromPoint(pos.x, pos.y);
|
|
48
|
+
getState().setDragging(true);
|
|
49
|
+
|
|
50
|
+
// Capture pointer for dragging
|
|
51
|
+
(e.target as HTMLElement).setPointerCapture?.(e.pointerId);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// Handle pointer move
|
|
55
|
+
const onPointerMove = (e: PointerEvent) => {
|
|
56
|
+
if (!getState().isDragging) return;
|
|
57
|
+
|
|
58
|
+
const pos = getPositionFromEvent(e);
|
|
59
|
+
if (!pos) return;
|
|
60
|
+
|
|
61
|
+
getState().setColorFromPoint(pos.x, pos.y);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// Handle pointer up
|
|
65
|
+
const onPointerUp = (e: PointerEvent) => {
|
|
66
|
+
if (getState().isDragging) {
|
|
67
|
+
getState().setDragging(false);
|
|
68
|
+
(e.target as HTMLElement).releasePointerCapture?.(e.pointerId);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// Handle keyboard for X axis
|
|
73
|
+
const onKeyDownX = (e: KeyboardEvent) => {
|
|
74
|
+
if (getProps().isDisabled || getState().isDisabled) return;
|
|
75
|
+
|
|
76
|
+
const s = getState();
|
|
77
|
+
let handled = true;
|
|
78
|
+
|
|
79
|
+
switch (e.key) {
|
|
80
|
+
case 'ArrowRight':
|
|
81
|
+
s.incrementX();
|
|
82
|
+
break;
|
|
83
|
+
case 'ArrowLeft':
|
|
84
|
+
s.decrementX();
|
|
85
|
+
break;
|
|
86
|
+
case 'ArrowUp':
|
|
87
|
+
s.incrementY();
|
|
88
|
+
break;
|
|
89
|
+
case 'ArrowDown':
|
|
90
|
+
s.decrementY();
|
|
91
|
+
break;
|
|
92
|
+
case 'PageUp':
|
|
93
|
+
s.incrementY(s.yChannelPageStep);
|
|
94
|
+
break;
|
|
95
|
+
case 'PageDown':
|
|
96
|
+
s.decrementY(s.yChannelPageStep);
|
|
97
|
+
break;
|
|
98
|
+
case 'Home':
|
|
99
|
+
if (e.ctrlKey) {
|
|
100
|
+
s.setXValue(0);
|
|
101
|
+
s.setYValue(100);
|
|
102
|
+
} else {
|
|
103
|
+
s.setXValue(0);
|
|
104
|
+
}
|
|
105
|
+
break;
|
|
106
|
+
case 'End':
|
|
107
|
+
if (e.ctrlKey) {
|
|
108
|
+
s.setXValue(100);
|
|
109
|
+
s.setYValue(0);
|
|
110
|
+
} else {
|
|
111
|
+
s.setXValue(100);
|
|
112
|
+
}
|
|
113
|
+
break;
|
|
114
|
+
default:
|
|
115
|
+
handled = false;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (handled) {
|
|
119
|
+
e.preventDefault();
|
|
120
|
+
e.stopPropagation();
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// Handle keyboard for Y axis
|
|
125
|
+
const onKeyDownY = (e: KeyboardEvent) => {
|
|
126
|
+
if (getProps().isDisabled || getState().isDisabled) return;
|
|
127
|
+
|
|
128
|
+
const s = getState();
|
|
129
|
+
let handled = true;
|
|
130
|
+
|
|
131
|
+
switch (e.key) {
|
|
132
|
+
case 'ArrowUp':
|
|
133
|
+
s.incrementY();
|
|
134
|
+
break;
|
|
135
|
+
case 'ArrowDown':
|
|
136
|
+
s.decrementY();
|
|
137
|
+
break;
|
|
138
|
+
case 'ArrowRight':
|
|
139
|
+
s.incrementX();
|
|
140
|
+
break;
|
|
141
|
+
case 'ArrowLeft':
|
|
142
|
+
s.decrementX();
|
|
143
|
+
break;
|
|
144
|
+
case 'PageUp':
|
|
145
|
+
s.incrementY(s.yChannelPageStep);
|
|
146
|
+
break;
|
|
147
|
+
case 'PageDown':
|
|
148
|
+
s.decrementY(s.yChannelPageStep);
|
|
149
|
+
break;
|
|
150
|
+
case 'Home':
|
|
151
|
+
s.setYValue(100);
|
|
152
|
+
break;
|
|
153
|
+
case 'End':
|
|
154
|
+
s.setYValue(0);
|
|
155
|
+
break;
|
|
156
|
+
default:
|
|
157
|
+
handled = false;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (handled) {
|
|
161
|
+
e.preventDefault();
|
|
162
|
+
e.stopPropagation();
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
// Color area props
|
|
167
|
+
const colorAreaProps = createMemo(() => {
|
|
168
|
+
const s = getState();
|
|
169
|
+
const p = getProps();
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
role: 'group' as const,
|
|
173
|
+
'aria-label': p['aria-label'],
|
|
174
|
+
'aria-labelledby': p['aria-labelledby'],
|
|
175
|
+
'aria-describedby': p['aria-describedby'],
|
|
176
|
+
'aria-disabled': s.isDisabled || p.isDisabled || undefined,
|
|
177
|
+
onPointerDown,
|
|
178
|
+
onPointerMove,
|
|
179
|
+
onPointerUp,
|
|
180
|
+
style: {
|
|
181
|
+
position: 'relative' as const,
|
|
182
|
+
'touch-action': 'none',
|
|
183
|
+
},
|
|
184
|
+
'data-disabled': s.isDisabled || p.isDisabled || undefined,
|
|
185
|
+
};
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// Generate gradient background for the color area
|
|
189
|
+
const generateGradient = (): Record<string, string> => {
|
|
190
|
+
const s = getState();
|
|
191
|
+
const value = s.value;
|
|
192
|
+
const xCh = s.xChannel;
|
|
193
|
+
const yCh = s.yChannel;
|
|
194
|
+
const zCh = s.zChannel;
|
|
195
|
+
const zValue = value.getChannelValue(zCh);
|
|
196
|
+
const end = 'right';
|
|
197
|
+
|
|
198
|
+
const hue = (color: Color) =>
|
|
199
|
+
[0, 60, 120, 180, 240, 300, 360].map(h => color.withChannelValue('hue', h).toString('css')).join(', ');
|
|
200
|
+
|
|
201
|
+
const hslChannels: Record<string, (c: Color) => string> = {
|
|
202
|
+
hue,
|
|
203
|
+
saturation: (color) => `${color.withChannelValue('saturation', 0).toString('css')}, transparent`,
|
|
204
|
+
lightness: () => 'black, transparent, white',
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const hsbChannels: Record<string, (c: Color) => string> = {
|
|
208
|
+
hue,
|
|
209
|
+
saturation: (color) => `${color.withChannelValue('saturation', 0).toString('css')}, transparent`,
|
|
210
|
+
brightness: () => 'black, transparent',
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
switch (value.getColorSpace()) {
|
|
214
|
+
case 'rgb': {
|
|
215
|
+
const rgb = parseColor('rgb(0, 0, 0)');
|
|
216
|
+
return {
|
|
217
|
+
background: [
|
|
218
|
+
`linear-gradient(to ${end}, ${rgb.withChannelValue(xCh, 0).toString('css')}, ${rgb.withChannelValue(xCh, 255).toString('css')})`,
|
|
219
|
+
`linear-gradient(to top, ${rgb.withChannelValue(yCh, 0).toString('css')}, ${rgb.withChannelValue(yCh, 255).toString('css')})`,
|
|
220
|
+
rgb.withChannelValue(zCh, zValue).toString('css'),
|
|
221
|
+
].join(','),
|
|
222
|
+
'background-blend-mode': 'screen',
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
case 'hsl': {
|
|
226
|
+
const channels = value.getColorChannels();
|
|
227
|
+
const base = parseColor('hsl(0, 100%, 50%)').withChannelValue(zCh, zValue);
|
|
228
|
+
const bg = channels
|
|
229
|
+
.filter((c: ColorChannel) => c !== zCh)
|
|
230
|
+
.map((c: ColorChannel) => `linear-gradient(to ${c === xCh ? end : 'top'}, ${hslChannels[c]?.(base) ?? ''})`)
|
|
231
|
+
.reverse();
|
|
232
|
+
if (zCh === 'hue') bg.push(base.toString('css'));
|
|
233
|
+
return { background: bg.join(', ') };
|
|
234
|
+
}
|
|
235
|
+
case 'hsb': {
|
|
236
|
+
const channels = value.getColorChannels();
|
|
237
|
+
const base = parseColor('hsb(0, 100%, 100%)').withChannelValue(zCh, zValue);
|
|
238
|
+
const bg = channels
|
|
239
|
+
.filter((c: ColorChannel) => c !== zCh)
|
|
240
|
+
.map((c: ColorChannel) => `linear-gradient(to ${c === xCh ? end : 'top'}, ${hsbChannels[c]?.(base) ?? ''})`)
|
|
241
|
+
.reverse();
|
|
242
|
+
if (zCh === 'hue') bg.push(base.toString('css'));
|
|
243
|
+
return { background: bg.join(', ') };
|
|
244
|
+
}
|
|
245
|
+
default:
|
|
246
|
+
return {};
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
// Gradient props (the visual area)
|
|
251
|
+
const gradientProps = createMemo(() => {
|
|
252
|
+
const gradientStyles = generateGradient();
|
|
253
|
+
return {
|
|
254
|
+
role: 'presentation' as const,
|
|
255
|
+
style: {
|
|
256
|
+
width: '100%',
|
|
257
|
+
height: '100%',
|
|
258
|
+
'forced-color-adjust': 'none' as const,
|
|
259
|
+
...gradientStyles,
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
// Thumb props
|
|
265
|
+
const thumbProps = createMemo(() => {
|
|
266
|
+
const s = getState();
|
|
267
|
+
const p = getProps();
|
|
268
|
+
const pos = s.getThumbPosition();
|
|
269
|
+
|
|
270
|
+
return {
|
|
271
|
+
role: 'presentation' as const,
|
|
272
|
+
style: {
|
|
273
|
+
position: 'absolute' as const,
|
|
274
|
+
left: `${pos.x * 100}%`,
|
|
275
|
+
top: `${pos.y * 100}%`,
|
|
276
|
+
transform: 'translate(-50%, -50%)',
|
|
277
|
+
'touch-action': 'none',
|
|
278
|
+
},
|
|
279
|
+
'data-dragging': s.isDragging || undefined,
|
|
280
|
+
'data-disabled': s.isDisabled || p.isDisabled || undefined,
|
|
281
|
+
};
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
// X input props (hidden, for accessibility)
|
|
285
|
+
const xInputProps = createMemo(() => {
|
|
286
|
+
const s = getState();
|
|
287
|
+
const p = getProps();
|
|
288
|
+
const xRange = s.value.getChannelRange(s.xChannel);
|
|
289
|
+
const xName = s.value.getChannelName(s.xChannel, 'en-US');
|
|
290
|
+
|
|
291
|
+
return {
|
|
292
|
+
type: 'range',
|
|
293
|
+
id: xInputId,
|
|
294
|
+
'aria-label': `${xName}`,
|
|
295
|
+
'aria-valuetext': `${xName}: ${s.getXValue()}`,
|
|
296
|
+
min: xRange.minValue,
|
|
297
|
+
max: xRange.maxValue,
|
|
298
|
+
step: xRange.step,
|
|
299
|
+
value: s.getXValue(),
|
|
300
|
+
disabled: s.isDisabled || p.isDisabled,
|
|
301
|
+
onKeyDown: onKeyDownX,
|
|
302
|
+
onChange: (e: Event) => {
|
|
303
|
+
const target = e.target as HTMLInputElement;
|
|
304
|
+
s.setXValue(parseFloat(target.value));
|
|
305
|
+
},
|
|
306
|
+
onBlur: () => {
|
|
307
|
+
if (s.isDragging) {
|
|
308
|
+
s.setDragging(false);
|
|
309
|
+
}
|
|
310
|
+
},
|
|
311
|
+
tabIndex: 0,
|
|
312
|
+
style: {
|
|
313
|
+
position: 'absolute' as const,
|
|
314
|
+
width: '1px',
|
|
315
|
+
height: '1px',
|
|
316
|
+
padding: '0',
|
|
317
|
+
margin: '-1px',
|
|
318
|
+
overflow: 'hidden',
|
|
319
|
+
clip: 'rect(0, 0, 0, 0)',
|
|
320
|
+
'white-space': 'nowrap',
|
|
321
|
+
border: '0',
|
|
322
|
+
},
|
|
323
|
+
};
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
// Y input props (hidden, for accessibility)
|
|
327
|
+
const yInputProps = createMemo(() => {
|
|
328
|
+
const s = getState();
|
|
329
|
+
const p = getProps();
|
|
330
|
+
const yRange = s.value.getChannelRange(s.yChannel);
|
|
331
|
+
const yName = s.value.getChannelName(s.yChannel, 'en-US');
|
|
332
|
+
|
|
333
|
+
return {
|
|
334
|
+
type: 'range',
|
|
335
|
+
id: yInputId,
|
|
336
|
+
'aria-label': `${yName}`,
|
|
337
|
+
'aria-valuetext': `${yName}: ${s.getYValue()}`,
|
|
338
|
+
min: yRange.minValue,
|
|
339
|
+
max: yRange.maxValue,
|
|
340
|
+
step: yRange.step,
|
|
341
|
+
value: s.getYValue(),
|
|
342
|
+
disabled: s.isDisabled || p.isDisabled,
|
|
343
|
+
onKeyDown: onKeyDownY,
|
|
344
|
+
onChange: (e: Event) => {
|
|
345
|
+
const target = e.target as HTMLInputElement;
|
|
346
|
+
s.setYValue(parseFloat(target.value));
|
|
347
|
+
},
|
|
348
|
+
tabIndex: -1, // Only first input is in tab order
|
|
349
|
+
style: {
|
|
350
|
+
position: 'absolute' as const,
|
|
351
|
+
width: '1px',
|
|
352
|
+
height: '1px',
|
|
353
|
+
padding: '0',
|
|
354
|
+
margin: '-1px',
|
|
355
|
+
overflow: 'hidden',
|
|
356
|
+
clip: 'rect(0, 0, 0, 0)',
|
|
357
|
+
'white-space': 'nowrap',
|
|
358
|
+
border: '0',
|
|
359
|
+
},
|
|
360
|
+
};
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
return {
|
|
364
|
+
get colorAreaProps() {
|
|
365
|
+
return colorAreaProps();
|
|
366
|
+
},
|
|
367
|
+
get gradientProps() {
|
|
368
|
+
return gradientProps();
|
|
369
|
+
},
|
|
370
|
+
get thumbProps() {
|
|
371
|
+
return thumbProps();
|
|
372
|
+
},
|
|
373
|
+
get xInputProps() {
|
|
374
|
+
return xInputProps();
|
|
375
|
+
},
|
|
376
|
+
get yInputProps() {
|
|
377
|
+
return yInputProps();
|
|
378
|
+
},
|
|
379
|
+
};
|
|
380
|
+
}
|