@robert-stackflow/oneui 0.0.0-stage → 0.1.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 (367) hide show
  1. package/README.md +45 -2
  2. package/assets/LUCIDE-LICENSE.txt +43 -0
  3. package/assets/character-metadata.json +1 -0
  4. package/assets/emoji.json +1 -0
  5. package/assets/icon-catalog.json +1 -0
  6. package/assets/symbols.json +1 -0
  7. package/components/Accessibility.module.css +8 -0
  8. package/components/Accordion.d.ts +7 -0
  9. package/components/Accordion.js +41 -0
  10. package/components/Accordion.module.css +38 -0
  11. package/components/Alert.d.ts +9 -0
  12. package/components/Alert.js +42 -0
  13. package/components/Alert.module.css +56 -0
  14. package/components/AppShell.d.ts +30 -0
  15. package/components/AppShell.js +152 -0
  16. package/components/AppShell.module.css +239 -0
  17. package/components/AppearanceSettings.d.ts +7 -0
  18. package/components/AppearanceSettings.js +201 -0
  19. package/components/AppearanceSettings.module.css +32 -0
  20. package/components/Avatar.d.ts +14 -0
  21. package/components/Avatar.js +69 -0
  22. package/components/Avatar.module.css +70 -0
  23. package/components/AvatarGroup.d.ts +15 -0
  24. package/components/AvatarGroup.js +115 -0
  25. package/components/AvatarGroup.module.css +54 -0
  26. package/components/Badge.d.ts +5 -0
  27. package/components/Badge.js +11 -0
  28. package/components/Badge.module.css +30 -0
  29. package/components/BlockedTab.d.ts +4 -0
  30. package/components/BlockedTab.js +10 -0
  31. package/components/Breadcrumb.d.ts +16 -0
  32. package/components/Breadcrumb.js +157 -0
  33. package/components/Breadcrumb.module.css +97 -0
  34. package/components/Button.d.ts +6 -0
  35. package/components/Button.js +29 -0
  36. package/components/Button.module.css +79 -0
  37. package/components/Calendar.d.ts +10 -0
  38. package/components/Calendar.js +260 -0
  39. package/components/Calendar.module.css +106 -0
  40. package/components/Card.d.ts +7 -0
  41. package/components/Card.js +19 -0
  42. package/components/Card.module.css +28 -0
  43. package/components/Cascader.d.ts +14 -0
  44. package/components/Cascader.js +296 -0
  45. package/components/CatalogIcon.d.ts +3 -0
  46. package/components/CatalogIcon.js +11 -0
  47. package/components/CharacterPicker.d.ts +15 -0
  48. package/components/CharacterPicker.js +200 -0
  49. package/components/Checkbox.d.ts +12 -0
  50. package/components/Checkbox.js +82 -0
  51. package/components/Checkbox.module.css +95 -0
  52. package/components/ColorField.d.ts +6 -0
  53. package/components/ColorField.js +61 -0
  54. package/components/ColorField.module.css +15 -0
  55. package/components/ColorPicker.d.ts +5 -0
  56. package/components/ColorPicker.js +188 -0
  57. package/components/ColorPicker.module.css +90 -0
  58. package/components/Combobox.d.ts +11 -0
  59. package/components/Combobox.js +252 -0
  60. package/components/Combobox.module.css +26 -0
  61. package/components/CommandPalette.d.ts +25 -0
  62. package/components/CommandPalette.js +269 -0
  63. package/components/CommandPalette.module.css +49 -0
  64. package/components/ContextMenu.d.ts +9 -0
  65. package/components/ContextMenu.js +363 -0
  66. package/components/ContextMenu.module.css +42 -0
  67. package/components/ContextMenuPanel.d.ts +22 -0
  68. package/components/ContextMenuPanel.js +155 -0
  69. package/components/ContributionCalendar.d.ts +18 -0
  70. package/components/ContributionCalendar.js +201 -0
  71. package/components/ContributionCalendar.module.css +114 -0
  72. package/components/ContributionCell.d.ts +11 -0
  73. package/components/ContributionCell.js +41 -0
  74. package/components/Control.module.css +73 -0
  75. package/components/DataTable.d.ts +49 -0
  76. package/components/DataTable.js +220 -0
  77. package/components/DataTable.module.css +112 -0
  78. package/components/DatePicker.d.ts +15 -0
  79. package/components/DatePicker.js +186 -0
  80. package/components/DatePicker.module.css +85 -0
  81. package/components/DateRangePicker.d.ts +9 -0
  82. package/components/DateRangePicker.js +168 -0
  83. package/components/Descriptions.d.ts +21 -0
  84. package/components/Descriptions.js +162 -0
  85. package/components/Descriptions.module.css +117 -0
  86. package/components/Dialog.d.ts +9 -0
  87. package/components/Dialog.js +112 -0
  88. package/components/Dialog.module.css +71 -0
  89. package/components/DisclosureChevron.d.ts +3 -0
  90. package/components/DisclosureChevron.js +17 -0
  91. package/components/DisclosureChevron.module.css +17 -0
  92. package/components/Divider.d.ts +5 -0
  93. package/components/Divider.js +24 -0
  94. package/components/Divider.module.css +19 -0
  95. package/components/Drawer.d.ts +18 -0
  96. package/components/Drawer.js +145 -0
  97. package/components/Drawer.module.css +109 -0
  98. package/components/EmojiPicker.d.ts +6 -0
  99. package/components/EmojiPicker.js +19 -0
  100. package/components/EmptyState.d.ts +8 -0
  101. package/components/EmptyState.js +20 -0
  102. package/components/EmptyState.module.css +30 -0
  103. package/components/FieldLabel.d.ts +8 -0
  104. package/components/FieldLabel.js +20 -0
  105. package/components/FieldMessages.d.ts +5 -0
  106. package/components/FieldMessages.js +15 -0
  107. package/components/FileDropOverlay.d.ts +5 -0
  108. package/components/FileDropOverlay.js +26 -0
  109. package/components/FileDropOverlay.module.css +55 -0
  110. package/components/FileDropZone.d.ts +15 -0
  111. package/components/FileDropZone.js +113 -0
  112. package/components/FileDropZone.module.css +6 -0
  113. package/components/FilePicker.d.ts +10 -0
  114. package/components/FilePicker.js +59 -0
  115. package/components/FileSelectionFeedback.d.ts +5 -0
  116. package/components/FileSelectionFeedback.js +23 -0
  117. package/components/FileSelectionFeedback.module.css +14 -0
  118. package/components/FileTree.d.ts +13 -0
  119. package/components/FileTree.js +125 -0
  120. package/components/FileTree.module.css +66 -0
  121. package/components/Form.d.ts +7 -0
  122. package/components/Form.js +26 -0
  123. package/components/Form.module.css +7 -0
  124. package/components/FormErrorSummary.d.ts +6 -0
  125. package/components/FormErrorSummary.js +27 -0
  126. package/components/FormErrorSummary.module.css +27 -0
  127. package/components/FormField.d.ts +9 -0
  128. package/components/FormField.js +59 -0
  129. package/components/FormField.module.css +85 -0
  130. package/components/FormGroup.d.ts +9 -0
  131. package/components/FormGroup.js +32 -0
  132. package/components/HierarchyPicker.module.css +146 -0
  133. package/components/IconButton.d.ts +7 -0
  134. package/components/IconButton.js +30 -0
  135. package/components/IconButton.module.css +39 -0
  136. package/components/IconPicker.d.ts +6 -0
  137. package/components/IconPicker.js +111 -0
  138. package/components/Indicator.d.ts +18 -0
  139. package/components/Indicator.js +97 -0
  140. package/components/Indicator.module.css +83 -0
  141. package/components/Input.d.ts +7 -0
  142. package/components/Input.js +29 -0
  143. package/components/Input.module.css +23 -0
  144. package/components/LoadingOverlay.d.ts +6 -0
  145. package/components/LoadingOverlay.js +16 -0
  146. package/components/LoadingOverlay.module.css +22 -0
  147. package/components/LoadingState.d.ts +5 -0
  148. package/components/LoadingState.js +29 -0
  149. package/components/LoadingState.module.css +14 -0
  150. package/components/Menu.d.ts +11 -0
  151. package/components/Menu.js +82 -0
  152. package/components/MenuItem.d.ts +14 -0
  153. package/components/MenuItem.js +49 -0
  154. package/components/MenuItem.module.css +163 -0
  155. package/components/MenuItemContent.d.ts +8 -0
  156. package/components/MenuItemContent.js +19 -0
  157. package/components/MultiSelect.d.ts +12 -0
  158. package/components/MultiSelect.js +161 -0
  159. package/components/MultiSelect.module.css +61 -0
  160. package/components/NumberInput.d.ts +12 -0
  161. package/components/NumberInput.js +113 -0
  162. package/components/NumberInput.module.css +33 -0
  163. package/components/Page.d.ts +7 -0
  164. package/components/Page.js +22 -0
  165. package/components/Page.module.css +44 -0
  166. package/components/Pagination.d.ts +11 -0
  167. package/components/Pagination.js +160 -0
  168. package/components/Pagination.module.css +70 -0
  169. package/components/PasswordField.d.ts +9 -0
  170. package/components/PasswordField.js +101 -0
  171. package/components/PasswordField.module.css +64 -0
  172. package/components/Picker.module.css +52 -0
  173. package/components/PinInput.d.ts +13 -0
  174. package/components/PinInput.js +172 -0
  175. package/components/PinInput.module.css +72 -0
  176. package/components/Placeholder.d.ts +31 -0
  177. package/components/Placeholder.js +36 -0
  178. package/components/Popconfirm.d.ts +17 -0
  179. package/components/Popconfirm.js +159 -0
  180. package/components/Popconfirm.module.css +49 -0
  181. package/components/Popover.d.ts +13 -0
  182. package/components/Popover.js +150 -0
  183. package/components/Popover.module.css +16 -0
  184. package/components/Progress.d.ts +5 -0
  185. package/components/Progress.js +31 -0
  186. package/components/Progress.module.css +33 -0
  187. package/components/RadioGroup.d.ts +15 -0
  188. package/components/RadioGroup.js +73 -0
  189. package/components/RadioGroup.module.css +87 -0
  190. package/components/RangeSlider.d.ts +22 -0
  191. package/components/RangeSlider.js +278 -0
  192. package/components/RangeSlider.module.css +141 -0
  193. package/components/ResizablePanel.d.ts +21 -0
  194. package/components/ResizablePanel.js +219 -0
  195. package/components/ResizablePanel.module.css +101 -0
  196. package/components/SearchField.d.ts +11 -0
  197. package/components/SearchField.js +66 -0
  198. package/components/SearchField.module.css +37 -0
  199. package/components/Section.d.ts +6 -0
  200. package/components/Section.js +18 -0
  201. package/components/Section.module.css +14 -0
  202. package/components/Segmented.d.ts +11 -0
  203. package/components/Segmented.js +77 -0
  204. package/components/Segmented.module.css +82 -0
  205. package/components/Select.d.ts +11 -0
  206. package/components/Select.js +171 -0
  207. package/components/Select.module.css +21 -0
  208. package/components/SelectOptionContent.d.ts +5 -0
  209. package/components/SelectOptionContent.js +20 -0
  210. package/components/SelectOptionContent.module.css +7 -0
  211. package/components/SelectTrigger.d.ts +5 -0
  212. package/components/SelectTrigger.js +32 -0
  213. package/components/SelectTrigger.module.css +24 -0
  214. package/components/SettingRow.d.ts +7 -0
  215. package/components/SettingRow.js +19 -0
  216. package/components/SettingRow.module.css +44 -0
  217. package/components/SettingsLayout.d.ts +9 -0
  218. package/components/SettingsLayout.js +45 -0
  219. package/components/SettingsLayout.module.css +48 -0
  220. package/components/ShortcutInput.d.ts +8 -0
  221. package/components/ShortcutInput.js +131 -0
  222. package/components/ShortcutInput.module.css +39 -0
  223. package/components/Skeleton.d.ts +5 -0
  224. package/components/Skeleton.js +19 -0
  225. package/components/Skeleton.module.css +27 -0
  226. package/components/SkeletonRows.d.ts +4 -0
  227. package/components/SkeletonRows.js +19 -0
  228. package/components/SkeletonRows.module.css +19 -0
  229. package/components/SkinTonePicker.d.ts +4 -0
  230. package/components/SkinTonePicker.js +43 -0
  231. package/components/SkinTonePicker.module.css +50 -0
  232. package/components/Slider.d.ts +10 -0
  233. package/components/Slider.js +40 -0
  234. package/components/Slider.module.css +19 -0
  235. package/components/Spinner.d.ts +6 -0
  236. package/components/Spinner.js +31 -0
  237. package/components/Spinner.module.css +57 -0
  238. package/components/SplitButton.d.ts +17 -0
  239. package/components/SplitButton.js +102 -0
  240. package/components/SplitButton.module.css +56 -0
  241. package/components/Statistic.d.ts +22 -0
  242. package/components/Statistic.js +102 -0
  243. package/components/Statistic.module.css +55 -0
  244. package/components/Steps.d.ts +19 -0
  245. package/components/Steps.js +102 -0
  246. package/components/Steps.module.css +176 -0
  247. package/components/Switch.d.ts +6 -0
  248. package/components/Switch.js +25 -0
  249. package/components/Switch.module.css +56 -0
  250. package/components/SymbolPicker.d.ts +6 -0
  251. package/components/SymbolPicker.js +18 -0
  252. package/components/Tab.module.css +145 -0
  253. package/components/TabList.d.ts +11 -0
  254. package/components/TabList.js +51 -0
  255. package/components/Table.d.ts +12 -0
  256. package/components/Table.js +20 -0
  257. package/components/Table.module.css +48 -0
  258. package/components/TableColumnFilter.d.ts +6 -0
  259. package/components/TableColumnFilter.js +76 -0
  260. package/components/TableColumnVisibility.d.ts +11 -0
  261. package/components/TableColumnVisibility.js +76 -0
  262. package/components/Tabs.d.ts +13 -0
  263. package/components/Tabs.js +49 -0
  264. package/components/Tabs.module.css +3 -0
  265. package/components/TagInput.d.ts +11 -0
  266. package/components/TagInput.js +154 -0
  267. package/components/TagInput.module.css +64 -0
  268. package/components/Textarea.d.ts +6 -0
  269. package/components/Textarea.js +24 -0
  270. package/components/Textarea.module.css +9 -0
  271. package/components/ThemePicker.d.ts +6 -0
  272. package/components/ThemePicker.js +78 -0
  273. package/components/ThemePicker.module.css +178 -0
  274. package/components/ThemeProvider.d.ts +11 -0
  275. package/components/ThemeProvider.js +80 -0
  276. package/components/ThemeStylePicker.d.ts +5 -0
  277. package/components/ThemeStylePicker.js +22 -0
  278. package/components/TimeColumns.d.ts +6 -0
  279. package/components/TimeColumns.js +55 -0
  280. package/components/TimeColumns.module.css +47 -0
  281. package/components/Timeline.d.ts +26 -0
  282. package/components/Timeline.js +131 -0
  283. package/components/Timeline.module.css +202 -0
  284. package/components/Toast.d.ts +6 -0
  285. package/components/Toast.js +181 -0
  286. package/components/Toast.module.css +175 -0
  287. package/components/ToastProvider.d.ts +35 -0
  288. package/components/ToastProvider.js +47 -0
  289. package/components/Tooltip.d.ts +10 -0
  290. package/components/Tooltip.js +169 -0
  291. package/components/Tooltip.module.css +53 -0
  292. package/components/TreeSelect.d.ts +23 -0
  293. package/components/TreeSelect.js +309 -0
  294. package/components/UIProvider.d.ts +10 -0
  295. package/components/UIProvider.js +20 -0
  296. package/components/UnderlinedTab.d.ts +2 -0
  297. package/components/UnderlinedTab.js +8 -0
  298. package/components/Upload.d.ts +22 -0
  299. package/components/Upload.js +165 -0
  300. package/components/Upload.module.css +36 -0
  301. package/components/UploadList.d.ts +9 -0
  302. package/components/UploadList.js +14 -0
  303. package/components/UploadList.module.css +130 -0
  304. package/components/UploadListItem.d.ts +13 -0
  305. package/components/UploadListItem.js +122 -0
  306. package/components/VirtualPickerList.d.ts +25 -0
  307. package/components/VirtualPickerList.js +269 -0
  308. package/components/VirtualPickerList.module.css +89 -0
  309. package/components/appearance.d.ts +19 -0
  310. package/components/appearance.js +60 -0
  311. package/components/characterCatalog.d.ts +9 -0
  312. package/components/characterCatalog.js +55 -0
  313. package/components/color.d.ts +7 -0
  314. package/components/color.js +18 -0
  315. package/components/contribution.d.ts +57 -0
  316. package/components/contribution.js +86 -0
  317. package/components/dateConstraints.d.ts +13 -0
  318. package/components/dateConstraints.js +44 -0
  319. package/components/field.d.ts +58 -0
  320. package/components/field.js +57 -0
  321. package/components/fileSelection.d.ts +21 -0
  322. package/components/fileSelection.js +43 -0
  323. package/components/hierarchy.d.ts +22 -0
  324. package/components/hierarchy.js +33 -0
  325. package/components/iconCatalog.d.ts +13 -0
  326. package/components/iconCatalog.js +80 -0
  327. package/components/index.d.ts +150 -0
  328. package/components/index.js +219 -0
  329. package/components/menuFocus.d.ts +7 -0
  330. package/components/menuFocus.js +21 -0
  331. package/components/menuPointer.d.ts +6 -0
  332. package/components/menuPointer.js +13 -0
  333. package/components/menuTypes.d.ts +24 -0
  334. package/components/menuTypes.js +0 -0
  335. package/components/motion.d.ts +9 -0
  336. package/components/motion.js +82 -0
  337. package/components/rangeMath.d.ts +12 -0
  338. package/components/rangeMath.js +30 -0
  339. package/components/surfacePortal.d.ts +13 -0
  340. package/components/surfacePortal.js +22 -0
  341. package/components/tooltipState.d.ts +5 -0
  342. package/components/tooltipState.js +48 -0
  343. package/components/types.d.ts +9 -0
  344. package/components/types.js +0 -0
  345. package/components/uploadTypes.d.ts +21 -0
  346. package/components/uploadTypes.js +0 -0
  347. package/components/useFormState.d.ts +51 -0
  348. package/components/useFormState.js +218 -0
  349. package/components/useHierarchy.d.ts +8 -0
  350. package/components/useHierarchy.js +80 -0
  351. package/components/useMenuLayers.d.ts +17 -0
  352. package/components/useMenuLayers.js +23 -0
  353. package/components/useModalScrollLock.d.ts +1 -0
  354. package/components/useModalScrollLock.js +18 -0
  355. package/components/usePopover.d.ts +8 -0
  356. package/components/usePopover.js +22 -0
  357. package/components/useTabIndicator.d.ts +12 -0
  358. package/components/useTabIndicator.js +63 -0
  359. package/components/useUploadQueue.d.ts +20 -0
  360. package/components/useUploadQueue.js +175 -0
  361. package/package.json +783 -3
  362. package/styles/base.css +189 -0
  363. package/styles/blue.css +254 -0
  364. package/styles/desktop.css +2 -0
  365. package/styles/minimal.css +337 -0
  366. package/styles/themes.css +2 -0
  367. package/styles/web.css +2 -0
