@mrpelz/uikit-ish 7.10.0 → 7.12.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 (177) hide show
  1. package/dist/components/action-sheet/main.d.ts.map +1 -1
  2. package/dist/components/action-sheet/main.js +2 -1
  3. package/dist/components/action-sheet/main.js.map +1 -1
  4. package/dist/components/action-sheet/style.css +6 -0
  5. package/dist/components/activity-view/main.d.ts.map +1 -1
  6. package/dist/components/activity-view/main.js +5 -0
  7. package/dist/components/activity-view/main.js.map +1 -1
  8. package/dist/components/activity-view/style.css +8 -0
  9. package/dist/components/alert/main.d.ts.map +1 -1
  10. package/dist/components/alert/main.js +2 -1
  11. package/dist/components/alert/main.js.map +1 -1
  12. package/dist/components/color-picker/color.d.ts +23 -0
  13. package/dist/components/color-picker/color.d.ts.map +1 -0
  14. package/dist/components/color-picker/color.js +150 -0
  15. package/dist/components/color-picker/color.js.map +1 -0
  16. package/dist/components/color-picker/main.d.ts +16 -6
  17. package/dist/components/color-picker/main.d.ts.map +1 -1
  18. package/dist/components/color-picker/main.js +472 -99
  19. package/dist/components/color-picker/main.js.map +1 -1
  20. package/dist/components/color-picker/named-colors.d.ts +3 -0
  21. package/dist/components/color-picker/named-colors.d.ts.map +1 -0
  22. package/dist/components/color-picker/named-colors.js +152 -0
  23. package/dist/components/color-picker/named-colors.js.map +1 -0
  24. package/dist/components/color-picker/props.d.ts +60 -12
  25. package/dist/components/color-picker/props.d.ts.map +1 -1
  26. package/dist/components/color-picker/style.css +211 -28
  27. package/dist/components/contextual-menu/main.d.ts +2 -2
  28. package/dist/components/contextual-menu/main.d.ts.map +1 -1
  29. package/dist/components/contextual-menu/main.js +19 -7
  30. package/dist/components/contextual-menu/main.js.map +1 -1
  31. package/dist/components/contextual-menu/props.d.ts +10 -1
  32. package/dist/components/contextual-menu/props.d.ts.map +1 -1
  33. package/dist/components/drawer/main.d.ts.map +1 -1
  34. package/dist/components/drawer/main.js +2 -1
  35. package/dist/components/drawer/main.js.map +1 -1
  36. package/dist/components/edit-menu/main.d.ts.map +1 -1
  37. package/dist/components/edit-menu/main.js +10 -8
  38. package/dist/components/edit-menu/main.js.map +1 -1
  39. package/dist/components/edit-menu/style.css +24 -2
  40. package/dist/components/glass/style.css +20 -1
  41. package/dist/components/index.d.ts +7 -5
  42. package/dist/components/index.d.ts.map +1 -1
  43. package/dist/components/index.js +3 -1
  44. package/dist/components/index.js.map +1 -1
  45. package/dist/components/island/main.d.ts +27 -0
  46. package/dist/components/island/main.d.ts.map +1 -0
  47. package/dist/components/island/main.js +409 -0
  48. package/dist/components/island/main.js.map +1 -0
  49. package/dist/components/island/props.d.ts +54 -0
  50. package/dist/components/island/props.d.ts.map +1 -0
  51. package/dist/components/island/props.js +2 -0
  52. package/dist/components/island/props.js.map +1 -0
  53. package/dist/components/island/style.css +404 -0
  54. package/dist/components/layout/props.d.ts +4 -3
  55. package/dist/components/layout/props.d.ts.map +1 -1
  56. package/dist/components/layout/style.css +37 -0
  57. package/dist/components/list/main.d.ts.map +1 -1
  58. package/dist/components/list/main.js +89 -17
  59. package/dist/components/list/main.js.map +1 -1
  60. package/dist/components/list/props.d.ts +4 -1
  61. package/dist/components/list/props.d.ts.map +1 -1
  62. package/dist/components/list/reorder.d.ts.map +1 -1
  63. package/dist/components/list/reorder.js +24 -0
  64. package/dist/components/list/reorder.js.map +1 -1
  65. package/dist/components/list/style.css +22 -3
  66. package/dist/components/menu/main.d.ts +13 -2
  67. package/dist/components/menu/main.d.ts.map +1 -1
  68. package/dist/components/menu/main.js +239 -9
  69. package/dist/components/menu/main.js.map +1 -1
  70. package/dist/components/menu/style.css +21 -6
  71. package/dist/components/navigation/main.d.ts +4 -2
  72. package/dist/components/navigation/main.d.ts.map +1 -1
  73. package/dist/components/navigation/main.js +115 -11
  74. package/dist/components/navigation/main.js.map +1 -1
  75. package/dist/components/navigation/props.d.ts +12 -1
  76. package/dist/components/navigation/props.d.ts.map +1 -1
  77. package/dist/components/navigation/style.css +25 -0
  78. package/dist/components/page/main.d.ts.map +1 -1
  79. package/dist/components/page/main.js +10 -5
  80. package/dist/components/page/main.js.map +1 -1
  81. package/dist/components/page/props.d.ts +8 -0
  82. package/dist/components/page/props.d.ts.map +1 -1
  83. package/dist/components/page/style.css +17 -0
  84. package/dist/components/popover/main.d.ts +5 -5
  85. package/dist/components/popover/main.d.ts.map +1 -1
  86. package/dist/components/popover/main.js +85 -27
  87. package/dist/components/popover/main.js.map +1 -1
  88. package/dist/components/popover/props.d.ts +26 -0
  89. package/dist/components/popover/props.d.ts.map +1 -1
  90. package/dist/components/popover/style.css +67 -3
  91. package/dist/components/progress/main.d.ts.map +1 -1
  92. package/dist/components/progress/main.js +47 -6
  93. package/dist/components/progress/main.js.map +1 -1
  94. package/dist/components/progress/style.css +4 -7
  95. package/dist/components/roll/main.d.ts.map +1 -1
  96. package/dist/components/roll/main.js +1 -1
  97. package/dist/components/roll/main.js.map +1 -1
  98. package/dist/components/roll/style.css +5 -0
  99. package/dist/components/segmented/main.d.ts.map +1 -1
  100. package/dist/components/segmented/main.js +149 -14
  101. package/dist/components/segmented/main.js.map +1 -1
  102. package/dist/components/segmented/props.d.ts +7 -0
  103. package/dist/components/segmented/props.d.ts.map +1 -1
  104. package/dist/components/segmented/style.css +135 -6
  105. package/dist/components/settings/main.d.ts +21 -0
  106. package/dist/components/settings/main.d.ts.map +1 -0
  107. package/dist/components/settings/main.js +182 -0
  108. package/dist/components/settings/main.js.map +1 -0
  109. package/dist/components/settings/props.d.ts +44 -0
  110. package/dist/components/settings/props.d.ts.map +1 -0
  111. package/dist/components/settings/props.js +2 -0
  112. package/dist/components/settings/props.js.map +1 -0
  113. package/dist/components/settings/style.css +8 -0
  114. package/dist/components/sheet/main.d.ts +11 -5
  115. package/dist/components/sheet/main.d.ts.map +1 -1
  116. package/dist/components/sheet/main.js +378 -20
  117. package/dist/components/sheet/main.js.map +1 -1
  118. package/dist/components/sheet/props.d.ts +56 -2
  119. package/dist/components/sheet/props.d.ts.map +1 -1
  120. package/dist/components/sheet/snap.d.ts +21 -0
  121. package/dist/components/sheet/snap.d.ts.map +1 -0
  122. package/dist/components/sheet/snap.js +363 -0
  123. package/dist/components/sheet/snap.js.map +1 -0
  124. package/dist/components/sheet/style.css +491 -33
  125. package/dist/components/sidebar/main.d.ts.map +1 -1
  126. package/dist/components/sidebar/main.js +6 -4
  127. package/dist/components/sidebar/main.js.map +1 -1
  128. package/dist/components/sidebar/style.css +17 -35
  129. package/dist/components/switch/style.css +2 -2
  130. package/dist/components/tab-bar/main.d.ts.map +1 -1
  131. package/dist/components/tab-bar/main.js +15 -8
  132. package/dist/components/tab-bar/main.js.map +1 -1
  133. package/dist/components/tab-bar/props.d.ts +2 -1
  134. package/dist/components/tab-bar/props.d.ts.map +1 -1
  135. package/dist/components/text-field/main.d.ts +2 -2
  136. package/dist/components/text-field/main.d.ts.map +1 -1
  137. package/dist/components/text-field/main.js +30 -10
  138. package/dist/components/text-field/main.js.map +1 -1
  139. package/dist/components/text-field/props.d.ts +5 -5
  140. package/dist/components/text-field/props.d.ts.map +1 -1
  141. package/dist/components/text-field/style.css +49 -20
  142. package/dist/components/tooltip/main.d.ts +1 -1
  143. package/dist/components/tooltip/main.d.ts.map +1 -1
  144. package/dist/components/tooltip/main.js +123 -8
  145. package/dist/components/tooltip/main.js.map +1 -1
  146. package/dist/components/utils/main.d.ts +12 -5
  147. package/dist/components/utils/main.d.ts.map +1 -1
  148. package/dist/components/utils/main.js +13 -4
  149. package/dist/components/utils/main.js.map +1 -1
  150. package/dist/components/viewport/edge-effect.d.ts.map +1 -1
  151. package/dist/components/viewport/edge-effect.js +128 -2
  152. package/dist/components/viewport/edge-effect.js.map +1 -1
  153. package/dist/components/viewport/edge.d.ts +1 -1
  154. package/dist/components/viewport/edge.d.ts.map +1 -1
  155. package/dist/components/viewport/edge.js +3 -3
  156. package/dist/components/viewport/edge.js.map +1 -1
  157. package/dist/components/viewport/input.d.ts +3 -1
  158. package/dist/components/viewport/input.d.ts.map +1 -1
  159. package/dist/components/viewport/input.js +57 -9
  160. package/dist/components/viewport/input.js.map +1 -1
  161. package/dist/components/viewport/ios27.d.ts +14 -0
  162. package/dist/components/viewport/ios27.d.ts.map +1 -0
  163. package/dist/components/viewport/ios27.js +28 -0
  164. package/dist/components/viewport/ios27.js.map +1 -0
  165. package/dist/components/viewport/main.d.ts +4 -2
  166. package/dist/components/viewport/main.d.ts.map +1 -1
  167. package/dist/components/viewport/main.js +206 -36
  168. package/dist/components/viewport/main.js.map +1 -1
  169. package/dist/components/viewport/padding.d.ts +12 -0
  170. package/dist/components/viewport/padding.d.ts.map +1 -1
  171. package/dist/components/viewport/padding.js +75 -15
  172. package/dist/components/viewport/padding.js.map +1 -1
  173. package/dist/components/viewport/props.d.ts +12 -1
  174. package/dist/components/viewport/props.d.ts.map +1 -1
  175. package/dist/components/viewport/style.css +63 -7
  176. package/dist/styles.css +56 -0
  177. package/package.json +7 -4
