@mrpelz/uikit-ish 7.13.0 → 7.26.2

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 (276) hide show
  1. package/dist/components/accordion/style.css +1 -1
  2. package/dist/components/action-sheet/main.d.ts.map +1 -1
  3. package/dist/components/action-sheet/main.js +9 -6
  4. package/dist/components/action-sheet/main.js.map +1 -1
  5. package/dist/components/action-sheet/props.d.ts +2 -1
  6. package/dist/components/action-sheet/props.d.ts.map +1 -1
  7. package/dist/components/alert/main.d.ts.map +1 -1
  8. package/dist/components/alert/main.js +12 -4
  9. package/dist/components/alert/main.js.map +1 -1
  10. package/dist/components/alert/props.d.ts +2 -1
  11. package/dist/components/alert/props.d.ts.map +1 -1
  12. package/dist/components/alert/style.css +27 -5
  13. package/dist/components/button/main.js +1 -1
  14. package/dist/components/button/main.js.map +1 -1
  15. package/dist/components/button/props.d.ts +3 -2
  16. package/dist/components/button/props.d.ts.map +1 -1
  17. package/dist/components/button/style.css +6 -17
  18. package/dist/components/card/main.d.ts +53 -0
  19. package/dist/components/card/main.d.ts.map +1 -0
  20. package/dist/components/card/main.js +286 -0
  21. package/dist/components/card/main.js.map +1 -0
  22. package/dist/components/card/props.d.ts +83 -0
  23. package/dist/components/card/props.d.ts.map +1 -0
  24. package/dist/components/card/props.js +2 -0
  25. package/dist/components/card/props.js.map +1 -0
  26. package/dist/components/card/style.css +900 -0
  27. package/dist/components/collapsible/style.css +1 -1
  28. package/dist/components/color-picker/main.d.ts.map +1 -1
  29. package/dist/components/color-picker/main.js +20 -33
  30. package/dist/components/color-picker/main.js.map +1 -1
  31. package/dist/components/color-picker/style.css +4 -23
  32. package/dist/components/contextual-menu/main.d.ts +6 -2
  33. package/dist/components/contextual-menu/main.d.ts.map +1 -1
  34. package/dist/components/contextual-menu/main.js +67 -43
  35. package/dist/components/contextual-menu/main.js.map +1 -1
  36. package/dist/components/contextual-menu/props.d.ts +2 -1
  37. package/dist/components/contextual-menu/props.d.ts.map +1 -1
  38. package/dist/components/contextual-menu/style.css +64 -2
  39. package/dist/components/control-cards/main.d.ts +49 -0
  40. package/dist/components/control-cards/main.d.ts.map +1 -0
  41. package/dist/components/control-cards/main.js +835 -0
  42. package/dist/components/control-cards/main.js.map +1 -0
  43. package/dist/components/control-cards/props.d.ts +409 -0
  44. package/dist/components/control-cards/props.d.ts.map +1 -0
  45. package/dist/components/control-cards/props.js +2 -0
  46. package/dist/components/control-cards/props.js.map +1 -0
  47. package/dist/components/control-cards/style.css +492 -0
  48. package/dist/components/date-picker/main.d.ts.map +1 -1
  49. package/dist/components/date-picker/main.js +7 -3
  50. package/dist/components/date-picker/main.js.map +1 -1
  51. package/dist/components/date-picker/style.css +1 -1
  52. package/dist/components/drawer/style.css +6 -0
  53. package/dist/components/edit-menu/main.d.ts +2 -1
  54. package/dist/components/edit-menu/main.d.ts.map +1 -1
  55. package/dist/components/edit-menu/main.js +8 -4
  56. package/dist/components/edit-menu/main.js.map +1 -1
  57. package/dist/components/glass/backdrop.d.ts +75 -0
  58. package/dist/components/glass/backdrop.d.ts.map +1 -0
  59. package/dist/components/glass/backdrop.js +608 -0
  60. package/dist/components/glass/backdrop.js.map +1 -0
  61. package/dist/components/glass/gradient.d.ts +17 -0
  62. package/dist/components/glass/gradient.d.ts.map +1 -0
  63. package/dist/components/glass/gradient.js +233 -0
  64. package/dist/components/glass/gradient.js.map +1 -0
  65. package/dist/components/glass/main.d.ts +60 -6
  66. package/dist/components/glass/main.d.ts.map +1 -1
  67. package/dist/components/glass/main.js +100 -122
  68. package/dist/components/glass/main.js.map +1 -1
  69. package/dist/components/glass/marker.d.ts +66 -0
  70. package/dist/components/glass/marker.d.ts.map +1 -0
  71. package/dist/components/glass/marker.js +268 -0
  72. package/dist/components/glass/marker.js.map +1 -0
  73. package/dist/components/glass/props.d.ts +33 -7
  74. package/dist/components/glass/props.d.ts.map +1 -1
  75. package/dist/components/glass/style.css +139 -75
  76. package/dist/components/grid/dashes.d.ts +15 -0
  77. package/dist/components/grid/dashes.d.ts.map +1 -0
  78. package/dist/components/grid/dashes.js +37 -0
  79. package/dist/components/grid/dashes.js.map +1 -0
  80. package/dist/components/grid/edit.d.ts +11 -0
  81. package/dist/components/grid/edit.d.ts.map +1 -0
  82. package/dist/components/grid/edit.js +1066 -0
  83. package/dist/components/grid/edit.js.map +1 -0
  84. package/dist/components/grid/handle.d.ts +123 -0
  85. package/dist/components/grid/handle.d.ts.map +1 -0
  86. package/dist/components/grid/handle.js +194 -0
  87. package/dist/components/grid/handle.js.map +1 -0
  88. package/dist/components/grid/icons.d.ts +40 -0
  89. package/dist/components/grid/icons.d.ts.map +1 -0
  90. package/dist/components/grid/icons.js +140 -0
  91. package/dist/components/grid/icons.js.map +1 -0
  92. package/dist/components/grid/layout.d.ts +111 -0
  93. package/dist/components/grid/layout.d.ts.map +1 -0
  94. package/dist/components/grid/layout.js +1257 -0
  95. package/dist/components/grid/layout.js.map +1 -0
  96. package/dist/components/grid/main.d.ts +63 -0
  97. package/dist/components/grid/main.d.ts.map +1 -0
  98. package/dist/components/grid/main.js +1894 -0
  99. package/dist/components/grid/main.js.map +1 -0
  100. package/dist/components/grid/overlay.d.ts +24 -0
  101. package/dist/components/grid/overlay.d.ts.map +1 -0
  102. package/dist/components/grid/overlay.js +312 -0
  103. package/dist/components/grid/overlay.js.map +1 -0
  104. package/dist/components/grid/plan.d.ts +78 -0
  105. package/dist/components/grid/plan.d.ts.map +1 -0
  106. package/dist/components/grid/plan.js +249 -0
  107. package/dist/components/grid/plan.js.map +1 -0
  108. package/dist/components/grid/props.d.ts +509 -0
  109. package/dist/components/grid/props.d.ts.map +1 -0
  110. package/dist/components/grid/props.js +2 -0
  111. package/dist/components/grid/props.js.map +1 -0
  112. package/dist/components/grid/reshape.d.ts +60 -0
  113. package/dist/components/grid/reshape.d.ts.map +1 -0
  114. package/dist/components/grid/reshape.js +214 -0
  115. package/dist/components/grid/reshape.js.map +1 -0
  116. package/dist/components/grid/style.css +1293 -0
  117. package/dist/components/header/main.d.ts.map +1 -1
  118. package/dist/components/header/main.js +97 -10
  119. package/dist/components/header/main.js.map +1 -1
  120. package/dist/components/header/props.d.ts +2 -2
  121. package/dist/components/header/props.d.ts.map +1 -1
  122. package/dist/components/header/style.css +28 -43
  123. package/dist/components/index.d.ts +10 -6
  124. package/dist/components/index.d.ts.map +1 -1
  125. package/dist/components/index.js +5 -1
  126. package/dist/components/index.js.map +1 -1
  127. package/dist/components/island/main.d.ts +2 -2
  128. package/dist/components/island/main.d.ts.map +1 -1
  129. package/dist/components/island/main.js +193 -41
  130. package/dist/components/island/main.js.map +1 -1
  131. package/dist/components/island/props.d.ts +4 -2
  132. package/dist/components/island/props.d.ts.map +1 -1
  133. package/dist/components/island/style.css +50 -3
  134. package/dist/components/layout/main.d.ts +3 -6
  135. package/dist/components/layout/main.d.ts.map +1 -1
  136. package/dist/components/layout/main.js +225 -56
  137. package/dist/components/layout/main.js.map +1 -1
  138. package/dist/components/layout/props.d.ts +43 -2
  139. package/dist/components/layout/props.d.ts.map +1 -1
  140. package/dist/components/layout/style.css +84 -23
  141. package/dist/components/list/main.d.ts +3 -3
  142. package/dist/components/list/main.d.ts.map +1 -1
  143. package/dist/components/list/main.js +96 -20
  144. package/dist/components/list/main.js.map +1 -1
  145. package/dist/components/list/props.d.ts +20 -0
  146. package/dist/components/list/props.d.ts.map +1 -1
  147. package/dist/components/list/reorder.d.ts +16 -2
  148. package/dist/components/list/reorder.d.ts.map +1 -1
  149. package/dist/components/list/reorder.js.map +1 -1
  150. package/dist/components/list/style.css +61 -4
  151. package/dist/components/menu/main.d.ts +9 -5
  152. package/dist/components/menu/main.d.ts.map +1 -1
  153. package/dist/components/menu/main.js +87 -9
  154. package/dist/components/menu/main.js.map +1 -1
  155. package/dist/components/menu/props.d.ts +14 -0
  156. package/dist/components/menu/props.d.ts.map +1 -1
  157. package/dist/components/menu/style.css +3 -1
  158. package/dist/components/page/main.d.ts.map +1 -1
  159. package/dist/components/page/main.js +6 -3
  160. package/dist/components/page/main.js.map +1 -1
  161. package/dist/components/page/props.d.ts +3 -2
  162. package/dist/components/page/props.d.ts.map +1 -1
  163. package/dist/components/page/style.css +8 -4
  164. package/dist/components/page-control/props.d.ts +3 -3
  165. package/dist/components/popover/main.d.ts +10 -4
  166. package/dist/components/popover/main.d.ts.map +1 -1
  167. package/dist/components/popover/main.js +30 -19
  168. package/dist/components/popover/main.js.map +1 -1
  169. package/dist/components/popover/props.d.ts +2 -0
  170. package/dist/components/popover/props.d.ts.map +1 -1
  171. package/dist/components/popover/style.css +6 -2
  172. package/dist/components/progress/style.css +2 -2
  173. package/dist/components/roll/main.d.ts.map +1 -1
  174. package/dist/components/roll/main.js +5 -3
  175. package/dist/components/roll/main.js.map +1 -1
  176. package/dist/components/segmented/main.d.ts.map +1 -1
  177. package/dist/components/segmented/main.js +4 -4
  178. package/dist/components/segmented/main.js.map +1 -1
  179. package/dist/components/segmented/props.d.ts +5 -2
  180. package/dist/components/segmented/props.d.ts.map +1 -1
  181. package/dist/components/segmented/style.css +1 -1
  182. package/dist/components/settings/main.d.ts +13 -0
  183. package/dist/components/settings/main.d.ts.map +1 -1
  184. package/dist/components/settings/main.js +16 -0
  185. package/dist/components/settings/main.js.map +1 -1
  186. package/dist/components/settings/props.d.ts +1 -0
  187. package/dist/components/settings/props.d.ts.map +1 -1
  188. package/dist/components/sheet/main.d.ts.map +1 -1
  189. package/dist/components/sheet/main.js +156 -45
  190. package/dist/components/sheet/main.js.map +1 -1
  191. package/dist/components/sheet/props.d.ts +4 -2
  192. package/dist/components/sheet/props.d.ts.map +1 -1
  193. package/dist/components/sheet/snap.d.ts +54 -0
  194. package/dist/components/sheet/snap.d.ts.map +1 -1
  195. package/dist/components/sheet/snap.js +253 -23
  196. package/dist/components/sheet/snap.js.map +1 -1
  197. package/dist/components/sheet/style.css +126 -20
  198. package/dist/components/sidebar/main.d.ts +2 -1
  199. package/dist/components/sidebar/main.d.ts.map +1 -1
  200. package/dist/components/sidebar/main.js +18 -6
  201. package/dist/components/sidebar/main.js.map +1 -1
  202. package/dist/components/sidebar/props.d.ts +2 -1
  203. package/dist/components/sidebar/props.d.ts.map +1 -1
  204. package/dist/components/sidebar/style.css +78 -0
  205. package/dist/components/slider/main.d.ts.map +1 -1
  206. package/dist/components/slider/main.js +51 -9
  207. package/dist/components/slider/main.js.map +1 -1
  208. package/dist/components/slider/props.d.ts +1 -0
  209. package/dist/components/slider/props.d.ts.map +1 -1
  210. package/dist/components/slider/style.css +9 -0
  211. package/dist/components/switch/main.d.ts.map +1 -1
  212. package/dist/components/switch/main.js +4 -2
  213. package/dist/components/switch/main.js.map +1 -1
  214. package/dist/components/symbol/main.d.ts.map +1 -1
  215. package/dist/components/symbol/main.js +5 -1
  216. package/dist/components/symbol/main.js.map +1 -1
  217. package/dist/components/symbol/props.d.ts +10 -0
  218. package/dist/components/symbol/props.d.ts.map +1 -1
  219. package/dist/components/symbol/style.css +21 -3
  220. package/dist/components/tab-bar/main.d.ts.map +1 -1
  221. package/dist/components/tab-bar/main.js +8 -5
  222. package/dist/components/tab-bar/main.js.map +1 -1
  223. package/dist/components/tab-bar/props.d.ts +16 -12
  224. package/dist/components/tab-bar/props.d.ts.map +1 -1
  225. package/dist/components/tab-bar/style.css +3 -9
  226. package/dist/components/text-field/main.d.ts.map +1 -1
  227. package/dist/components/text-field/main.js +6 -3
  228. package/dist/components/text-field/main.js.map +1 -1
  229. package/dist/components/text-field/style.css +1 -1
  230. package/dist/components/toolbar/main.js +1 -1
  231. package/dist/components/toolbar/main.js.map +1 -1
  232. package/dist/components/toolbar/props.d.ts +3 -3
  233. package/dist/components/toolbar/style.css +1 -1
  234. package/dist/components/tooltip/main.d.ts +6 -1
  235. package/dist/components/tooltip/main.d.ts.map +1 -1
  236. package/dist/components/tooltip/main.js +13 -7
  237. package/dist/components/tooltip/main.js.map +1 -1
  238. package/dist/components/utils/main.d.ts +31 -2
  239. package/dist/components/utils/main.d.ts.map +1 -1
  240. package/dist/components/utils/main.js +60 -3
  241. package/dist/components/utils/main.js.map +1 -1
  242. package/dist/components/viewport/current.d.ts +15 -0
  243. package/dist/components/viewport/current.d.ts.map +1 -0
  244. package/dist/components/viewport/current.js +74 -0
  245. package/dist/components/viewport/current.js.map +1 -0
  246. package/dist/components/viewport/edge-effect.d.ts.map +1 -1
  247. package/dist/components/viewport/edge-effect.js +52 -24
  248. package/dist/components/viewport/edge-effect.js.map +1 -1
  249. package/dist/components/viewport/edge.d.ts +7 -4
  250. package/dist/components/viewport/edge.d.ts.map +1 -1
  251. package/dist/components/viewport/edge.js +21 -7
  252. package/dist/components/viewport/edge.js.map +1 -1
  253. package/dist/components/viewport/focus-scroll.d.ts +21 -0
  254. package/dist/components/viewport/focus-scroll.d.ts.map +1 -0
  255. package/dist/components/viewport/focus-scroll.js +272 -0
  256. package/dist/components/viewport/focus-scroll.js.map +1 -0
  257. package/dist/components/viewport/input.d.ts +39 -1
  258. package/dist/components/viewport/input.d.ts.map +1 -1
  259. package/dist/components/viewport/input.js +122 -13
  260. package/dist/components/viewport/input.js.map +1 -1
  261. package/dist/components/viewport/main.d.ts +16 -1
  262. package/dist/components/viewport/main.d.ts.map +1 -1
  263. package/dist/components/viewport/main.js +243 -49
  264. package/dist/components/viewport/main.js.map +1 -1
  265. package/dist/components/viewport/padding.d.ts +1 -1
  266. package/dist/components/viewport/padding.d.ts.map +1 -1
  267. package/dist/components/viewport/padding.js +2 -2
  268. package/dist/components/viewport/props.d.ts +12 -2
  269. package/dist/components/viewport/props.d.ts.map +1 -1
  270. package/dist/components/viewport/status-bar.d.ts +9 -0
  271. package/dist/components/viewport/status-bar.d.ts.map +1 -0
  272. package/dist/components/viewport/status-bar.js +131 -0
  273. package/dist/components/viewport/status-bar.js.map +1 -0
  274. package/dist/components/viewport/style.css +62 -5
  275. package/dist/styles.css +123 -198
  276. package/package.json +5 -4