@@ -0,0 +1,278 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef } from "react";
3
+ import { Tooltip } from "./Tooltip.js";
4
+ import { useFieldControl } from "./field.js";
5
+ import { moveRange, rangeSettings } from "./rangeMath.js";
6
+ import s from "./RangeSlider.module.css";
7
+ function RangeSlider({
8
+ label,
9
+ value,
10
+ onChange,
11
+ onChangeEnd,
12
+ min = 0,
13
+ max = 100,
14
+ step = 1,
15
+ minDistance = 0,
16
+ lowerLabel,
17
+ upperLabel,
18
+ formatValue = String,
19
+ marks = [],
20
+ tooltip = true,
21
+ ...options
22
+ }) {
23
+ const field = useFieldControl({ ...options, label }), settings = rangeSettings(min, max, step, minDistance), pair = settings.normalize(value), blocked = field.disabled || field.readOnly || !settings.count, rail = useRef(null), thumbs = useRef([]), current = useRef(pair), drag = useRef(null), keys = useRef(null), last = useRef(0), callbacks = useRef({ onChange, onChangeEnd });
24
+ current.current = pair;
25
+ callbacks.current = { onChange, onChangeEnd };
26
+ const emit = (next) => {
27
+ if (next[0] === current.current[0] && next[1] === current.current[1])
28
+ return;
29
+ current.current = next;
30
+ callbacks.current.onChange(next);
31
+ };
32
+ const finishKeys = () => {
33
+ const start = keys.current;
34
+ keys.current = null;
35
+ if (start && (start[0] !== current.current[0] || start[1] !== current.current[1]))
36
+ callbacks.current.onChangeEnd?.([...current.current]);
37
+ };
38
+ const stop = (cancel = false) => {
39
+ const active = drag.current;
40
+ if (!active) return;
41
+ drag.current = null;
42
+ if (active?.blur) window.removeEventListener("blur", active.blur);
43
+ rail.current?.removeAttribute("data-dragging");
44
+ if (rail.current?.hasPointerCapture(active.id))
45
+ rail.current.releasePointerCapture(active.id);
46
+ if (cancel) emit(active.start);
47
+ else if (active.start[0] !== current.current[0] || active.start[1] !== current.current[1])
48
+ callbacks.current.onChangeEnd?.([...current.current]);
49
+ };
50
+ const point = (clientX, index, offset = 0) => {
51
+ const box = rail.current?.getBoundingClientRect();
52
+ if (!box?.width) return;
53
+ const target = settings.min + Math.max(0, Math.min(1, (clientX - offset - box.left) / box.width)) * (settings.max - settings.min);
54
+ emit(moveRange(current.current, index, target, settings));
55
+ };
56
+ useEffect(() => {
57
+ if (drag.current) {
58
+ const active = drag.current;
59
+ drag.current = null;
60
+ if (active?.blur) window.removeEventListener("blur", active.blur);
61
+ rail.current?.removeAttribute("data-dragging");
62
+ if (rail.current?.hasPointerCapture(active.id))
63
+ rail.current.releasePointerCapture(active.id);
64
+ }
65
+ keys.current = null;
66
+ }, [min, max, step, minDistance, blocked]);
67
+ useEffect(
68
+ () => () => {
69
+ const active = drag.current;
70
+ drag.current = null;
71
+ if (active?.blur) window.removeEventListener("blur", active.blur);
72
+ if (active && rail.current?.hasPointerCapture(active.id))
73
+ rail.current.releasePointerCapture(active.id);
74
+ },
75
+ []
76
+ );
77
+ const percent = (amount) => settings.count ? (amount - settings.min) / (settings.max - settings.min) * 100 : 0;
78
+ return /* @__PURE__ */ jsxs(
79
+ "div",
80
+ {
81
+ id: field.id,
82
+ role: "group",
83
+ "aria-label": label,
84
+ tabIndex: -1,
85
+ className: s.field,
86
+ "data-disabled": field.disabled || !settings.count,
87
+ "aria-invalid": field.invalid,
88
+ "aria-describedby": field.descriptionId,
89
+ onFocus: (event) => {
90
+ if (event.target === event.currentTarget) thumbs.current[0]?.focus();
91
+ },
92
+ children: [
93
+ /* @__PURE__ */ jsxs("div", { className: s.label, children: [
94
+ /* @__PURE__ */ jsx("span", { children: label }),
95
+ /* @__PURE__ */ jsxs("span", { "aria-hidden": "true", children: [
96
+ formatValue(pair[0]),
97
+ " \u2014 ",
98
+ formatValue(pair[1])
99
+ ] })
100
+ ] }),
101
+ /* @__PURE__ */ jsxs(
102
+ "div",
103
+ {
104
+ className: s.rail,
105
+ "data-range-track": true,
106
+ ref: rail,
107
+ onPointerDown: (event) => {
108
+ if (blocked || event.button !== 0 || !event.isPrimary) return;
109
+ event.preventDefault();
110
+ finishKeys();
111
+ const box = event.currentTarget.getBoundingClientRect(), target = event.target.closest(
112
+ '[role="slider"]'
113
+ ), amount = settings.min + (event.clientX - box.left) / box.width * (settings.max - settings.min), index = target ? Number(target.dataset.thumb) : Math.abs(amount - pair[0]) === Math.abs(amount - pair[1]) ? pair[0] === pair[1] && amount !== pair[0] ? amount > pair[0] ? 1 : 0 : last.current : Math.abs(amount - pair[0]) < Math.abs(amount - pair[1]) ? 0 : 1, offset = target ? event.clientX - (box.left + percent(pair[index]) / 100 * box.width) : 0;
114
+ last.current = index;
115
+ const blur = () => stop(true);
116
+ drag.current = {
117
+ id: event.pointerId,
118
+ index,
119
+ start: [...current.current],
120
+ offset,
121
+ blur
122
+ };
123
+ window.addEventListener("blur", blur, { once: true });
124
+ event.currentTarget.setPointerCapture(event.pointerId);
125
+ event.currentTarget.dataset.dragging = "true";
126
+ thumbs.current[index]?.focus({ preventScroll: true });
127
+ point(event.clientX, index, offset);
128
+ },
129
+ onPointerMove: (event) => {
130
+ if (drag.current?.id === event.pointerId)
131
+ point(event.clientX, drag.current.index, drag.current.offset);
132
+ },
133
+ onPointerUp: (event) => {
134
+ if (drag.current?.id === event.pointerId) stop();
135
+ },
136
+ onPointerCancel: () => stop(true),
137
+ onLostPointerCapture: () => stop(true),
138
+ onKeyDown: (event) => {
139
+ if (event.key === "Escape" && drag.current) {
140
+ event.preventDefault();
141
+ event.stopPropagation();
142
+ stop(true);
143
+ }
144
+ },
145
+ children: [
146
+ /* @__PURE__ */ jsx("div", { className: s.track }),
147
+ /* @__PURE__ */ jsx(
148
+ "div",
149
+ {
150
+ className: s.fill,
151
+ style: {
152
+ left: percent(pair[0]) + "%",
153
+ width: percent(pair[1]) - percent(pair[0]) + "%"
154
+ }
155
+ }
156
+ ),
157
+ [0, 1].map((index) => {
158
+ const handle = /* @__PURE__ */ jsx(
159
+ "div",
160
+ {
161
+ ref: (node) => {
162
+ thumbs.current[index] = node;
163
+ },
164
+ role: "slider",
165
+ "data-thumb": index,
166
+ tabIndex: field.disabled || !settings.count ? -1 : 0,
167
+ className: s.thumb,
168
+ "aria-label": index === 0 ? lowerLabel || `${label}\u4E0B\u9650` : upperLabel || `${label}\u4E0A\u9650`,
169
+ "aria-valuemin": index === 0 ? settings.min : settings.toValue(settings.indexOf(pair[0]) + settings.gap),
170
+ "aria-valuemax": index === 0 ? settings.toValue(settings.indexOf(pair[1]) - settings.gap) : settings.max,
171
+ "aria-valuenow": pair[index],
172
+ "aria-valuetext": formatValue(pair[index]),
173
+ "aria-disabled": field.disabled || !settings.count || void 0,
174
+ "aria-readonly": field.readOnly || void 0,
175
+ "aria-invalid": field.invalid,
176
+ "aria-describedby": field.descriptionId,
177
+ onFocus: () => {
178
+ last.current = index;
179
+ },
180
+ onBlur: finishKeys,
181
+ onKeyDown: (event) => {
182
+ if (blocked) return;
183
+ let target;
184
+ const direction = {
185
+ ArrowRight: 1,
186
+ ArrowUp: 1,
187
+ ArrowLeft: -1,
188
+ ArrowDown: -1,
189
+ PageUp: 10,
190
+ PageDown: -10
191
+ }[event.key];
192
+ if (direction)
193
+ target = current.current[index] + direction * settings.step;
194
+ else if (event.key === "Home") target = settings.min;
195
+ else if (event.key === "End") target = settings.max;
196
+ else return;
197
+ event.preventDefault();
198
+ event.stopPropagation();
199
+ keys.current ??= [...current.current];
200
+ emit(moveRange(current.current, index, target, settings));
201
+ },
202
+ onKeyUp: (event) => {
203
+ if ([
204
+ "ArrowRight",
205
+ "ArrowLeft",
206
+ "ArrowUp",
207
+ "ArrowDown",
208
+ "PageUp",
209
+ "PageDown",
210
+ "Home",
211
+ "End"
212
+ ].includes(event.key))
213
+ finishKeys();
214
+ }
215
+ }
216
+ );
217
+ return /* @__PURE__ */ jsx(
218
+ "div",
219
+ {
220
+ className: s.anchor,
221
+ style: {
222
+ left: percent(pair[index]) + "%",
223
+ zIndex: last.current === index ? 2 : 1
224
+ },
225
+ children: tooltip ? /* @__PURE__ */ jsx(Tooltip, { content: formatValue(pair[index]), children: handle }) : handle
226
+ },
227
+ index
228
+ );
229
+ })
230
+ ]
231
+ }
232
+ ),
233
+ !!marks.length && /* @__PURE__ */ jsx("div", { className: s.marks, "aria-hidden": "true", children: marks.map((mark, index) => {
234
+ const item = typeof mark === "number" ? { value: mark } : mark;
235
+ if (!Number.isFinite(item.value) || item.value < settings.min || item.value > settings.max)
236
+ return null;
237
+ const position = percent(item.value);
238
+ return /* @__PURE__ */ jsxs(
239
+ "span",
240
+ {
241
+ className: s.mark,
242
+ "data-edge": position === 0 ? "start" : position === 100 ? "end" : void 0,
243
+ style: { left: position + "%" },
244
+ children: [
245
+ /* @__PURE__ */ jsx("i", {}),
246
+ item.label ?? formatValue(item.value)
247
+ ]
248
+ },
249
+ index
250
+ );
251
+ }) }),
252
+ field.name && /* @__PURE__ */ jsxs(Fragment, { children: [
253
+ /* @__PURE__ */ jsx(
254
+ "input",
255
+ {
256
+ type: "hidden",
257
+ name: `${field.name}.min`,
258
+ value: pair[0],
259
+ disabled: field.disabled
260
+ }
261
+ ),
262
+ /* @__PURE__ */ jsx(
263
+ "input",
264
+ {
265
+ type: "hidden",
266
+ name: `${field.name}.max`,
267
+ value: pair[1],
268
+ disabled: field.disabled
269
+ }
270
+ )
271
+ ] })
272
+ ]
273
+ }
274
+ );
275
+ }
276
+ export {
277
+ RangeSlider
278
+ };
@@ -0,0 +1,141 @@
1
+ .field {
2
+ min-width: 0;
3
+ outline: none;
4
+ }
5
+ .label {
6
+ display: flex;
7
+ align-items: center;
8
+ justify-content: space-between;
9
+ gap: 12px;
10
+ font-size: 12px;
11
+ line-height: 20px;
12
+ margin-bottom: 12px;
13
+ }
14
+ .label > span:last-child {
15
+ color: var(--muted);
16
+ font-variant-numeric: tabular-nums;
17
+ white-space: nowrap;
18
+ }
19
+ .rail {
20
+ position: relative;
21
+ height: 24px;
22
+ margin: 0 9px;
23
+ touch-action: none;
24
+ cursor: pointer;
25
+ }
26
+ .track,
27
+ .fill {
28
+ position: absolute;
29
+ top: 10px;
30
+ height: 4px;
31
+ border-radius: 3px;
32
+ pointer-events: none;
33
+ }
34
+ .track {
35
+ inset-inline: 0;
36
+ background: var(--line);
37
+ }
38
+ .fill {
39
+ background: var(--accent);
40
+ transition:
41
+ left var(--motion-hover) var(--ease),
42
+ width var(--motion-hover) var(--ease);
43
+ }
44
+ .anchor {
45
+ position: absolute;
46
+ top: 50%;
47
+ transform: translate(-50%, -50%);
48
+ height: 18px;
49
+ width: 18px;
50
+ transition: left var(--motion-hover) var(--ease);
51
+ }
52
+ .thumb {
53
+ display: block;
54
+ width: 18px;
55
+ height: 18px;
56
+ background: var(--field);
57
+ border: 1px solid color-mix(in srgb, var(--fg) 28%, var(--surface));
58
+ border-radius: 50%;
59
+ box-shadow: var(--shadow-sm);
60
+ outline: none;
61
+ cursor: grab;
62
+ transition:
63
+ border-color var(--motion-hover),
64
+ box-shadow var(--motion-hover),
65
+ background-color var(--motion-hover);
66
+ }
67
+ .thumb:hover {
68
+ border-color: var(--accent);
69
+ }
70
+ .thumb:focus,
71
+ .thumb:focus-visible {
72
+ outline: none;
73
+ border-color: color-mix(in srgb, var(--accent) 60%, var(--surface));
74
+ box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 12%, transparent);
75
+ }
76
+ .rail[data-dragging="true"] .thumb {
77
+ cursor: grabbing;
78
+ }
79
+ .rail[data-dragging="true"] :is(.anchor, .fill) {
80
+ transition: none;
81
+ }
82
+ .field[data-disabled="true"] {
83
+ opacity: 0.45;
84
+ }
85
+ .field[data-disabled="true"] :is(.rail, .thumb) {
86
+ cursor: not-allowed;
87
+ }
88
+ .field[aria-invalid="true"] .thumb {
89
+ border-color: var(--danger);
90
+ }
91
+ .field[aria-invalid="true"] .thumb:focus {
92
+ box-shadow: 0 0 0 2px color-mix(in srgb, var(--danger) 12%, transparent);
93
+ }
94
+ .marks {
95
+ position: relative;
96
+ height: 24px;
97
+ margin: 0 9px;
98
+ font-size: 10px;
99
+ color: var(--muted);
100
+ }
101
+ .mark {
102
+ position: absolute;
103
+ top: 0;
104
+ max-width: 33%;
105
+ transform: translateX(-50%);
106
+ white-space: nowrap;
107
+ overflow: hidden;
108
+ text-overflow: ellipsis;
109
+ padding-top: 8px;
110
+ }
111
+ .mark > i {
112
+ position: absolute;
113
+ top: 0;
114
+ left: 50%;
115
+ height: 4px;
116
+ width: 1px;
117
+ background: var(--line);
118
+ }
119
+ .mark[data-edge="start"] {
120
+ transform: none;
121
+ }
122
+ .mark[data-edge="start"] > i {
123
+ left: 0;
124
+ }
125
+ .mark[data-edge="end"] {
126
+ transform: translateX(-100%);
127
+ }
128
+ .mark[data-edge="end"] > i {
129
+ left: auto;
130
+ right: 0;
131
+ }
132
+ @media (prefers-reduced-motion: reduce) {
133
+ .anchor,
134
+ .fill {
135
+ transition: none;
136
+ }
137
+ }
138
+
139
+ .anchor:focus-within {
140
+ z-index: 3 !important;
141
+ }
@@ -0,0 +1,21 @@
1
+ import { type CSSProperties, type ReactNode } from "react";
2
+ export type ResizablePanelProps = {
3
+ children: [ReactNode, ReactNode];
4
+ direction?: "horizontal" | "vertical";
5
+ value?: number;
6
+ defaultValue?: number;
7
+ onChange?(value: number): void;
8
+ min?: number;
9
+ max?: number;
10
+ step?: number;
11
+ collapsible?: boolean;
12
+ disabled?: boolean;
13
+ primaryLabel?: string;
14
+ secondaryLabel?: string;
15
+ label?: string;
16
+ onResizeStart?(): void;
17
+ onResizeEnd?(value: number): void;
18
+ className?: string;
19
+ style?: CSSProperties;
20
+ };
21
+ export declare function ResizablePanel({ children, direction, value, defaultValue, onChange, min, max, step, collapsible, disabled, primaryLabel, secondaryLabel, label, onResizeStart, onResizeEnd, className, style, }: ResizablePanelProps): import("react").JSX.Element;
@@ -0,0 +1,219 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import {
3
+ useCallback,
4
+ useEffect,
5
+ useId,
6
+ useRef,
7
+ useState
8
+ } from "react";
9
+ import s from "./ResizablePanel.module.css";
10
+ const finite = (value, fallback) => Number.isFinite(value) ? value : fallback;
11
+ function ResizablePanel({
12
+ children,
13
+ direction = "horizontal",
14
+ value,
15
+ defaultValue = 35,
16
+ onChange,
17
+ min = 15,
18
+ max = 85,
19
+ step = 1,
20
+ collapsible = false,
21
+ disabled = false,
22
+ primaryLabel = "\u4E3B\u9762\u677F",
23
+ secondaryLabel = "\u6B21\u9762\u677F",
24
+ label = "\u53EF\u8C03\u6574\u9762\u677F",
25
+ onResizeStart,
26
+ onResizeEnd,
27
+ className = "",
28
+ style
29
+ }) {
30
+ const low = Math.max(0, Math.min(100, finite(min, 15))), high = Math.max(low, Math.min(100, finite(max, 85)));
31
+ const clamp = (number) => collapsible && number <= 0 ? 0 : Math.max(low, Math.min(high, finite(number, finite(defaultValue, 35))));
32
+ const [local, setLocal] = useState(() => clamp(defaultValue)), [dragging, setDragging] = useState(false), [draft, setDraft] = useState();
33
+ const current = clamp(value ?? local), shown = dragging && draft !== void 0 ? draft : current;
34
+ const readonly = disabled || low === high || value !== void 0 && !onChange;
35
+ const root = useRef(null), handle = useRef(null), drag = useRef(null), frame = useRef(null), pending = useRef(null), expanded = useRef(
36
+ Math.max(low, Math.min(high, finite(defaultValue, 35))) || high
37
+ ), id = useId();
38
+ const commit = (next) => {
39
+ next = clamp(next);
40
+ if (next > 0) expanded.current = next;
41
+ if (value === void 0) setLocal(next);
42
+ if (drag.current) {
43
+ drag.current.last = next;
44
+ setDraft(next);
45
+ }
46
+ onChange?.(next);
47
+ };
48
+ const latest = useRef({ commit, onResizeEnd, current, readonly });
49
+ latest.current = { commit, onResizeEnd, current, readonly };
50
+ const finish = useCallback((notify = true) => {
51
+ const active = drag.current;
52
+ if (!active) return;
53
+ if (frame.current !== null) cancelAnimationFrame(frame.current);
54
+ frame.current = null;
55
+ if (notify && pending.current !== null)
56
+ latest.current.commit(pending.current);
57
+ pending.current = null;
58
+ drag.current = null;
59
+ if (handle.current?.hasPointerCapture(active.pointer))
60
+ handle.current.releasePointerCapture(active.pointer);
61
+ if (notify) {
62
+ setDragging(false);
63
+ setDraft(void 0);
64
+ latest.current.onResizeEnd?.(active.last);
65
+ }
66
+ }, []);
67
+ useEffect(() => {
68
+ if (current > 0) expanded.current = current;
69
+ }, [current]);
70
+ useEffect(() => {
71
+ if (drag.current) {
72
+ finish();
73
+ }
74
+ }, [direction, low, high, readonly, finish]);
75
+ useEffect(() => {
76
+ const blur = () => finish();
77
+ const key = (event) => {
78
+ if (event.key === "Escape" && drag.current) {
79
+ event.preventDefault();
80
+ event.stopPropagation();
81
+ finish();
82
+ }
83
+ };
84
+ window.addEventListener("blur", blur);
85
+ window.addEventListener("keydown", key);
86
+ return () => {
87
+ window.removeEventListener("blur", blur);
88
+ window.removeEventListener("keydown", key);
89
+ finish(false);
90
+ };
91
+ }, [finish]);
92
+ const toggle = () => {
93
+ if (readonly) return;
94
+ if (collapsible)
95
+ commit(shown === 0 ? clamp(expanded.current || defaultValue) : 0);
96
+ else commit(clamp(defaultValue));
97
+ };
98
+ return /* @__PURE__ */ jsxs(
99
+ "div",
100
+ {
101
+ ref: root,
102
+ className: `${s.group} ${className}`,
103
+ role: "group",
104
+ "aria-label": label,
105
+ "data-direction": direction,
106
+ "data-resizing": dragging,
107
+ style: {
108
+ ...style,
109
+ "--panel-first": `${shown}fr`,
110
+ "--panel-second": `${100 - shown}fr`
111
+ },
112
+ children: [
113
+ /* @__PURE__ */ jsx(
114
+ "div",
115
+ {
116
+ id: `${id}-first`,
117
+ className: s.pane,
118
+ role: "region",
119
+ "aria-label": primaryLabel,
120
+ inert: shown === 0,
121
+ "aria-hidden": shown === 0 || void 0,
122
+ "data-collapsed": shown === 0,
123
+ children: children[0]
124
+ }
125
+ ),
126
+ /* @__PURE__ */ jsx(
127
+ "div",
128
+ {
129
+ ref: handle,
130
+ className: s.handle,
131
+ role: "separator",
132
+ tabIndex: readonly ? -1 : 0,
133
+ "aria-label": `\u8C03\u6574${primaryLabel}\u4E0E${secondaryLabel}`,
134
+ "aria-orientation": direction === "horizontal" ? "vertical" : "horizontal",
135
+ "aria-controls": `${id}-first`,
136
+ "aria-valuemin": collapsible ? 0 : low,
137
+ "aria-valuemax": high,
138
+ "aria-valuenow": Math.round(shown * 10) / 10,
139
+ "aria-valuetext": shown === 0 ? "\u5DF2\u6298\u53E0" : `${Math.round(shown)}%`,
140
+ "aria-disabled": readonly || void 0,
141
+ "aria-describedby": `${id}-help`,
142
+ onDoubleClick: toggle,
143
+ onKeyDown: (event) => {
144
+ if (readonly) return;
145
+ const delta = Math.max(0.1, finite(step, 1)) * (event.shiftKey ? 10 : 1);
146
+ const previous = direction === "horizontal" ? "ArrowLeft" : "ArrowUp", next = direction === "horizontal" ? "ArrowRight" : "ArrowDown";
147
+ if (event.key === "Enter" && collapsible) {
148
+ event.preventDefault();
149
+ toggle();
150
+ return;
151
+ }
152
+ const result = event.key === "Home" ? low : event.key === "End" ? high : event.key === previous ? shown - delta : event.key === next ? shown + delta : void 0;
153
+ if (result !== void 0) {
154
+ event.preventDefault();
155
+ commit(result > 0 ? Math.max(low, result) : collapsible ? 0 : low);
156
+ }
157
+ },
158
+ onPointerDown: (event) => {
159
+ if (readonly || event.button !== 0) return;
160
+ const rect = root.current.getBoundingClientRect(), bar = event.currentTarget.getBoundingClientRect();
161
+ const extent = direction === "horizontal" ? rect.width - bar.width : rect.height - bar.height;
162
+ if (extent <= 0) return;
163
+ event.preventDefault();
164
+ event.currentTarget.focus({ preventScroll: true });
165
+ event.currentTarget.setPointerCapture(event.pointerId);
166
+ drag.current = {
167
+ pointer: event.pointerId,
168
+ coordinate: direction === "horizontal" ? event.clientX : event.clientY,
169
+ value: shown,
170
+ extent,
171
+ last: shown
172
+ };
173
+ setDraft(shown);
174
+ setDragging(true);
175
+ onResizeStart?.();
176
+ },
177
+ onPointerMove: (event) => {
178
+ const active = drag.current;
179
+ if (!active || active.pointer !== event.pointerId) return;
180
+ const coordinate = direction === "horizontal" ? event.clientX : event.clientY;
181
+ const next = active.value + (coordinate - active.coordinate) / active.extent * 100;
182
+ pending.current = collapsible && next < low / 2 ? 0 : Math.max(low, Math.min(high, next));
183
+ if (frame.current === null)
184
+ frame.current = requestAnimationFrame(() => {
185
+ frame.current = null;
186
+ if (pending.current !== null && drag.current) {
187
+ latest.current.commit(pending.current);
188
+ pending.current = null;
189
+ }
190
+ });
191
+ },
192
+ onPointerUp: () => finish(),
193
+ onPointerCancel: () => finish(),
194
+ onLostPointerCapture: () => finish()
195
+ }
196
+ ),
197
+ /* @__PURE__ */ jsx(
198
+ "div",
199
+ {
200
+ className: s.pane,
201
+ role: "region",
202
+ "aria-label": secondaryLabel,
203
+ inert: shown === 100,
204
+ "aria-hidden": shown === 100 || void 0,
205
+ "data-collapsed": shown === 100,
206
+ children: children[1]
207
+ }
208
+ ),
209
+ /* @__PURE__ */ jsxs("span", { id: `${id}-help`, className: s.help, children: [
210
+ "\u62D6\u52A8\u6216\u4F7F\u7528\u65B9\u5411\u952E\u8C03\u6574\uFF0CShift \u52A0\u901F\uFF0CHome/End \u5230\u8FB9\u754C\u3002",
211
+ collapsible ? "Enter \u6216\u53CC\u51FB\u6298\u53E0\u548C\u6062\u590D\u4E3B\u9762\u677F\u3002" : "\u53CC\u51FB\u6062\u590D\u9ED8\u8BA4\u6BD4\u4F8B\u3002"
212
+ ] })
213
+ ]
214
+ }
215
+ );
216
+ }
217
+ export {
218
+ ResizablePanel
219
+ };