@@ -1,28 +1,35 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import '../button/style.css';
3
+ import '../list/style.css';
3
4
  import '../menu/style.css';
4
5
  import '../page-control/style.css';
5
6
  import '../segmented/style.css';
6
7
  import './style.css';
7
8
  import { Slider as BaseSlider } from '@base-ui/react/slider';
8
- import { cloneElement, createContext, forwardRef, useCallback, useContext, useLayoutEffect, useMemo, useRef, useState, } from 'react';
9
+ import { useRender } from '@base-ui/react/use-render';
10
+ import { Children, cloneElement, createContext, forwardRef, Fragment, isValidElement, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, } from 'react';
9
11
  import { Button } from '../button/main.js';
12
+ import { List } from '../list/main.js';
10
13
  import { Menu } from '../menu/main.js';
11
14
  import { PageControl } from '../page-control/main.js';
12
15
  import { Segmented } from '../segmented/main.js';
13
- import { cn, useTouchHold, withStyle } from '../utils/main.js';
16
+ import { Checkmark, cn, useForwardedRef, useTouchHold, withStyle, } from '../utils/main.js';
14
17
  import { Viewport } from '../viewport/main.js';
18
+ import { codeGroups, parseCssColor } from './color.js';
19
+ import { cssNamedColors } from './named-colors.js';
15
20
  // A color picker and a color well, in the app's popover (a regular width)
16
- // or sheet (compact), its header the app's (a `Toolbar`: the
17
- // eyedropper, “Colors”, close):
21
+ // or sheet (compact), its header the app's (a `Toolbar`: the eyedropper,
22
+ // “Colors”, close; in the popup's header, `Popover.Header` or
23
+ // `Sheet.Header`, the panel scrolling under it, behind its edge effect):
18
24
  // - a segmented control (Grid, Spectrum, Sliders), 24px above the view;
19
25
  // - Grid: 12 by 10 swatches (a gray row, then hues by lightness), its
20
26
  // corners 18px, the selected one outlined white (3px);
21
27
  // - Spectrum: hues across, light to dark down (white at the top, pure hues
22
28
  // halfway, black at the bottom), its corners 18px, the color ringed;
23
- // - Sliders: red, green and blue (0 to 255), each a channel's row (see
24
- // `ChannelRow`): its title (all caps), a slider mixing from the color
25
- // (the channel at 0 to 255), and its value, typed;
29
+ // - Sliders: red, green and blue (0 to 255; or 0 to 100%, see `Sliders`),
30
+ // each a channel's row (see `ChannelRow`): its title (all caps), a slider
31
+ // mixing from the color (the channel along its range), and its value,
32
+ // typed;
26
33
  // - Each channel's row kept above the keyboard as its field's typed into
27
34
  // (a `Viewport.KeyboardAccessory`; in a `Viewport.Provider`);
28
35
  // - Opacity (optional: its part, `Opacity`), a channel's row too: the
@@ -39,6 +46,10 @@ import { Viewport } from '../viewport/main.js';
39
46
  // opacity, always opaque).
40
47
  // - The eyedropper (`ColorPicker.Eyedropper`) is the browser's
41
48
  // (`EyeDropper`; not where it has none, e.g. Safari).
49
+ // - The system's color picker (`ColorPicker.SystemColors`) is a color
50
+ // input's (over its button, pressed itself: on iOS, nothing else opens
51
+ // it; with the opacity rendered, its alpha too where the input has one,
52
+ // e.g. Safari; else its colors opaque, the opacity kept).
42
53
  // - Saved colors are deleted by their menu (a secondary click: right click,