@@ -0,0 +1,835 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import '../card/style.css';
3
+ import '../list/style.css';
4
+ import '../progress/style.css';
5
+ import './style.css';
6
+ import { Radio as BaseRadio } from '@base-ui/react/radio';
7
+ import { RadioGroup as BaseRadioGroup } from '@base-ui/react/radio-group';
8
+ import { createContext, forwardRef, useCallback, useContext, useLayoutEffect, useMemo, useRef, useState, } from 'react';
9
+ import { Badge } from '../badge/main.js';
10
+ import { Card, CardBlendScope, useCardOrientation, } from '../card/main.js';
11
+ import { colorSchemeStyle, toneOfColor, } from '../glass/main.js';
12
+ import { measureOf } from '../grid/handle.js';
13
+ import { iconOf, polyline } from '../grid/icons.js';
14
+ import { gridIcons, startWithFrame, useGridItem } from '../grid/main.js';
15
+ import { forwardClick, List } from '../list/main.js';
16
+ import { Progress } from '../progress/main.js';
17
+ import { useSettings } from '../settings/main.js';
18
+ import { Slider } from '../slider/main.js';
19
+ import { Symbol } from '../symbol/main.js';
20
+ import { cn, reducedMotionOf } from '../utils/main.js';
21
+ // Control cards: ready-made cards (each a `Card.Root` and its parts) for
22
+ // what a home's devices show and control: a state, a switch, a value, a
23
+ // slider, a momentary button, a progress, a light of several channels, a
24
+ // list; and what they're made of besides (a light's bars, corner buttons
25
+ // expanding a card and opening it above the page). A namespace, not one
26
+ // component's parts: each card stands on its own, its other props its
27
+ // `Card.Root`'s, its `children` added after its parts (e.g. a corner
28
+ // button).
29
+ /** Controlled or uncontrolled state (as Base UI's components). */
30
+ const useControlled = (value, defaultValue) => {
31
+ const [state, setState] = useState(defaultValue);
32
+ return [value === undefined ? state : value, setState];
33
+ };
34
+ /** The document's language, if it says (none: the runtime's default). */
35
+ const documentLocale = () => typeof document === 'undefined'
36
+ ? undefined
37
+ : document.documentElement.lang || undefined;
38
+ /** A number, formatted (see `ControlCardFormat`). */
39
+ const formatted = (value, { format, locale }) => new Intl.NumberFormat(locale ?? documentLocale(), format).format(value);
40
+ /**
41
+ * Whether its card shows its large layout: its tile at least 2x2 (a full
42
+ * width's: wide), however it got there (expanded, resized), or open above
43
+ * the page.
44
+ */
45
+ const useIsLarge = () => {
46
+ const item = useGridItem();
47
+ if (!item)
48
+ return false;
49
+ const [columns = '1', rows = '1'] = item.size.split('x');
50
+ return (item.open ||
51
+ ((columns === '*' || Number(columns) >= 2) && Number(rows) >= 2));
52
+ };
53
+ /** Its symbol: its icon, or its emphasized one while on. */
54
+ const symbolOf = ({ emphasizedIcon, icon }, children) => (_jsx(Symbol, { box: "square", emphasizedIcon: emphasizedIcon, icon: icon, children: children }));
55
+ /**
56
+ * A binary display: its state lit (`active`), its symbol emphasized, its
57
+ * value its state's words (e.g. a door open or closed).
58
+ */
59
+ const State = forwardRef(({ active, children, className, emphasizedIcon, icon, name, states = ['On', 'Off'], ...props }, ref) => (_jsxs(Card.Root, { ref: ref, active: active, ...props, className: cn('uikit-control-cards-state', className), "data-control-cards-part": "state", children: [_jsx(Card.Symbol, { children: symbolOf({ emphasizedIcon, icon }) }), _jsx(Card.Title, { children: name }), _jsx(Card.Value, { children: active ? states[0] : states[1] }), children] })));
60
+ /**
61
+ * A binary control: a switch at its top trailing corner, a press on the
62
+ * card toggling it; lit while on.
63
+ */
64
+ const SwitchCard = forwardRef(({ checked, children, className, defaultChecked = false, emphasizedIcon, icon, name, onCheckedChange, onClick, states = ['On', 'Off'], tint, ...props }, ref) => {
65
+ const [isOn, setIsOn] = useControlled(checked, defaultChecked);
66
+ const switchTo = (next) => {
67
+ setIsOn(next);
68
+ onCheckedChange?.(next);
69
+ };
70
+ return (_jsxs(Card.Root, { ref: ref, active: isOn, ...props, className: cn('uikit-control-cards-switch', className), "data-control-cards-part": "switch", onClick: onClick ?? forwardClick('[role=switch]'), children: [_jsx(Card.Symbol, { tint: tint, children: symbolOf({ emphasizedIcon, icon }) }), _jsx(Card.Title, { children: name }), _jsx(Card.Value, { children: isOn ? states[0] : states[1] }), _jsx(Card.Switch, { "aria-label": name, checked: isOn, tint: tint, onCheckedChange: switchTo }), children] }));
71
+ });
72
+ /** A trend's arrow (see `Trend`): pointing ahead, turned by its angle. */
73
+ const trendIcon = iconOf('control-cards.trend', polyline([-4.5, 0], [4.5, 0]) + polyline([0.5, -4], [4.5, 0], [0.5, 4]));
74
+ /** A trend's words, by its angle (see `Trend`). */
75
+ const trendOf = (angle) => {
76
+ if (angle > 10)
77
+ return 'rising';
78
+ return angle < -10 ? 'falling' : 'steady';
79
+ };
80
+ /**
81
+ * A value's trend: an arrow pointing up as steeply as it rises (`angle`,
82
+ * -90 to 90 degrees: 0 steady), named for assistive technology. It turns
83
+ * to a new angle by its own transform.
84
+ */
85
+ const Trend = ({ angle }) => {
86
+ const clamped = Math.max(-90, Math.min(90, angle));
87
+ return (_jsx("span", { "aria-label": trendOf(clamped), className: "uikit-control-cards-trend", role: "img", style: { '--uikit-control-cards-trend': String(clamped) }, children: _jsx(Symbol, { icon: trendIcon }) }));
88
+ };
89
+ /**
90
+ * A numerical display: its value, formatted as the app says, and its
91
+ * trend (an arrow after it), if given.
92
+ */
93
+ const Value = forwardRef(({ children, className, emphasizedIcon, format, icon, locale, name, trend, value, ...props }, ref) => (_jsxs(Card.Root, { ref: ref, ...props, className: cn('uikit-control-cards-value', className), "data-control-cards-part": "value", children: [_jsx(Card.Symbol, { children: symbolOf({ emphasizedIcon, icon }) }), _jsx(Card.Title, { children: name }), _jsxs(Card.Value, { children: [typeof value === 'number'
94
+ ? formatted(value, { format, locale })
95
+ : value, trend === undefined ? null : _jsx(Trend, { angle: trend })] }), children] })));
96
+ // How far a press moves before it's a drag (px; the grid's resize
97
+ // handle's, see Grid's edit.ts); a touch's (or a pen's), before it's told
98
+ // a drag (along the slider) from a scroll (across it), as a browser tells
99
+ // a pan.
100
+ const pressSlop = 4;
101
+ const touchSlop = 8;
102
+ // (A press handed on to the slider (see `pressProps`): let through; one
103
+ // held back, not yet a drag or a click: its touch held back too.)
104
+ let isHandingOn = false;
105
+ let isHolding = false;
106
+ /**
107
+ * A slider's press (its `Slider.Root`'s props), held back at first (the
108
+ * slider would set its value as it's pressed, and, a touch, follow it
109
+ * even as the page scrolls, see Base UI's SliderControl):
110
+ * - Moved (`pressSlop`; a touch, `touchSlop`) along it (a mouse, any
111
+ * way): a drag, handed on to the slider (the press again, where it
112
+ * started).
113
+ * - A touch moved across it, or the browser panning (it's cancelled): a
114
+ * scroll, the page's, the slider never told.
115
+ * - Released before: `onClick`'s, the slider never told (its value
116
+ * kept); its click, if the browser moves it to a control near it (e.g.
117
+ * the card's switch, a tap's target adjusted, as WebKit's on iOS), not
118
+ * that control's too (toggled back): swallowed (not the click deciding:
119
+ * on iOS, none may come to it). No `onClick`: handed on to the slider as
120
+ * it's released (its value set where it was pressed).
121
+ */
122
+ const pressProps = (onClick, orientation) => ({
123
+ onPointerDownCapture: (event) => {
124
+ if (isHandingOn || event.button !== 0)
125
+ return;
126
+ event.stopPropagation();
127
+ // (The DOM's event: React's wraps it, Preact's is it.)
128
+ const pressed = event.nativeEvent ??
129
+ event;
130
+ const { clientX, clientY, pointerId, pointerType, target } = pressed;
131
+ const isMouse = pointerType === 'mouse';
132
+ const slop = isMouse ? pressSlop : touchSlop;
133
+ const root = event.currentTarget;
134
+ const handOn = () => {
135
+ isHandingOn = true;
136
+ try {
137
+ target?.dispatchEvent(new PointerEvent('pointerdown', pressed));
138
+ }
139
+ finally {
140
+ isHandingOn = false;
141
+ }
142
+ };
143
+ const listening = new AbortController();
144
+ const options = { capture: true, signal: listening.signal };
145
+ isHolding = true;
146
+ listening.signal.addEventListener('abort', () => {
147
+ isHolding = false;
148
+ });
149
+ addEventListener('pointermove', (move) => {
150
+ if (move.pointerId !== pointerId)
151
+ return;
152
+ const across = Math.abs(move.clientX - clientX);
153
+ const upright = Math.abs(move.clientY - clientY);
154
+ if (Math.hypot(across, upright) < slop)
155
+ return;
156
+ listening.abort();
157
+ // (A touch across it: a scroll, let go.)
158
+ const along = orientation === 'vertical' ? upright : across;
159
+ const crossing = orientation === 'vertical' ? across : upright;
160
+ if (!isMouse && crossing > along)
161
+ return;
162
+ handOn();
163
+ }, options);
164
+ addEventListener('pointerup', (up) => {
165
+ if (up.pointerId !== pointerId)
166
+ return;
167
+ listening.abort();
168
+ // (No click of its own: the slider's, its value set there; this
169
+ // release ending it, as it goes on.)
170
+ if (onClick === undefined) {
171
+ handOn();
172
+ return;
173
+ }
174
+ onClick();
175
+ // (Its click next, if any, elsewhere: swallowed; none before
176
+ // another press or key, nothing.)
177
+ const clicking = new AbortController();
178
+ const once = { capture: true, signal: clicking.signal };
179
+ addEventListener('click', (clicked) => {
180
+ clicking.abort();
181
+ if (root.contains(clicked.target))
182
+ return;
183
+ clicked.preventDefault();
184
+ clicked.stopPropagation();
185
+ }, once);
186
+ for (const type of ['pointerdown', 'keydown']) {
187
+ addEventListener(type, () => clicking.abort(), once);
188
+ }
189
+ }, options);
190
+ addEventListener('pointercancel', (cancel) => {
191
+ if (cancel.pointerId === pointerId)
192
+ listening.abort();
193
+ }, options);
194
+ },
195
+ // (The slider takes a touch's start too, unless its pointer's started
196
+ // it (see Base UI's SliderControl), following it past a pan: held back
197
+ // with it.)
198
+ onTouchStartCapture: (event) => {
199
+ if (isHolding)
200
+ event.stopPropagation();
201
+ },
202
+ });
203
+ /**
204
+ * Its fill's tone (opaque: its color's), as its tint or the color scheme
205
+ * changes (not as it moves), and the color scheme of what's drawn over it.
206
+ * Its tint's, read where it's drawn (its `light-dark()` resolved there), not
207
+ * what's painted: off, with a switch, the fill isn't drawn (see Card), and
208
+ * its tone is still wanted as it's switched on.
209
+ */
210
+ const useFillScheme = (indicator, tint) => {
211
+ const { colorScheme } = useSettings();
212
+ const [tone, setTone] = useState();
213
+ useLayoutEffect(() => {
214
+ const { current: element } = indicator;
215
+ if (!element)
216
+ return;
217
+ // (Read once it's laid out: its color computed, a var's resolved, by a
218
+ // probe in it, gone again.)
219
+ const read = () => {
220
+ const probe = document.createElement('span');
221
+ probe.style.color = 'var(--uikit-slider-tint)';
222
+ element.append(probe);
223
+ const { color } = getComputedStyle(probe);
224
+ probe.remove();
225
+ setTone((last) => toneOfColor(color, last));
226
+ };
227
+ read();
228
+ }, [colorScheme, indicator, tint]);
229
+ if (tone === undefined)
230
+ return undefined;
231
+ return tone === 'bright' ? 'light' : 'dark';
232
+ };
233
+ /**
234
+ * A slider card's switch (see `ControlCardSliderProps.checked`): whether
235
+ * it has one, whether it's on (with none: on), switching it.
236
+ */
237
+ const useSliderSwitch = (checked, defaultChecked, onCheckedChange) => {
238
+ const hasSwitch = checked !== undefined || defaultChecked !== undefined;
239
+ const [isOn, setIsOn] = useControlled(checked, defaultChecked ?? true);
240
+ const switchTo = (next) => {
241
+ setIsOn(next);
242
+ onCheckedChange?.(next);
243
+ };
244
+ return { hasSwitch, isOn, switchTo };
245
+ };
246
+ /** A value text (see `getValueText`) as `Slider.Value`'s children. */
247
+ const valueTextOf = (getValueText) => getValueText
248
+ ? (formattedValues, values) => getValueText(formattedValues[0] ?? '', values[0] ?? 0)
249
+ : undefined;
250
+ const FillCopies = ({ layerRef, name, orientation, scheme, ticks, valueText, }) => (_jsxs("span", { ref: layerRef, "aria-hidden": true, inert: true, className: "uikit-card-blend", "data-color-scheme": scheme, "data-orientation": orientation, style: colorSchemeStyle(scheme), children: [_jsx("span", { className: "uikit-slider-label", "data-card-copy": "", children: name }), _jsx(Slider.Value, { "data-card-copy": "", children: valueText }), ticks === undefined ? null : (_jsx(Slider.Ticks, { count: ticks, "data-card-copy": "" }))] }));
251
+ /**
252
+ * A slider filling its card (a `Card.Root`'s, among its parts): its fill
253
+ * the card's background (from its leading edge, or from its bottom upright,
254
+ * by its tile's shape), ticks at its steps (`step`), its label and value at
255
+ * the card's bottom. What's over the fill (its label, value and ticks, the
256
+ * card's symbol and corner buttons) drawn twice: on the card, and again
257
+ * inside the fill in the fill's color scheme (dark on a bright fill, light
258
+ * on a dim one), clipped by its edge, so it reads whatever its tint. With
259
+ * an `onPress`, a click on it is that (e.g. a switch toggled), a drag sets
260
+ * its value.
261
+ */
262
+ const SliderFill = forwardRef(({ className, defaultValue, format, getValueText, locale, max = 100, min = 0, name, onPress, onValueChange, step, tint, value, }, ref) => {
263
+ const orientation = useCardOrientation();
264
+ const [current, setCurrent] = useControlled(value, defaultValue ?? min);
265
+ // (Its fill's color scheme; the layer in it registered with its card,
266
+ // see `CardBlendScope`.)
267
+ const indicator = useRef(null);
268
+ const scheme = useFillScheme(indicator, tint);
269
+ const setLayer = useContext(CardBlendScope)?.setLayer;
270
+ const ticks = step === undefined ? undefined : Math.round((max - min) / step) + 1;
271
+ const valueText = valueTextOf(getValueText);
272
+ return (_jsxs(Slider.Root, { ref: ref, className: cn('uikit-control-cards-slider-fill', className), "data-control-cards-part": "slider-fill", format: format, locale: locale, max: max, min: min, orientation: orientation, step: step ?? (max - min) / 100, tint: tint, value: current, onValueChange: (next) => {
273
+ setCurrent(next);
274
+ onValueChange?.(next);
275
+ }, ...pressProps(onPress, orientation), children: [_jsx(Slider.Control, { children: _jsxs(Slider.Track, { children: [_jsx(Slider.Indicator, { ref: indicator, children: scheme ? (_jsx(FillCopies, { layerRef: setLayer, name: name, orientation: orientation, scheme: scheme, ticks: ticks, valueText: valueText })) : null }), ticks === undefined ? null : _jsx(Slider.Ticks, { count: ticks }), _jsx(Slider.Thumb, { "aria-label": name, getAriaValueText: getValueText })] }) }), _jsx(Slider.Label, { children: name }), _jsx(Slider.Value, { children: valueText })] }));
276
+ });
277
+ /**
278
+ * A slider card's value text by default (see `getValueText`): with a
279
+ * switch, its state's word and its number (“On · 60%”); without one, its
280
+ * number.
281
+ */
282
+ const defaultValueText = (formattedValue, { checked, states: [on, off] }) => checked === undefined
283
+ ? formattedValue
284
+ : `${checked ? on : off} · ${formattedValue}`;
285
+ /**
286
+ * A numerical control: a `SliderFill` in a card, its symbol at its top.
287
+ * Optionally a switch (`checked`): on and off, its value kept; a click on
288
+ * the card toggles it, a drag sets its value.
289
+ */
290
+ const SliderCard = forwardRef(({ brightness = false, checked, children, className, defaultChecked, defaultValue, emphasizedIcon, format, getValueText, icon, locale, max = 100, min = 0, name, onCheckedChange, onValueChange, states = ['On', 'Off'], step, tint, value, ...props }, ref) => {
291
+ const [current, setCurrent] = useControlled(value, defaultValue ?? min);
292
+ const { hasSwitch, isOn, switchTo } = useSliderSwitch(checked, defaultChecked, onCheckedChange);
293
+ // (Its symbol on: a brightness's above its minimum, while on; else, as
294
+ // its switch, if any.)
295
+ const isOnAtAll = !hasSwitch || isOn;
296
+ const isSymbolOn = brightness
297
+ ? isOnAtAll && current > min
298
+ : hasSwitch && isOn;
299
+ return (_jsxs(Card.Root, { ref: ref,
300
+ // (A brightness's: never lit, its dark glass and its fill telling
301
+ // how much light; else, its glass the color scheme's.)
302
+ active: brightness ? false : undefined, ...props, className: cn('uikit-control-cards-slider', className), "data-control-cards-part": "slider", children: [_jsx(Card.Symbol, { active: isSymbolOn, children: symbolOf({ emphasizedIcon, icon }) }), _jsx(SliderFill, { format: format, locale: locale, max: max, min: min, name: name, step: step, tint: tint, value: current, getValueText: (formattedValue, number) => {
303
+ const isChecked = hasSwitch ? isOn : undefined;
304
+ if (getValueText) {
305
+ return getValueText(formattedValue, number, {
306
+ checked: isChecked,
307
+ states,
308
+ });
309
+ }
310
+ return defaultValueText(formattedValue, {
311
+ checked: isChecked,
312
+ states,
313
+ });
314
+ }, onPress: hasSwitch ? () => switchTo(!isOn) : undefined, onValueChange: (next) => {
315
+ setCurrent(next);
316
+ onValueChange?.(next);
317
+ } }), hasSwitch ? (_jsx(Card.Switch, { "aria-label": name, checked: isOn, tint: tint, onCheckedChange: switchTo })) : null, children] }));
318
+ });
319
+ /**
320
+ * A momentary button: a press does something once (e.g. a doorbell rung,
321
+ * all lights off); it lights up for a moment and fades back, also as the
322
+ * app flashes it (`actionsRef`). A badge on its symbol, if given.
323
+ */
324
+ const Button = forwardRef(({ badge, children, className, emphasizedIcon, icon, name, onClick, onPress, status, ...props }, ref) => (_jsxs(Card.Root, { ref: ref, momentary: true, ...props, className: cn('uikit-control-cards-button', className), "data-control-cards-part": "button", onClick: (event) => {
325
+ onPress?.();
326
+ onClick?.(event);
327
+ }, children: [_jsx(Card.Symbol, { children: symbolOf({ emphasizedIcon, icon }, badge === undefined || badge === null ? null : (_jsx(Badge, { placement: "symbol", children: badge }))) }), _jsx(Card.Title, { children: name }), status === undefined ? null : _jsx(Card.Value, { children: status }), children] })));
328
+ /**
329
+ * A progress (e.g. a washer's, a garage door moving): a bar between its
330
+ * top row and its title while there is one (`value`), its value's words.
331
+ */
332
+ const ProgressCard = forwardRef(({ active, children, className, emphasizedIcon, icon, max = 100, name, status, tint, value, ...props }, ref) => (_jsxs(Card.Root, { ref: ref, active: active, ...props, className: cn('uikit-control-cards-progress', className), "data-control-cards-part": "progress", children: [_jsx(Card.Symbol, { children: symbolOf({ emphasizedIcon, icon }) }), value === undefined ? null : (_jsx("div", { className: "uikit-control-cards-controls", children: _jsx(Progress.Root, { "aria-label": name, max: max, tint: tint, value: value, children: _jsx(Progress.Track, { children: _jsx(Progress.Indicator, {}) }) }) })), _jsx(Card.Title, { children: name }), status === undefined ? null : _jsx(Card.Value, { children: status }), children] })));
333
+ /**
334
+ * A card's bars (e.g. a light's channels): side by side, upright, in a
335
+ * tile taller than one row, else stacked across; each a slider (0 to 1),
336
+ * its short name on it (upright) or beside it (across, too thin for it),
337
+ * in its tint. Between the card's top row and its title.
338
+ */
339
+ const Channels = forwardRef(({ channels, className, onValueChange, value }, ref) => {
340
+ const [, rows = '1'] = (useGridItem()?.size ?? '2x2').split('x');
341
+ const orientation = rows === '1' ? 'horizontal' : 'vertical';
342
+ return (_jsx("div", { ref: ref, className: cn('uikit-control-cards-channels', className), "data-control-cards-part": "channels", "data-orientation": orientation, children: channels.map(({ label, name, tint }, index) => (_jsxs(Slider.Root, { format: { style: 'percent' }, max: 1, min: 0, orientation: orientation, step: 0.01, tint: tint, value: value[index] ?? 0, onValueChange: (next) => onValueChange?.(index, next), children: [_jsx(Slider.Control, { children: _jsxs(Slider.Track, { children: [_jsx(Slider.Indicator, {}), _jsx(Slider.Thumb, { "aria-label": name })] }) }), _jsx(Slider.Label, { "aria-hidden": "true", children: label })] }, name))) }));
343
+ });
344
+ /**
345
+ * What channels make together (each 0 to 1, by its tint): their colors
346
+ * mixed by their shares, at full strength; none on, none.
347
+ */
348
+ const mixColor = (channels, values) => {
349
+ const lit = channels
350
+ .map(({ tint }, index) => ({ tint, value: values[index] ?? 0 }))
351
+ .filter(({ value }) => value > 0);
352
+ const total = lit.reduce((sum, { value }) => sum + value, 0);
353
+ if (total === 0)
354
+ return undefined;
355
+ // (color-mix of two at a time, each step weighting the next by its share
356
+ // of what's mixed so far.)
357
+ let mixed = lit[0]?.tint ?? '';
358
+ let sum = lit[0]?.value ?? 0;
359
+ for (const { tint, value } of lit.slice(1)) {
360
+ sum += value;
361
+ const share = Math.round((value / sum) * 100);
362
+ mixed = `color-mix(in oklab, ${tint} ${String(share)}%, ${mixed})`;
363
+ }
364
+ return mixed;
365
+ };
366
+ /**
367
+ * A light of several channels (e.g. red, green, blue): a switch, lit while
368
+ * on, its symbol in the color they make, its value its brightness (its
369
+ * strongest channel's); large (expanded, resized, opened), a bar per
370
+ * channel (see `Channels`). Small, a press on it toggles it.
371
+ */
372
+ const Light = forwardRef(({ channels, checked, children, className, defaultChecked = true, defaultValue, emphasizedIcon, format = { maximumFractionDigits: 0, style: 'percent' }, icon, locale, name, offLabel = 'Off', onCheckedChange, onClick, onValueChange, value, ...props }, ref) => {
373
+ const [isOn, setIsOn] = useControlled(checked, defaultChecked);
374
+ const [values, setValues] = useControlled(value, defaultValue ?? channels.map(() => 1));
375
+ const isLarge = useIsLarge();
376
+ const color = isOn ? mixColor(channels, values) : undefined;
377
+ const switchTo = (next) => {
378
+ setIsOn(next);
379
+ onCheckedChange?.(next);
380
+ };
381
+ return (_jsxs(Card.Root, { ref: ref, ...props, className: cn('uikit-control-cards-light', className), "data-control-cards-part": "light", onClick: onClick ??
382
+ (isLarge ? undefined : forwardClick('[role=switch]:not([disabled])')), children: [_jsx(Card.Symbol, { style: color ? { color } : undefined, children: symbolOf({ emphasizedIcon, icon }) }), _jsx(Card.Switch, { "aria-label": name, checked: isOn, tint: color, onCheckedChange: switchTo }), isLarge ? (_jsx(Channels, { channels: channels, value: values, onValueChange: (index, next) => {
383
+ const all = values.map((each, at) => at === index ? next : each);
384
+ setValues(all);
385
+ onValueChange?.(all);
386
+ } })) : null, _jsx(Card.Title, { children: name }), _jsx(Card.Value, { children: isOn
387
+ ? formatted(Math.max(0, ...values), { format, locale })
388
+ : offLabel }), children] }));
389
+ });
390
+ /**
391
+ * A corner button expanding its card in place and making it small again
392
+ * (bottom trailing; its grid item's size is the app's, see Grid).
393
+ */
394
+ const ExpandButton = ({ collapsedSize, expanded, expandedSize, label, onExpandedChange, }) => {
395
+ // (Each size as its item would be it now (see `useGridItem`'s
396
+ // `sizeOf`): the same, expanding changes nothing, hidden; outside a
397
+ // grid, as given.)
398
+ const item = useGridItem();
399
+ const small = item?.sizeOf(collapsedSize).size ?? collapsedSize;
400
+ const large = item?.sizeOf(expandedSize).size ?? expandedSize;
401
+ // (Its icon by where it goes: larger, expanding; smaller, collapsing
402
+ // (e.g. expanded smaller than it's stored).)
403
+ const [from, to] = expanded ? [large, small] : [small, large];
404
+ return (_jsx(Card.CornerButton, { mirrored: true, "aria-expanded": expanded, "aria-label": label, visible: small !== large, icon: measureOf(to) > measureOf(from) ? gridIcons.expand : gridIcons.collapse, onClick: () => onExpandedChange(!expanded) }));
405
+ };
406
+ /**
407
+ * How many rows of its list fit in it whole (its box filling its room in
408
+ * the card, see Card; a row's height its `--uikit-list-row-min-height`, as
409
+ * Card sets it, opened above the page too): by its height, at least one;
410
+ * as the card's size changes too.
411
+ */
412
+ const rowsIn = (list) => {
413
+ const row = Number.parseFloat(getComputedStyle(list).getPropertyValue('--uikit-list-row-min-height')) || 30;
414
+ return Math.max(1, Math.floor(list.clientHeight / row));
415
+ };
416
+ const useRowsThatFit = () => {
417
+ const [list, setList] = useState(null);
418
+ const [count, setCount] = useState(1);
419
+ useLayoutEffect(() => {
420
+ if (!list)
421
+ return undefined;
422
+ const observer = new ResizeObserver(() => setCount(rowsIn(list)));
423
+ observer.observe(list);
424
+ return () => observer.disconnect();
425
+ }, [list]);
426
+ // (Also after each render, before it's painted: its tile resized in it
427
+ // (e.g. collapsed), its rows counted at once, not a frame late (a frame
428
+ // of the rows of the size it had, its last row a new one after).)
429
+ useLayoutEffect(() => {
430
+ if (!list)
431
+ return;
432
+ const read = () => setCount(rowsIn(list));
433
+ read();
434
+ });
435
+ return [setList, count, list];
436
+ };
437
+ /** Grid's reflow (its tiles reshaping): its duration and easing. */
438
+ const reflowDuration = 300;
439
+ const reflowEasing = 'cubic-bezier(0.32, 0.72, 0, 1)';
440
+ /** Its last row's height's animation (see `useLastRowHeight`). */
441
+ const lastRowId = 'uikit-control-cards-last-row';
442
+ /**
443
+ * Its list's last row's height changing with how many rows there are (one
444
+ * only: taller, see Card), as its tile reshapes (Grid's reflow: its
445
+ * duration and easing): from the height it had, animated, started with
446
+ * the frames (see Grid's `startWithFrame`: a long task laying the page out
447
+ * anew, e.g. its tile expanding, not past it already, as a transition
448
+ * would be).
449
+ */
450
+ const useLastRowHeight = (list, count) => {
451
+ const last = useRef(undefined);
452
+ useLayoutEffect(() => {
453
+ const row = list?.querySelector(':scope .uikit-list-item:last-child .uikit-list-row');
454
+ if (!row) {
455
+ last.current = undefined;
456
+ return;
457
+ }
458
+ for (const animation of row.getAnimations()) {
459
+ if (animation.id === lastRowId)
460
+ animation.cancel();
461
+ }
462
+ const height = getComputedStyle(row).minHeight;
463
+ const before = last.current;
464
+ last.current = { count, height };
465
+ if (!before ||
466
+ before.count === count ||
467
+ before.height === height ||
468
+ reducedMotionOf(row).matches) {
469
+ return;
470
+ }
471
+ startWithFrame(row.animate([{ minHeight: before.height }, { minHeight: height }], {
472
+ duration: reflowDuration,
473
+ easing: reflowEasing,
474
+ id: lastRowId,
475
+ }));
476
+ }, [count, list]);
477
+ };
478
+ const actionIcons = {
479
+ expand: gridIcons.expand,
480
+ less: gridIcons.collapse,
481
+ more: undefined,
482
+ open: gridIcons.open,
483
+ };
484
+ /**
485
+ * What a list card's last row does (see `ListCard`): open above the page,
486
+ * none; expanded, making it small again; rows left out, expanding it (only
487
+ * where that'd change its size, as `ExpandButton`), else opening it, else
488
+ * only counting them; none.
489
+ */
490
+ const useListAction = ({ expansion, isLeftOut, opening, }) => {
491
+ const item = useGridItem();
492
+ if (item?.open === true)
493
+ return undefined;
494
+ const canExpand = expansion !== undefined &&
495
+ (item?.sizeOf(expansion.collapsedSize).size ?? expansion.collapsedSize) !==
496
+ (item?.sizeOf(expansion.expandedSize).size ?? expansion.expandedSize);
497
+ if (canExpand && expansion.expanded) {
498
+ return { kind: 'less', onPress: () => expansion.onExpandedChange(false) };
499
+ }
500
+ if (!isLeftOut)
501
+ return undefined;
502
+ if (canExpand) {
503
+ return { kind: 'expand', onPress: () => expansion.onExpandedChange(true) };
504
+ }
505
+ return opening
506
+ ? { kind: 'open', onPress: () => item?.setOpen(true) }
507
+ : { kind: 'more' };
508
+ };
509
+ /**
510
+ * A list card's last row (see `ListCard`): its label where its rows' are
511
+ * (after their symbols' room, if they have them), pressed doing its
512
+ * action; the corner symbol for it where a value is.
513
+ */
514
+ const ActionRow = ({ action, hasIcons, label, }) => {
515
+ const icon = actionIcons[action.kind];
516
+ const isExpanding = action.kind === 'expand' || action.kind === 'less';
517
+ return (_jsxs(List.Item, { "data-control-cards-part": "list-action", children: [hasIcons ? (_jsx(List.Leading, { children: _jsx(List.Image, { variant: "symbol" }) })) : null, _jsx(List.Content, { children: _jsx(List.Title, { render: action.onPress ? (_jsx("button", { "aria-expanded": isExpanding ? action.kind === 'less' : undefined, type: "button", onClick: action.onPress })) : undefined, children: label }) }), icon ? (_jsx(List.Trailing, { children: _jsx(List.Detail, { children: _jsx(Symbol, { icon: icon }) }) })) : null] }));
518
+ };
519
+ /**
520
+ * A summary in rows (e.g. a room's, a device's details): its symbol, its
521
+ * title and status beside it at its top, a glass list of rows (as many as
522
+ * fit whole) in a well at its bottom. Rows left out, its last row counts
523
+ * them, expanding or opening it (`expansion`, `opening`); expanded, it
524
+ * makes it small again. No rows, no list (its corner buttons instead);
525
+ * open above the page, an x in its top trailing corner closes it.
526
+ */
527
+ const ListCard = forwardRef(({ children, className, emphasizedIcon, expansion, getMoreLabel = (count) => `${String(count)} more`, icon, lessLabel = 'Less', name, opening, rows, status, ...props }, ref) => {
528
+ const [list, fit, listElement] = useRowsThatFit();
529
+ const item = useGridItem();
530
+ const isOpen = item?.open === true;
531
+ const action = useListAction({
532
+ expansion,
533
+ isLeftOut: rows.length > fit,
534
+ opening,
535
+ });
536
+ // (Its last row the action's, if any: one row less.)
537
+ const shown = action ? rows.slice(0, fit - 1) : rows.slice(0, fit);
538
+ useLastRowHeight(listElement, shown.length + (action ? 1 : 0));
539
+ return (_jsxs(Card.Root, { ref: ref, ...props, className: cn('uikit-control-cards-list', className), "data-control-cards-part": "list", children: [_jsx(Card.Symbol, { children: symbolOf({ emphasizedIcon, icon }) }), _jsx(Card.Title, { children: name }), status === undefined ? null : _jsx(Card.Value, { children: status }), rows.length === 0 ? null : (_jsx(List.Root, { ref: list, children: _jsx(List.Section, { children: _jsxs(List.Group, { children: [shown.map((row) => (_jsxs(List.Item, { children: [row.icon ? (_jsx(List.Leading, { children: _jsx(List.Image, { variant: "symbol", children: _jsx(Symbol, { icon: row.icon }) }) })) : null, _jsx(List.Content, { children: _jsx(List.Title, { render: row.onPress ? (_jsx("button", { type: "button", onClick: row.onPress })) : undefined, children: row.label }) }), _jsxs(List.Trailing, { children: [_jsx(List.Detail, { children: row.value }), row.onPress ? _jsx(List.DrillIn, {}) : null] })] }, row.label))), action ? (_jsx(ActionRow, { action: action, hasIcons: rows.some((row) => row.icon !== undefined), label: action.kind === 'less'
540
+ ? lessLabel
541
+ : getMoreLabel(rows.length - shown.length) }, "action")) : null] }) }) })), rows.length > 0 && action?.onPress ? (_jsx(Card.CornerButton, { "aria-hidden": true, className: "uikit-control-cards-hit-area", icon: actionIcons[action.kind] ?? gridIcons.open, tabIndex: -1, onClick: action.onPress })) : null, rows.length === 0 && expansion ? (_jsx(ExpandButton, { ...expansion })) : null, rows.length === 0 && opening && !expansion ? (_jsx(Card.CornerButton, { "aria-label": opening.label, icon: gridIcons.open, visible: !isOpen, onClick: () => item?.setOpen(true) })) : null, opening ? (_jsx(Card.CornerButton, { "aria-label": opening.closeLabel, corner: "top-trailing", icon: gridIcons.close, visible: isOpen, onClick: () => item?.setOpen(false) })) : null, children] }));
542
+ });
543
+ /**
544
+ * Corner buttons opening its card above the page (its grid item's `open`,
545
+ * see `Grid.Item`), bottom trailing, and closing it (top leading), each
546
+ * shown as it applies.
547
+ */
548
+ const OpenButtons = ({ closeLabel, label, }) => {
549
+ const item = useGridItem();
550
+ const isOpen = item?.open === true;
551
+ return (_jsxs(_Fragment, { children: [_jsx(Card.CornerButton, { "aria-label": label, icon: gridIcons.open, visible: !isOpen, onClick: () => item?.setOpen(true) }), _jsx(Card.CornerButton, { "aria-label": closeLabel, corner: "top-trailing", icon: gridIcons.close, visible: isOpen, onClick: () => item?.setOpen(false) })] }));
552
+ };
553
+ /**
554
+ * Its layout by its size (open above the page, that one) and its
555
+ * orientation (the app's; none, by its size): taller than a row, its
556
+ * options stacked (`upright`: vertical, or one wide) or side by side, a
557
+ * symbol over its words (`tall`: horizontal, or wider); one row, side by
558
+ * side across it (`row`: wider, not vertical); else none (`compact`: 1x1,
559
+ * or vertical in one row, no room to stack them). Outside a grid, a row,
560
+ * or stacked (vertical).
561
+ */
562
+ const layoutOf = (orientation, isWide, isTall) => {
563
+ if (isTall) {
564
+ if (orientation === undefined)
565
+ return isWide ? 'tall' : 'upright';
566
+ return orientation === 'vertical' ? 'upright' : 'tall';
567
+ }
568
+ return isWide && orientation !== 'vertical' ? 'row' : 'compact';
569
+ };
570
+ /** Its layout (see `layoutOf`), and whether it's one wide (narrow). */
571
+ const useSegmentedLayout = (orientation) => {
572
+ const item = useGridItem();
573
+ if (!item)
574
+ return [orientation === 'vertical' ? 'upright' : 'row', false];
575
+ const [columns = '1', rows = '1'] = (item.open ? item.openSize : item.size).split('x');
576
+ const isWide = columns === '*' || Number(columns) >= 2;
577
+ return [layoutOf(orientation, isWide, Number(rows) >= 2), !isWide];
578
+ };
579
+ /** A segmented card's thumb, placed on an option's box (see below). */
580
+ const placeThumb = (thumb, on) => {
581
+ thumb.hidden = !on;
582
+ if (!on)
583
+ return;
584
+ thumb.style.setProperty('--uikit-control-cards-thumb-x', `${String(on.offsetLeft)}px`);
585
+ thumb.style.setProperty('--uikit-control-cards-thumb-y', `${String(on.offsetTop)}px`);
586
+ thumb.style.setProperty('--uikit-control-cards-thumb-width', `${String(on.offsetWidth)}px`);
587
+ thumb.style.setProperty('--uikit-control-cards-thumb-height', `${String(on.offsetHeight)}px`);
588
+ };
589
+ /** The option nearest a point, along the options (see `dragProps`). */
590
+ const nearestOption = (root, isUpright, { clientX, clientY }) => {
591
+ let nearest;
592
+ let distance = Infinity;
593
+ for (const option of root.querySelectorAll('[role="radio"]')) {
594
+ if (Object.hasOwn(option.dataset, 'disabled'))
595
+ continue;
596
+ const box = option.getBoundingClientRect();
597
+ const away = isUpright
598
+ ? Math.abs(box.top + box.height / 2 - clientY)
599
+ : Math.abs(box.left + box.width / 2 - clientX);
600
+ if (!(away < distance)) {
601
+ continue;
602
+ }
603
+ distance = away;
604
+ nearest = option;
605
+ }
606
+ return nearest;
607
+ };
608
+ /**
609
+ * Dragging between a segmented card's options (as Segmented's, no lens:
610
+ * its thumb what moves): held back until it moves (`pressSlop`; a touch,
611
+ * `touchSlop`), then along the options (a mouse, any way), the nearest one
612
+ * chosen as it's reached (its thumb going there); a touch across them, or
613
+ * the browser panning first (it's cancelled), a scroll, let go (as a
614
+ * slider card's, see `pressProps`). Dragging, the page doesn't pan (see
615
+ * `SegmentedChoice`). Released before, a press: the option's own (its
616
+ * click).
617
+ */
618
+ const dragProps = (isUpright, onChoose) => ({
619
+ onPointerDown: (event) => {
620
+ if (event.button !== 0)
621
+ return;
622
+ const root = event.currentTarget;
623
+ const { clientX, clientY, pointerId, pointerType } = event;
624
+ const isMouse = pointerType === 'mouse';
625
+ const slop = isMouse ? pressSlop : touchSlop;
626
+ let isDragging = false;
627
+ let under;
628
+ const listening = new AbortController();
629
+ const options = { capture: true, signal: listening.signal };
630
+ const end = () => {
631
+ listening.abort();
632
+ delete root.dataset.dragging;
633
+ };
634
+ addEventListener('pointermove', (move) => {
635
+ if (move.pointerId !== pointerId)
636
+ return;
637
+ if (!isDragging) {
638
+ const across = Math.abs(move.clientX - clientX);
639
+ const upright = Math.abs(move.clientY - clientY);
640
+ if (Math.hypot(across, upright) < slop)
641
+ return;
642
+ const along = isUpright ? upright : across;
643
+ const crossing = isUpright ? across : upright;
644
+ // (A touch across them: a scroll, let go.)
645
+ if (!isMouse && crossing > along) {
646
+ end();
647
+ return;
648
+ }
649
+ isDragging = true;
650
+ root.dataset.dragging = '';
651
+ }
652
+ // (Its nearest option chosen as it's reached.)
653
+ const next = nearestOption(root, isUpright, move);
654
+ if (!next || next === under)
655
+ return;
656
+ under = next;
657
+ const { value } = next.dataset;
658
+ if (value !== undefined && !Object.hasOwn(next.dataset, 'checked')) {
659
+ onChoose(value);
660
+ }
661
+ }, options);
662
+ addEventListener('pointerup', (up) => {
663
+ if (up.pointerId !== pointerId)
664
+ return;
665
+ end();
666
+ if (!isDragging)
667
+ return;
668
+ // (Its click next, if any: not an option's (dragged, not pressed);
669
+ // none before another press or key, nothing.)
670
+ const clicking = new AbortController();
671
+ const once = { capture: true, signal: clicking.signal };
672
+ addEventListener('click', (clicked) => {
673
+ clicking.abort();
674
+ clicked.preventDefault();
675
+ clicked.stopPropagation();
676
+ }, once);
677
+ for (const type of ['pointerdown', 'keydown']) {
678
+ addEventListener(type, () => clicking.abort(), once);
679
+ }
680
+ }, options);
681
+ addEventListener('pointercancel', (cancel) => {
682
+ if (cancel.pointerId === pointerId)
683
+ end();
684
+ }, options);
685
+ },
686
+ });
687
+ const SegmentedContext = createContext(undefined);
688
+ /**
689
+ * Its options, as they've told it (in the order they did: theirs), see
690
+ * `SegmentedItem`.
691
+ */
692
+ const useSegmentedOptions = () => {
693
+ const [options, setOptions] = useState(() => new Map());
694
+ const register = useCallback((value, info) => {
695
+ setOptions((current) => new Map(current).set(value, info));
696
+ return () => setOptions((current) => {
697
+ const next = new Map(current);
698
+ next.delete(value);
699
+ return next;
700
+ });
701
+ }, []);
702
+ return [options, register];
703
+ };
704
+ /**
705
+ * Its options' segments (a radio group, Base UI's; its options its
706
+ * children, see `SegmentedItem`): in a well, the chosen one's raised (a
707
+ * thumb, moved to it as it's chosen, by its box: its corners the well's
708
+ * less its padding, a pill while short); dragged between (see
709
+ * `dragProps`). None shown (1x1): there all the same, unseen, its options
710
+ * telling the card theirs.
711
+ */
712
+ const SegmentedChoice = ({ children, isNarrow, layout, name, onValueChange, value, }) => {
713
+ const group = useRef(null);
714
+ const isShown = layout !== 'compact';
715
+ // (Its thumb on the chosen segment, as it's chosen and as its box
716
+ // changes; moved (transitioned) once it's been placed.)
717
+ useLayoutEffect(() => {
718
+ const root = group.current;
719
+ const thumb = root?.querySelector('[data-part="thumb"]');
720
+ if (!root || !thumb || !isShown)
721
+ return undefined;
722
+ const place = () => {
723
+ placeThumb(thumb, root.querySelector('[data-checked]'));
724
+ };
725
+ place();
726
+ let frame = requestAnimationFrame(() => {
727
+ root.dataset.placed = '';
728
+ });
729
+ // (Its box changing (e.g. its card resized, opened): there at once, as
730
+ // its options are; moved only as another's chosen. Its first report
731
+ // (as it's observed, each choice: this effect's again) no change.)
732
+ let size = `${String(root.offsetWidth)}x${String(root.offsetHeight)}`;
733
+ const observer = new ResizeObserver(() => {
734
+ const next = `${String(root.offsetWidth)}x${String(root.offsetHeight)}`;
735
+ if (next === size)
736
+ return;
737
+ size = next;
738
+ cancelAnimationFrame(frame);
739
+ delete root.dataset.placed;
740
+ place();
741
+ frame = requestAnimationFrame(() => {
742
+ root.dataset.placed = '';
743
+ });
744
+ });
745
+ observer.observe(root);
746
+ // (Its options changing (added, removed, laid out anew), or another
747
+ // marked chosen (Base UI's radios a render after its value): placed
748
+ // again.)
749
+ const mutations = new MutationObserver(place);
750
+ mutations.observe(root, {
751
+ attributeFilter: ['data-checked'],
752
+ childList: true,
753
+ subtree: true,
754
+ });
755
+ return () => {
756
+ cancelAnimationFrame(frame);
757
+ observer.disconnect();
758
+ mutations.disconnect();
759
+ };
760
+ }, [isShown, layout, value]);
761
+ // (Dragged (see `dragProps`): its touch's moves not the page's, its pan
762
+ // not starting as the finger strays across its options; not passive, as
763
+ // React's listeners are.)
764
+ useLayoutEffect(() => {
765
+ const root = group.current;
766
+ if (!root)
767
+ return undefined;
768
+ const hold = (move) => {
769
+ if (Object.hasOwn(root.dataset, 'dragging') && move.cancelable) {
770
+ move.preventDefault();
771
+ }
772
+ };
773
+ root.addEventListener('touchmove', hold, { passive: false });
774
+ return () => root.removeEventListener('touchmove', hold);
775
+ }, []);
776
+ return (_jsxs(BaseRadioGroup, { ref: group, "aria-label": name, className: "uikit-control-cards-segmented-choice", "data-control-cards-part": "segmented-choice", "data-layout": layout, "data-narrow": isNarrow ? '' : undefined, hidden: !isShown, value: value, onValueChange: (next) => onValueChange(next), ...dragProps(layout === 'upright', onValueChange), children: [_jsx("span", { "aria-hidden": "true", className: "uikit-control-cards-segmented-thumb", "data-part": "thumb" }), children] }));
777
+ };
778
+ /**
779
+ * A segmented card's option (a radio, Base UI's): its symbol and its words
780
+ * (`children`), or either (its card's `optionContent`; its symbol only, its
781
+ * words unseen, its name), a subtitle under them where there's room;
782
+ * telling its card its symbol, words and tint (its value and symbol while
783
+ * it's chosen).
784
+ */
785
+ const SegmentedItem = forwardRef(({ children, className, icon, subtitle, tint, value, ...props }, ref) => {
786
+ const context = useContext(SegmentedContext);
787
+ const register = context?.register;
788
+ useLayoutEffect(() => register?.(value, { icon, label: children, tint }), [children, icon, register, tint, value]);
789
+ const content = context?.content ?? 'both';
790
+ const hasIcon = icon !== undefined && content !== 'label';
791
+ const isIconOnly = hasIcon && content === 'icon';
792
+ return (_jsxs(BaseRadio.Root, { ref: ref, ...props, className: cn('uikit-control-cards-segmented-item', className), "data-control-cards-part": "segmented-item", "data-value": value, value: value, children: [hasIcon ? _jsx(Symbol, { icon: icon }) : null, _jsxs("span", { className: "uikit-control-cards-segmented-text", "data-unseen": isIconOnly ? '' : undefined, children: [_jsx("span", { className: "uikit-control-cards-segmented-label", children: children }), context?.layout !== 'row' && subtitle !== undefined ? (_jsx("span", { className: "uikit-control-cards-segmented-subtitle", children: subtitle })) : null] })] }));
793
+ });
794
+ /**
795
+ * A device of a few modes (e.g. a heat pump's Off, Heat, Cool, Auto): its
796
+ * options (its children, `SegmentedItem`s) as segments in a well at its
797
+ * bottom (see `SegmentedChoice`), laid out by its size and orientation
798
+ * (see `useSegmentedLayout`); 1x1, its chosen option's words only, opening
799
+ * above the page to choose (`opening`). Lit while its chosen option isn't
800
+ * its `offValue`; its symbol and tint the chosen option's.
801
+ */
802
+ const SegmentedCard = forwardRef(({ children, className, defaultValue = '', emphasizedIcon, icon, name, offValue, onClick, onValueChange, opening, optionContent = 'both', orientation, tint, value, ...props }, ref) => {
803
+ const [options, register] = useSegmentedOptions();
804
+ // (None chosen at first: its first option.)
805
+ const [chosenValue, setCurrent] = useControlled(value, defaultValue);
806
+ const current = chosenValue || (options.keys().next().value ?? '');
807
+ const [layout, isNarrow] = useSegmentedLayout(orientation);
808
+ const item = useGridItem();
809
+ const chosen = options.get(current);
810
+ const isCompact = layout === 'compact';
811
+ const context = useMemo(() => ({ content: optionContent, layout, register }), [layout, optionContent, register]);
812
+ return (_jsxs(Card.Root, { ref: ref, active: offValue === undefined ? undefined : current !== offValue, ...props, className: cn('uikit-control-cards-segmented', className), "data-control-cards-part": "segmented", "data-layout": layout, onClick: onClick ??
813
+ (isCompact && opening ? () => item?.setOpen(true) : undefined), children: [_jsx(Card.Symbol, { tint: chosen?.tint ?? tint, children: chosen?.icon ? (_jsx(Symbol, { box: "square", icon: chosen.icon })) : (symbolOf({ emphasizedIcon, icon })) }), _jsx(Card.Title, { children: name }), layout === 'row' ? null : _jsx(Card.Value, { children: chosen?.label }), _jsx(SegmentedContext.Provider, { value: context, children: _jsx(SegmentedChoice, { isNarrow: isNarrow, layout: layout, name: name, value: current, onValueChange: (next) => {
814
+ setCurrent(next);
815
+ onValueChange?.(next);
816
+ }, children: children }) }), opening ? (_jsxs(_Fragment, { children: [_jsx(Card.CornerButton, { "aria-label": opening.label, icon: gridIcons.open, visible: isCompact && item?.open !== true, onClick: () => item?.setOpen(true) }), _jsx(Card.CornerButton, { "aria-label": opening.closeLabel, corner: "top-trailing", icon: gridIcons.close, visible: item?.open === true, onClick: () => item?.setOpen(false) })] })) : null] }));
817
+ });
818
+ export const ControlCards = {
819
+ State,
820
+ Switch: SwitchCard,
821
+ Value,
822
+ Slider: SliderCard,
823
+ SliderFill,
824
+ Button,
825
+ Progress: ProgressCard,
826
+ Light,
827
+ List: ListCard,
828
+ Segmented: SegmentedCard,
829
+ SegmentedItem,
830
+ Channels,
831
+ Trend,
832
+ ExpandButton,
833
+ OpenButtons,
834
+ };
835
+ //# sourceMappingURL=main.js.map