43
54
  // long press).
44
55
  // eslint-disable-next-line unicorn/no-unnecessary-parameters
@@ -119,14 +130,29 @@ const sameColor = (a, b) => Math.round(a.r) === Math.round(b.r) &&
119
130
  const unregister = () => undefined;
120
131
  const PickerContext = createContext({
121
132
  color: { a: 1, b: 0, g: 0, r: 0 },
133
+ hasOpacity: false,
122
134
  registerOpacity: () => unregister,
123
135
  setColor: () => undefined,
124
136
  });
125
137
  /**
126
- * A color picker: its color, for its
127
- * parts (`Panel`, `Eyedropper`), in the app's popover or sheet.
138
+ * Its modes (see `Root`): the one shown, chosen by its `Modes`; the first
139
+ * `Mode` (or `View`) unless a default is given.
128
140
  */
129
- const Root = forwardRef(({ className, defaultValue = '#000000', onValueChange, style, value, ...props }, ref) => {
141
+ const PanelContext = createContext({
142
+ isGridHeight: false,
143
+ mode: null,
144
+ registerGridHeight: () => unregister,
145
+ registerMode: () => undefined,
146
+ setMode: () => undefined,
147
+ });
148
+ /**
149
+ * A color picker: its color and its mode, for its parts (`Modes`,
150
+ * `Panel`, `Eyedropper`, anywhere in it), in the app's popover or sheet.
151
+ * Its element (`render`) may be the popover's or the sheet's popup, so its
152
+ * toolbar (and, in a sheet, its modes' control) can be in the popup's
153
+ * header (`Popover.Header`, `Sheet.Header`), its panel scrolling under it.
154
+ */
155
+ const Root = forwardRef(({ className, defaultMode, defaultValue = '#000000', mode: modeProp, onModeChange, onValueChange, render, style, value, ...props }, ref) => {
130
156
  const [own, setOwn] = useState(defaultValue);
131
157
  // Its `Opacity`s rendered: without one, the color opaque (its alpha,
132
158
  // if given one, dropped).
@@ -140,6 +166,7 @@ const Root = forwardRef(({ className, defaultValue = '#000000', onValueChange, s
140
166
  }, []);
141
167
  const state = useMemo(() => ({
142
168
  color,
169
+ hasOpacity,
143
170
  registerOpacity,
144
171
  // Uncontrolled: its own state; controlled, only the app's `value`.
145
172
  setColor: (next, details) => {
@@ -152,55 +179,68 @@ const Root = forwardRef(({ className, defaultValue = '#000000', onValueChange, s
152
179
  // (By its hex value.)
153
180
  // eslint-disable-next-line react-hooks/exhaustive-deps
154
181
  [value ?? own, onValueChange, hasOpacity]);
155
- return (_jsx(PickerContext.Provider, { value: state, children: _jsx("div", { ref: ref, style: withStyle({
156
- // (For its parts.)
157
- '--uikit-color-picker-color': formatColor(color),
158
- '--uikit-color-picker-color-opaque': formatColor({
159
- ...color,
160
- a: 1,
161
- }),
162
- }, style), ...props, className: cn('uikit-color-picker-root', className), "data-color-picker-part": "root" }) }));
163
- });
164
- /**
165
- * Its panel's modes (see `Panel`): the one shown, chosen by its `Modes`;
166
- * the first `Mode` (or `View`) unless a default is given.
167
- */
168
- const PanelContext = createContext({
169
- mode: null,
170
- registerMode: () => undefined,
171
- setMode: () => undefined,
172
- });
173
- /**
174
- * Its panel: its modes (`Modes`, a `Mode` each; a `View` each, paired by
175
- * their `value`s), the opacity, the color and the saved colors, as
176
- * composed (in its padding, its parts spaced).
177
- */
178
- const Panel = forwardRef(({ className, defaultMode, mode: modeProp, onModeChange, ...props }, ref) => {
179
182
  const [ownMode, setOwnMode] = useState(defaultMode);
180
183
  // (Without a default: the first mode, as it's rendered.)
181
184
  const [firstMode, setFirstMode] = useState();
182
185
  // (Controlled from the start: none yet, before its first mode is
183
186
  // known, not undefined, which would leave its control uncontrolled.)
184
187
  const mode = modeProp ?? ownMode ?? firstMode ?? null;
185
- const panel = useMemo(() => ({
188
+ // Its views of the grid's height (a `Grid`, a `Spectrum`): with one,
189
+ // all as high (see `View`).
190
+ const [gridHeights, setGridHeights] = useState(0);
191
+ const registerGridHeight = useCallback(() => {
192
+ setGridHeights((count) => count + 1);
193
+ return () => setGridHeights((count) => count - 1);
194
+ }, []);
195
+ const modes = useMemo(() => ({
196
+ isGridHeight: gridHeights > 0,
186
197
  mode,
187
- registerMode: (value) => setFirstMode((first) => first ?? value),
198
+ registerGridHeight,
199
+ registerMode: (next) => setFirstMode((first) => first ?? next),
188
200
  // Uncontrolled: its own state; controlled, only the app's `mode`.
189
201
  setMode: (next, details) => {
190
202
  if (modeProp === undefined)
191
203
  setOwnMode(next);
192
204
  onModeChange?.(next, details);
193
205
  },
194
- }), [mode, modeProp, onModeChange]);
195
- return (_jsx(PanelContext.Provider, { value: panel, children: _jsx("div", { ref: ref, ...props, className: cn('uikit-color-picker-panel', className), "data-color-picker-part": "panel" }) }));
206
+ }), [gridHeights, mode, modeProp, onModeChange, registerGridHeight]);
207
+ const element = useRender({
208
+ defaultTagName: 'div',
209
+ props: {
210
+ style: withStyle({
211
+ // (For its parts.)
212
+ '--uikit-color-picker-color': formatColor(color),
213
+ '--uikit-color-picker-color-opaque': formatColor({
214
+ ...color,
215
+ a: 1,
216
+ }),
217
+ }, style),
218
+ ...props,
219
+ className: cn('uikit-color-picker-root', className),
220
+ 'data-color-picker-part': 'root',
221
+ },
222
+ ref,
223
+ render,
224
+ });
225
+ return (_jsx(PickerContext.Provider, { value: state, children: _jsx(PanelContext.Provider, { value: modes, children: element }) }));
196
226
  });
227
+ /**
228
+ * Its panel: its modes' control (`Modes`, unless elsewhere, e.g. a sheet's
229
+ * header) and views (a `View` each, paired with its `Mode` by their
230
+ * `value`s), the opacity, the color and the saved colors, as composed (in
231
+ * its padding, its parts spaced).
232
+ */
233
+ const Panel = forwardRef(({ className, ...props }, ref) => (_jsx("div", { ref: ref, ...props, className: cn('uikit-color-picker-panel', className), "data-color-picker-part": "panel" })));
197
234
  /**
198
235
  * Its modes' control: a segmented control (its `Mode`s, its highlight),
199
- * choosing the `View` shown; 24px above it.
236
+ * choosing the `View` shown; 24px above it (in its panel, or at the end of
237
+ * a header).
200
238
  */
201
239
  const Modes = forwardRef(({ children, ...props }, ref) => {
202
240
  const { mode, setMode } = useContext(PanelContext);
203
- return (_jsxs(Segmented.Root, { ref: ref, "aria-label": "Mode", ...props, value: mode, onValueChange: (next, details) => setMode(String(next), details), children: [children, _jsx(Segmented.Highlight, {})] }));
241
+ return (_jsxs(Segmented.Root, { ref: ref, "aria-label": "Mode",
242
+ // (Its modes, however many, scrolled when they don't fit.)
243
+ overflow: "scroll", ...props, className: cn('uikit-color-picker-modes', props.className), value: mode, onValueChange: (next, details) => setMode(String(next), details), children: [children, _jsx(Segmented.Highlight, {})] }));
204
244
  });
205
245
  /** A mode, in its `Modes`: its label, choosing its `View` (by `value`). */
206
246
  const Mode = forwardRef(({ value, ...props }, ref) => {
@@ -208,18 +248,6 @@ const Mode = forwardRef(({ value, ...props }, ref) => {
208
248
  useLayoutEffect(() => registerMode(value), [registerMode, value]);
209
249
  return (_jsx(Segmented.Item, { ref: ref, value: value, ...props }));
210
250
  });
211
- /**
212
- * A mode's view (by `value`, its `Mode`'s): shown while it's chosen; all
213
- * as high as the grid (so a popover doesn't move as they're switched).
214
- */
215
- const View = forwardRef(({ className, value, ...props }, ref) => {
216
- const { mode, registerMode } = useContext(PanelContext);
217
- // (A mode, too: without `Modes`, its only view shown.)
218
- useLayoutEffect(() => registerMode(value), [registerMode, value]);
219
- if (mode !== value)
220
- return null;
221
- return (_jsx("div", { ref: ref, "data-color-picker-view": value, ...props, className: cn('uikit-color-picker-view', className), "data-color-picker-part": "view" }));
222
- });
223
251
  /** Swatches in rows (a gray row, then hues by lightness), its corners 18px. */
224
252
  const Grid = forwardRef(({ className, ...props }, ref) => {
225
253
  const { color, setColor } = useContext(PickerContext);
@@ -270,33 +298,90 @@ const Spectrum = forwardRef(({ className, ...props }, ref) => {
270
298
  top: `${String((1 - l) * 100)}%`,
271
299
  } }) }));
272
300
  });
301
+ /**
302
+ * A mode's view (by `value`, its `Mode`'s): shown while it's chosen. With a
303
+ * view of the grid's height (a `Grid` or `Spectrum` in it) among them, all
304
+ * as high (so a popover doesn't move as they're switched); without, each as
305
+ * high as its content (e.g. sliders alone).
306
+ */
307
+ const View = forwardRef(({ children, className, value, ...props }, ref) => {
308
+ const { isGridHeight, mode, registerGridHeight, registerMode } = useContext(PanelContext);
309
+ // (A mode, too: without `Modes`, its only view shown.)
310
+ useLayoutEffect(() => registerMode(value), [registerMode, value]);
311
+ // (Rendered or not: its own height known by its children's types.)
312
+ const isOwnGridHeight = Children.toArray(children).some((child) => isValidElement(child) &&
313
+ (child.type === Grid || child.type === Spectrum));
314
+ useLayoutEffect(() => (isOwnGridHeight ? registerGridHeight() : undefined), [isOwnGridHeight, registerGridHeight]);
315
+ if (mode !== value)
316
+ return null;
317
+ return (_jsx("div", { ref: ref, "data-color-picker-view": value, ...props, className: cn('uikit-color-picker-view', className), "data-color-picker-part": "view", "data-grid-height": isGridHeight ? '' : undefined, children: children }));
318
+ });
273
319
  /**
274
320
  * A gradient's stops, across a channel's track (from where its knob's
275
321
  * center is at its least to where it is at its most), evenly.
276
322
  */
277
323
  const trackStops = (colors) => colors
278
- .map((stop, index) => `${stop} calc(20px + (100% - 40px) * ${String(index / Math.max(colors.length - 1, 1))})`)
324
+ .map((stop, index) => `${stop} calc(var(--uikit-color-picker-channel-size) / 2 + (100% - var(--uikit-color-picker-channel-size)) * ${String(index / Math.max(colors.length - 1, 1))})`)
279
325
  .join(', ');
280
326
  /**
281
327
  * A channel's row (the sliders', the opacity's): its title (all caps,
282
- * secondary), a slider (40px high, mixing from the color: its gradient
283
- * the color with the channel along its range; its knob 36px, in the color,
284
- * ringed white, 3px) and its value (a 75px by 40px field on the system
285
- * fill, 8px corners, Body emphasized: typed, committed on Enter or as it's
286
- * left).
328
+ * secondary), a slider (32px high, mixing from the color: its gradient
329
+ * the color with the channel along its range; its knob as high, in the
330
+ * color, ringed white, 3px) and its value (a 75px by 32px field on the system
331
+ * fill, 8px corners, Body emphasized: typed, applied as it's typed, within
332
+ * its range).
287
333
  */
334
+ /**
335
+ * A typed field's handlers (a channel's value, the code): focused, all of
336
+ * it selected (to type over); left (or Enter), `onLeave` (its value again,
337
+ * e.g. emptied) and its selection collapsed (kept, the next tap would be on
338
+ * selected text). The tap focusing it is on its text, selected: Chrome opens
339
+ * its context menu for that; not for this tap (a later press, held, opens
340
+ * it).
341
+ */
342
+ const useFieldSelection = (onLeave) => {
343
+ // Focused by a tap (until its click).
344
+ const focusingRef = useRef(false);
345
+ return {
346
+ onBlur: (event) => {
347
+ onLeave();
348
+ focusingRef.current = false;
349
+ const { length } = event.currentTarget.value;
350
+ event.currentTarget.setSelectionRange(length, length);
351
+ },
352
+ onClick: () => {
353
+ focusingRef.current = false;
354
+ },
355
+ onContextMenu: (event) => {
356
+ if (focusingRef.current)
357
+ event.preventDefault();
358
+ },
359
+ onFocus: (event) => {
360
+ focusingRef.current = true;
361
+ event.currentTarget.select();
362
+ },
363
+ onKeyDown: (event) => {
364
+ if (event.key === 'Enter')
365
+ onLeave();
366
+ },
367
+ };
368
+ };
288
369
  const ChannelRow = ({ fieldLabel, isCheckered = false, label, max, onValueChange, stops, thumbColor, unit, value, }) => {
289
370
  const [draft, setDraft] = useState(undefined);
371
+ const selection = useFieldSelection(() => setDraft(undefined));
290
372
  // Held, its touch doesn't scroll (see `useTouchHold`).
291
373
  const holdHandlers = useTouchHold('x');
292
- const commit = (event) => {
293
- if (draft === undefined)
374
+ // Typed: its digits (a whole number), within its range, applied at once;
375
+ // shown as applied (e.g. 300 as 255), or empty while it's typed over.
376
+ const type = (text, event) => {
377
+ const digits = text.replaceAll(/\D/gu, '');
378
+ if (digits === '') {
379
+ setDraft('');
294
380
  return;
295
- const next = Number.parseFloat(draft);
296
- if (Number.isFinite(next)) {
297
- onValueChange(clamp(Math.round(next), 0, max), event);
298
381
  }
299
- setDraft(undefined);
382
+ const next = clamp(Number.parseInt(digits, 10), 0, max);
383
+ setDraft(String(next));
384
+ onValueChange(next, event);
300
385
  };
301
386
  return (_jsxs(Viewport.KeyboardAccessory, { className: "uikit-color-picker-channel", "data-color-picker-part": "channel", gap: 20, children: [_jsx("div", { "aria-hidden": "true", className: "uikit-color-picker-channel-title", "data-color-picker-part": "channel-title", children: label }), _jsxs("div", { className: "uikit-color-picker-channel-row", "data-color-picker-part": "channel-row", children: [_jsx(BaseSlider.Root, { "aria-label": label, max: max, min: 0, style: { display: 'contents' }, thumbAlignment: "center", value: value, onValueChange: (next, { event }) => onValueChange(next, event), children: _jsx(BaseSlider.Control, { className: "uikit-color-picker-channel-control", "data-base-ui-swipe-ignore": "", "data-checkered": isCheckered ? '' : undefined, "data-color-picker-part": "channel-control",
302
387
  // (Its knob's place, for the hole in its gradient: the slider's
@@ -305,12 +390,10 @@ const ChannelRow = ({ fieldLabel, isCheckered = false, label, max, onValueChange
305
390
  '--uikit-color-picker-channel-position': value / max,
306
391
  '--uikit-color-picker-channel-stops': trackStops(stops),
307
392
  '--uikit-color-picker-channel-thumb': thumbColor,
308
- }, ...holdHandlers, children: _jsx(BaseSlider.Track, { children: _jsx(BaseSlider.Thumb, { className: "uikit-color-picker-channel-thumb", "data-color-picker-part": "channel-thumb" }) }) }) }), _jsxs("label", { className: "uikit-color-picker-channel-field", "data-color-picker-part": "channel-field", children: [_jsx("input", { "aria-label": fieldLabel ?? `${label} value`, inputMode: "numeric", value: draft ?? String(value), onBlur: (event) => commit(event), onChange: (event) => setDraft(event.currentTarget.value),
309
- // Focused, all of it (to type over).
310
- onFocus: (event) => event.currentTarget.select(), onKeyDown: (event) => {
311
- if (event.key === 'Enter')
312
- commit(event);
313
- } }), unit ? _jsx("span", { "aria-hidden": "true", children: unit }) : null] })] })] }));
393
+ }, ...holdHandlers, children: _jsx(BaseSlider.Track, { children: _jsx(BaseSlider.Thumb, { className: "uikit-color-picker-channel-thumb", "data-color-picker-part": "channel-thumb" }) }) }) }), _jsxs("label", { className: "uikit-color-picker-channel-field", "data-color-picker-part": "channel-field", children: [_jsx("input", { "aria-label": fieldLabel ?? `${label} value`, inputMode: "numeric", value: draft ?? String(value),
394
+ // (Left, or Enter: its value again, e.g. emptied; see
395
+ // `useFieldSelection`.)
396
+ onChange: (event) => type(event.currentTarget.value, event), ...selection }), unit ? _jsx("span", { "aria-hidden": "true", children: unit }) : null] })] })] }));
314
397
  };
315
398
  /** Hue (0–360°), saturation and lightness (0–100%). */
316
399
  const hsl = {
@@ -356,42 +439,80 @@ const rgb = {
356
439
  from: ({ b, g, r }) => [r, g, b].map((channel) => Math.round(channel)),
357
440
  to: ([r = 0, g = 0, b = 0]) => ({ b, g, r }),
358
441
  };
442
+ const rgbKeys = ['r', 'g', 'b'];
443
+ /**
444
+ * Red, green and blue in percent (0–100%): coarser than bytes, so a channel
445
+ * set leaves the others as they are (not as rounded, see `set`).
446
+ */
447
+ const rgbPercentage = {
448
+ channels: [
449
+ { label: 'Red', max: 100, unit: '%' },
450
+ { label: 'Green', max: 100, unit: '%' },
451
+ { label: 'Blue', max: 100, unit: '%' },
452
+ ],
453
+ from: ({ b, g, r }) => [r, g, b].map((channel) => Math.round((channel / 255) * 100)),
454
+ set: ({ b, g, r }, index, value) => ({
455
+ b,
456
+ g,
457
+ r,
458
+ [rgbKeys[index] ?? 'r']: (value * 255) / 100,
459
+ }),
460
+ to: ([r = 0, g = 0, b = 0]) => ({
461
+ b: (b * 255) / 100,
462
+ g: (g * 255) / 100,
463
+ r: (r * 255) / 100,
464
+ }),
465
+ };
359
466
  const models = { cmyk, hsl, rgb };
467
+ /** A model's color, one channel set (see `Model`'s `set`). */
468
+ const withChannel = (model, color, values, index, value) => model.set
469
+ ? model.set(color, index, value)
470
+ : model.to(values.with(index, value));
360
471
  /**
361
472
  * A channel's track's colors: the color with the channel along its range,
362
473
  * enough of them to be exact (linear between them): a hue around (every
363
474
  * 60°), a lightness through the pure hue (halfway), the others its ends.
364
475
  */
365
- const trackColors = (model, values, index) => {
476
+ const trackColors = (model, color, values, index) => {
366
477
  const { max } = model.channels[index] ?? { max: 1 };
367
478
  const steps = model === hsl ? ([6, 1, 2][index] ?? 1) : 1;
368
- return Array.from({ length: steps + 1 }, (_, step) => {
369
- const next = values.with(index, (max * step) / steps);
370
- return formatColor({ ...model.to(next), a: 1 });
371
- });
479
+ return Array.from({ length: steps + 1 }, (_, step) => formatColor({
480
+ ...withChannel(model, color, values, index, (max * step) / steps),
481
+ a: 1,
482
+ }));
372
483
  };
373
484
  /**
374
- * Sliders: a color model's channels (`model`: red, green and blue; hue,
375
- * saturation and lightness; cyan, magenta, yellow and black), each mixing
376
- * from the color, its value typed too.
485
+ * Sliders: a color model's channels (`model`: red, green and blue, in bytes
486
+ * or percent, its `range`; hue, saturation and lightness; cyan, magenta,
487
+ * yellow and black), each mixing from the color, its value typed too; then
488
+ * its children (e.g. the `Code`), spaced as the channels.
377
489
  */
378
- const Sliders = forwardRef(({ className, model: modelName = 'rgb', ...props }, ref) => {
490
+ const Sliders = forwardRef(({ children, className, model: modelName = 'rgb', range = 'byte', ...props }, ref) => {
379
491
  const { color, setColor } = useContext(PickerContext);
380
- const model = models[modelName];
492
+ const model = modelName === 'rgb' && range === 'percentage'
493
+ ? rgbPercentage
494
+ : models[modelName];
381
495
  const opaque = formatColor({ ...color, a: 1 });
382
- // Its values as last set, while they're the color's: so a hue isn't
383
- // lost to a gray (no saturation), nor inks to black (all of it).
496
+ // Its values as last set, while they're the color's (and its model's):
497
+ // so a hue isn't lost to a gray (no saturation), nor inks to black (all
498
+ // of it).
384
499
  const [last, setLast] = useState();
385
- const values = last?.color === opaque ? last.values : model.from(color);
386
- return (_jsx("div", { ref: ref, ...props, className: cn('uikit-color-picker-sliders', className), "data-color-picker-part": "sliders", "data-model": modelName, children: model.channels.map(({ label, max, unit }, index) => (_jsx(ChannelRow, { label: label, max: max, stops: trackColors(model, values, index), thumbColor: opaque, unit: unit, value: values[index] ?? 0, onValueChange: (next, event) => {
387
- const nextValues = values.with(index, next);
388
- const nextColor = { ...model.to(nextValues), a: color.a };
389
- setLast({
390
- color: formatColor({ ...nextColor, a: 1 }),
391
- values: nextValues,
392
- });
393
- setColor(nextColor, { event, reason: 'sliders' });
394
- } }, label))) }));
500
+ const values = last?.color === opaque && last.model === model
501
+ ? last.values
502
+ : model.from(color);
503
+ return (_jsxs("div", { ref: ref, ...props, className: cn('uikit-color-picker-sliders', className), "data-color-picker-part": "sliders", "data-model": modelName, "data-range": modelName === 'rgb' ? range : undefined, children: [model.channels.map(({ label, max, unit }, index) => (_jsx(ChannelRow, { label: label, max: max, stops: trackColors(model, color, values, index), thumbColor: opaque, unit: unit, value: values[index] ?? 0, onValueChange: (next, event) => {
504
+ const nextValues = values.with(index, next);
505
+ const nextColor = {
506
+ ...withChannel(model, color, values, index, next),
507
+ a: color.a,
508
+ };
509
+ setLast({
510
+ color: formatColor({ ...nextColor, a: 1 }),
511
+ model,
512
+ values: nextValues,
513
+ });
514
+ setColor(nextColor, { event, reason: 'sliders' });
515
+ } }, label))), children] }));
395
516
  });
396
517
  /**
397
518
  * The opacity: the color fading in over a checkerboard, in percent; 22px
@@ -415,7 +536,7 @@ const SavedSwatch = ({ hex, onDelete }) => {
415
536
  const { color, setColor } = useContext(PickerContext);
416
537
  const swatch = parseColor(hex);
417
538
  // Its menu (a secondary click: right click, or a long press): delete it.
418
- return (_jsxs(Menu.Root, { children: [_jsx(Menu.Trigger, { openOn: "secondaryClick", render: _jsx("button", { "aria-label": hex, "aria-pressed": sameColor(swatch, color) && swatch.a === color.a, style: { backgroundColor: hex }, type: "button", onClick: (event) => setColor(swatch, { event, reason: 'saved' }) }) }), _jsx(Menu.Portal, { children: _jsx(Menu.Positioner, { children: _jsx(Menu.Popup, { children: _jsx(Menu.Item, { destructive: true, onClick: (event) => onDelete(event), children: _jsx(Menu.Label, { children: "Delete" }) }) }) }) })] }));
539
+ return (_jsxs(Menu.Root, { children: [_jsx(Menu.Trigger, { openOn: "secondaryClick", render: _jsx("button", { "aria-label": hex, "aria-pressed": sameColor(swatch, color) && swatch.a === color.a, style: { '--uikit-color-picker-color': hex }, type: "button", onClick: (event) => setColor(swatch, { event, reason: 'saved' }) }) }), _jsx(Menu.Portal, { children: _jsx(Menu.Positioner, { children: _jsx(Menu.Popup, { children: _jsx(Menu.Item, { destructive: true, onClick: (event) => onDelete(event), children: _jsx(Menu.Label, { children: "Delete" }) }) }) }) })] }));
419
540
  };
420
541
  /**
421
542
  * The color (82px, 18px corners; translucent, over black and white) beside
@@ -490,10 +611,6 @@ const Swatches = forwardRef(({ className, defaultSavedColors: initialSaved = def
490
611
  goTo(Math.floor(saved.length / pageSize));
491
612
  }, children: "+" }, "add")) : (_jsx(SavedSwatch, { hex: hex, onDelete: (event) => changeSaved(saved.filter((other) => other !== hex), { event, reason: 'delete' }) }, hex))) }, index))) }), pages > 1 ? (_jsx(PageControl, { count: pages, value: shownPage, variant: "plain", onValueChange: goTo })) : null] })] }));
492
613
  });
493
- // Its header (in the panel's popover: 16px from its top, 10px above the
494
- // panel): the app's (e.g. a `Toolbar`: eyedropper, title,
495
- // close); in a sheet, its `Sheet.Header` instead.
496
- const Header = forwardRef(({ className, ...props }, ref) => (_jsx("div", { ref: ref, className: cn('uikit-color-picker-header', className), "data-color-picker-part": "header", ...props })));
497
614
  /** The browser's eyedropper (`EyeDropper`), if it has one. */
498
615
  const eyeDropper = () => globalThis.EyeDropper;
499
616
  /**
@@ -518,11 +635,261 @@ const Eyedropper = ({ render, ...props }) => {
518
635
  onClick: pick,
519
636
  })) : (_jsx(Button.Root, { "aria-label": "Eyedropper", ...props, onClick: pick }));
520
637
  };
638
+ /** Whether the browser has a color input (its picker the system's). */
639
+ const hasColorInput = () => {
640
+ if (typeof document === 'undefined')
641
+ return false;
642
+ const input = document.createElement('input');
643
+ input.type = 'color';
644
+ return input.type === 'color';
645
+ };
646
+ /**
647
+ * Whether its color input has an alpha (its `alpha` attribute: e.g.
648
+ * Safari's; without, a value with one is invalid, black).
649
+ */
650
+ const hasColorInputAlpha = () => typeof HTMLInputElement !== 'undefined' &&
651
+ 'alpha' in HTMLInputElement.prototype;
652
+ /**
653
+ * A color input's `alpha` (its picker's opacity), as a property: too new for
654
+ * the JSX types, and React renders no attribute it doesn't know as `true`.
655
+ */
656
+ const setAlpha = (input, hasAlpha) => {
657
+ if (input)
658
+ input.alpha = hasAlpha;
659
+ };
660
+ /**
661
+ * Its system colors (a leading button, after the eyedropper): a `Button`
662
+ * (or what it renders), opening the system's color picker: a color input's
663
+ * (none without one), over the button, transparent: pressed itself (on iOS,
664
+ * nothing else opens it: neither `showPicker` nor a click, see WebKit's bug
665
+ * 261703), the button showing the press; the button clicking it from the
666
+ * keyboard. With the opacity rendered, its alpha too, where the input has
667
+ * one (its `alpha`: e.g. Safari); else its colors opaque, the opacity kept.
668
+ */
669
+ const SystemColors = ({ render, ...props }) => {
670
+ const { color, hasOpacity, setColor } = useContext(PickerContext);
671
+ // (Its input, as rendered: for its button's press.)
672
+ const [input, setInput] = useState(null);
673
+ // (With the opacity, the input's alpha too, where it has one.)
674
+ const hasAlpha = hasOpacity && hasColorInputAlpha();
675
+ useLayoutEffect(() => setAlpha(input, hasAlpha), [hasAlpha, input]);
676
+ if (!hasColorInput())
677
+ return null;
678
+ const open = () => input?.click();
679
+ return (_jsxs("span", { className: "uikit-color-picker-system-colors", "data-color-picker-part": "system-colors", children: [render ? (cloneElement(render, {
680
+ 'aria-label': 'System colors',
681
+ ...props,
682
+ onClick: open,
683
+ })) : (_jsx(Button.Root, { "aria-label": "System colors", ...props, onClick: open })), _jsx("input", { ref: setInput, "aria-hidden": "true", className: "uikit-color-picker-system-colors-input", disabled: props.disabled, tabIndex: -1, type: "color",
684
+ // (The color, as it is: its picker opened from it.)
685
+ value: formatColor(hasAlpha ? color : { ...color, a: 1 }).toLowerCase(),
686
+ // (As it's picked, live; without its alpha, the opacity kept.)
687
+ onChange: (event) => {
688
+ // (Any CSS color, with an alpha: see color.ts.)
689
+ const picked = parseCssColor(event.currentTarget.value);
690
+ if (!picked)
691
+ return;
692
+ setColor(hasAlpha ? picked : { ...picked, a: color.a }, {
693
+ event,
694
+ reason: 'system-colors',
695
+ });
696
+ } })] }));
697
+ };
698
+ /** A field without spell checking (its `spellcheck` property). */
699
+ const noSpellcheck = (input) => {
700
+ if (input)
701
+ input.spellcheck = false;
702
+ };
703
+ /**
704
+ * Its code (a row; its place the app's: e.g. under the sliders), as high as a
705
+ * channel's, its field where a channel's value is: “Hex” (a channel's title,
706
+ * beside them, centered), then its children (e.g. a `CodeCopy`), the color's
707
+ * hex code typed (`#` before it, not typed: its digits, applied as they make
708
+ * a code, 3, 4, 6 or 8 of them; with an alpha, 4 or 8), at its end. Kept above the keyboard as it's typed into (as a
709
+ * channel's row).
710
+ */
711
+ const Code = forwardRef(({ children, className, ...props }, ref) => {
712
+ const { color, setColor } = useContext(PickerContext);
713
+ const [draft, setDraft] = useState(undefined);
714
+ const selection = useFieldSelection(() => setDraft(undefined));
715
+ const type = (text, event) => {
716
+ const digits = text
717
+ .replaceAll(/[^\da-f]/giu, '')
718
+ .slice(0, 8)
719
+ .toUpperCase();
720
+ setDraft(digits);
721
+ if (![3, 4, 6, 8].includes(digits.length))
722
+ return;
723
+ const typed = parseColor(`#${digits}`);
724
+ // (Without an alpha typed, the color's kept.)
725
+ setColor(digits.length % 4 === 0 ? typed : { ...typed, a: color.a }, {
726
+ event,
727
+ reason: 'code',
728
+ });
729
+ };
730
+ return (_jsx(Viewport.KeyboardAccessory, { ref: ref, gap: 20, ...props, className: cn('uikit-color-picker-code', className), "data-color-picker-part": "code", children: _jsxs("div", { className: "uikit-color-picker-channel-row uikit-color-picker-code-row", "data-color-picker-part": "code-row", children: [_jsx("div", { "aria-hidden": "true", className: "uikit-color-picker-channel-title", "data-color-picker-part": "code-title", children: "Hex" }), children, _jsxs("label", { className: "uikit-color-picker-channel-field uikit-color-picker-code-field", "data-color-picker-part": "code-field", children: [_jsx("span", { "aria-hidden": "true", children: "#" }), _jsx("input", {
731
+ // (As a property: spelled differently in React's and Preact's
732
+ // JSX.)
733
+ ref: noSpellcheck, value: draft ?? formatColor(color).slice(1), onChange: (event) => type(event.currentTarget.value, event), ...selection })] })] }) }));
734
+ });
521
735
  /** A color well: its color, opening the picker. */
522
736
  const Well = forwardRef(({ className, color, size = 'small', style, ...props }, ref) => (_jsx("button", { ref: ref, "aria-label": "Color", "data-color": color === undefined ? undefined : '', "data-size": size, style: withStyle({ '--uikit-color-picker-well-color': color }, style), type: "button", ...props, className: cn('uikit-color-picker-well', className), "data-color-picker-part": "well" })));
737
+ // How long a copy shows as done (its checkmark).
738
+ const copiedFor = 1500;
739
+ /**
740
+ * Its code's copy button: a `Button` (or what it renders, its content the
741
+ * app's: e.g. a symbol), opening a menu of the color's codes (see color.ts):
742
+ * hex's, then a submenu each of the others' groups, each code its format and
743
+ * its values (`Menu.Label`, `Menu.Subtitle`). One picked, copied to the
744
+ * clipboard (`onCodeCopy`); for a moment, a checkmark instead of its content
745
+ * (`data-copied`). Its place the app's (in a `Code`, or not).
746
+ */
747
+ const CodeCopy = ({ children, onCodeCopy, render, ...props }) => {
748
+ const { color } = useContext(PickerContext);
749
+ const [isCopied, setIsCopied] = useState(false);
750
+ useEffect(() => {
751
+ if (!isCopied)
752
+ return undefined;
753
+ const timeout = setTimeout(() => setIsCopied(false), copiedFor);
754
+ return () => clearTimeout(timeout);
755
+ }, [isCopied]);
756
+ const copy = (code, event) => {
757
+ navigator.clipboard
758
+ .writeText(code)
759
+ .then(() => {
760
+ setIsCopied(true);
761
+ onCodeCopy?.(code, event);
762
+ })
763
+ .catch(() => undefined);
764
+ };
765
+ // (Hex's: its color in a well at its end, inert.)
766
+ const item = ({ code, label, subtitle, well }) => (_jsxs(Menu.Item, { onClick: (event) => copy(code, event), children: [_jsx(Menu.Label, { children: label }), _jsx(Menu.Subtitle, { children: subtitle }), well === undefined ? null : (_jsx(Well, { inert: true, "aria-hidden": "true", className: "uikit-color-picker-code-copy-well", color: well, tabIndex: -1 }))] }, code));
767
+ const content = isCopied ? (_jsx(Button.Icon, { children: _jsx(Checkmark, {}) })) : (children);
768
+ const trigger = render ? (cloneElement(render, {
769
+ 'aria-label': 'Copy color code',
770
+ ...props,
771
+ 'data-copied': isCopied ? '' : undefined,
772
+ }, content)) : (_jsx(Button.Root, { "aria-label": "Copy color code", ...props, "data-copied": isCopied ? '' : undefined, children: content }));
773
+ return (_jsxs(Menu.Root, { children: [_jsx(Menu.Trigger, { render: trigger }), _jsx(Menu.Portal, { children: _jsx(Menu.Positioner, { children: _jsx(Menu.Popup, { children: codeGroups(color, formatColor({ ...color, a: 1 })).map(([title, codes], index) => index === 0 ? (_jsx(Fragment, { children: codes.map((entry) => item(entry)) }, title)) : (_jsxs(Menu.SubmenuRoot, { children: [_jsx(Menu.SubmenuTrigger, { children: _jsx(Menu.Label, { children: title }) }), _jsx(Menu.Portal, { children: _jsx(Menu.Positioner, { children: _jsx(Menu.Popup, { children: codes.map((entry) => item(entry)) }) }) })] }, title))) }) }) })] }));
774
+ };
775
+ /**
776
+ * Its named colors' rows (see `Named`): one registered (its label's first
777
+ * letter, for the index), while mounted.
778
+ */
779
+ const NamedContext = createContext(() => unregister);
780
+ /** The scroll container `element` is in (its block axis), or the page. */
781
+ const scrollerOf = (element) => {
782
+ for (let parent = element.parentElement; parent && parent !== document.body; parent = parent.parentElement) {
783
+ const { overflowY } = getComputedStyle(parent);
784
+ if (overflowY === 'auto' || overflowY === 'scroll')
785
+ return parent;
786
+ }
787
+ return document.scrollingElement ?? document.documentElement;
788
+ };
789
+ /** A row at the top of its scroll container (below its scroll padding). */
790
+ const jumpTo = (element) => {
791
+ const scroller = scrollerOf(element);
792
+ const padding = Number.parseFloat(getComputedStyle(scroller).scrollPaddingBlockStart) || 0;
793
+ const top = scroller === document.scrollingElement
794
+ ? 0
795
+ : scroller.getBoundingClientRect().top;
796
+ scroller.scrollTo({
797
+ top: scroller.scrollTop + element.getBoundingClientRect().top - top - padding,
798
+ });
799
+ };
800
+ /**
801
+ * A row in view (between its scroll container's scroll paddings: e.g. a
802
+ * sheet's header), at once: already, it stays; else, centered there.
803
+ */
804
+ const revealCentered = (element) => {
805
+ const scroller = scrollerOf(element);
806
+ const style = getComputedStyle(scroller);
807
+ const paddingStart = Number.parseFloat(style.scrollPaddingBlockStart) || 0;
808
+ const paddingEnd = Number.parseFloat(style.scrollPaddingBlockEnd) || 0;
809
+ const scrollerTop = scroller === document.scrollingElement
810
+ ? 0
811
+ : scroller.getBoundingClientRect().top;
812
+ const { bottom, height, top } = element.getBoundingClientRect();
813
+ const viewStart = scrollerTop + paddingStart;
814
+ const viewHeight = scroller.clientHeight - paddingStart - paddingEnd;
815
+ if (top >= viewStart && bottom <= viewStart + viewHeight)
816
+ return;
817
+ scroller.scrollTo({
818
+ behavior: 'instant',
819
+ top: scroller.scrollTop + top - viewStart - (viewHeight - height) / 2,
820
+ });
821
+ };
822
+ /**
823
+ * Its named colors (a mode's content, e.g. “Named”): one list of their rows
824
+ * (`NamedColor`s: e.g. the app's, `CssNamedColors`'), as high as they are
825
+ * (scrolled by its container: e.g. a sheet's content, a popover's body). At
826
+ * its end (in its panel's inset), an index of their labels' first letters,
827
+ * kept centered in view as it's scrolled; one picked, the first row with it
828
+ * at the top (below the container's scroll padding: e.g. a sheet's header).
829
+ * Shown, the color's row in view at once (see `revealCentered`).
830
+ */
831
+ const Named = forwardRef(({ children, className, ...props }, forwardedRef) => {
832
+ const ref = useForwardedRef(forwardedRef);
833
+ // Shown (e.g. its mode chosen): the color's row in view, at once.
834
+ useLayoutEffect(() => {
835
+ const picked = ref.current?.querySelector('[data-color-picker-part="named-color"][data-picked]');
836
+ if (picked)
837
+ revealCentered(picked);
838
+ }, [ref]);
839
+ const [entries, setEntries] = useState([]);
840
+ const register = useCallback((entry) => {
841
+ // (In the document's order; rows apart, neither in the other: only
842
+ // following, or not.)
843
+ setEntries((current) => [...current, entry].toSorted((a, b) => a.element.compareDocumentPosition(b.element) ===
844
+ Node.DOCUMENT_POSITION_FOLLOWING
845
+ ? -1
846
+ : 1));
847
+ return () => setEntries((current) => current.filter((other) => other !== entry));
848
+ }, []);
849
+ // Each letter's first row.
850
+ const letters = useMemo(() => {
851
+ const first = new Map();
852
+ for (const { element, label } of entries) {
853
+ if (!first.has(label))
854
+ first.set(label, element);
855
+ }
856
+ return [...first];
857
+ }, [entries]);
858
+ return (_jsx(NamedContext.Provider, { value: register, children: _jsxs("div", { ref: ref, ...props, className: cn('uikit-color-picker-named', className), "data-color-picker-part": "named", children: [_jsx(List.Root, { listStyle: "insetGrouped", children: _jsx(List.Section, { children: _jsx(List.Group, { children: children }) }) }), letters.length > 0 ? (_jsx("div", { className: "uikit-color-picker-named-index", "data-color-picker-part": "named-index", children: _jsx(List.Index, { "aria-label": "Index", children: letters.map(([letter, element]) => (_jsx(List.IndexItem, { onClick: () => jumpTo(element), children: letter }, letter))) }) })) : null] }) }));
859
+ });
860
+ /**
861
+ * A named color's row (in a `Named`): its color in a well (inert), its label
862
+ * (or its color), a checkmark while it's the color (its opacity aside); its
863
+ * label's first letter in the index. Pressed, the color (its opacity kept,
864
+ * as a grid swatch's).
865
+ */
866
+ const NamedColor = forwardRef(({ children, color: cssColor, ...props }, forwardedRef) => {
867
+ const { color, setColor } = useContext(PickerContext);
868
+ const register = useContext(NamedContext);
869
+ const ref = useForwardedRef(forwardedRef);
870
+ const named = useMemo(() => parseCssColor(cssColor), [cssColor]);
871
+ const isPicked = named !== undefined && sameColor(named, color);
872
+ const letter = (typeof children === 'string' ? children : cssColor)
873
+ .charAt(0)
874
+ .toUpperCase();
875
+ useLayoutEffect(() => {
876
+ const { current: element } = ref;
877
+ return element ? register({ element, label: letter }) : undefined;
878
+ }, [letter, ref, register]);
879
+ return (_jsxs(List.Item, { ref: ref, ...props, "data-color-picker-part": "named-color", "data-picked": isPicked ? '' : undefined, children: [_jsx(List.Leading, { children: _jsx(Well, { inert: true, "aria-hidden": "true", color: cssColor, tabIndex: -1 }) }), _jsx(List.Content, { children: _jsx(List.Title, { "aria-pressed": isPicked, render: _jsx("button", { type: "button" }), onClick: (event) => {
880
+ if (!named)
881
+ return;
882
+ setColor({ ...named, a: color.a }, { event, reason: 'named' });
883
+ }, children: children ?? cssColor }) }), _jsx(List.Trailing, { children: isPicked ? _jsx(List.Checkmark, {}) : null })] }));
884
+ });
885
+ /**
886
+ * The CSS named colors (148, synonyms too: e.g. gray and grey; not
887
+ * `transparent`; see named-colors.ts), as a `Named`'s rows, labeled by their
888
+ * names.
889
+ */
890
+ const CssNamedColors = () => (_jsx(_Fragment, { children: cssNamedColors.map((name) => (_jsx(NamedColor, { color: name }, name))) }));
523
891
  export const ColorPicker = {
524
892
  Root,
525
- Header,
526
893
  Panel,
527
894
  Modes,
528
895
  Mode,
@@ -533,6 +900,12 @@ export const ColorPicker = {
533
900
  Opacity,
534
901
  Swatches,
535
902
  Eyedropper,
903
+ SystemColors,
904
+ Code,
905
+ CodeCopy,
906
+ Named,
907
+ NamedColor,
908
+ CssNamedColors,
536
909
  Well,
537
910
  };
538
911
  //# sourceMappingURL=main.js.map