gooee 0.0.0-stage → 0.41.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 (247) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +99 -2
  3. package/package.json +36 -4
  4. package/scripts/add.js +533 -0
  5. package/scripts/pro-components.json +82 -0
  6. package/src/base.css +39 -0
  7. package/src/components/Accordion/Accordion.module.css +90 -0
  8. package/src/components/Accordion/Accordion.tsx +125 -0
  9. package/src/components/Accordion/index.ts +1 -0
  10. package/src/components/Alert/Alert.module.css +121 -0
  11. package/src/components/Alert/Alert.tsx +90 -0
  12. package/src/components/Alert/index.ts +1 -0
  13. package/src/components/AlertDialog/AlertDialog.module.css +2 -0
  14. package/src/components/AlertDialog/AlertDialog.tsx +108 -0
  15. package/src/components/AlertDialog/index.ts +1 -0
  16. package/src/components/AnimatedNumber/AnimatedNumber.module.css +48 -0
  17. package/src/components/AnimatedNumber/AnimatedNumber.tsx +52 -0
  18. package/src/components/AnimatedNumber/index.ts +1 -0
  19. package/src/components/AspectRatio/AspectRatio.module.css +15 -0
  20. package/src/components/AspectRatio/AspectRatio.tsx +12 -0
  21. package/src/components/AspectRatio/index.ts +1 -0
  22. package/src/components/Avatar/Avatar.module.css +62 -0
  23. package/src/components/Avatar/Avatar.tsx +55 -0
  24. package/src/components/Avatar/index.ts +3 -0
  25. package/src/components/AvatarGroup/AvatarGroup.module.css +53 -0
  26. package/src/components/AvatarGroup/AvatarGroup.tsx +43 -0
  27. package/src/components/AvatarGroup/index.ts +1 -0
  28. package/src/components/Badge/Badge.module.css +69 -0
  29. package/src/components/Badge/Badge.tsx +25 -0
  30. package/src/components/Badge/index.ts +1 -0
  31. package/src/components/Breadcrumb/Breadcrumb.module.css +104 -0
  32. package/src/components/Breadcrumb/Breadcrumb.tsx +76 -0
  33. package/src/components/Breadcrumb/index.ts +1 -0
  34. package/src/components/Button/Button.module.css +191 -0
  35. package/src/components/Button/Button.tsx +148 -0
  36. package/src/components/Button/index.ts +1 -0
  37. package/src/components/ButtonGroup/ButtonGroup.module.css +59 -0
  38. package/src/components/ButtonGroup/ButtonGroup.tsx +45 -0
  39. package/src/components/ButtonGroup/index.ts +1 -0
  40. package/src/components/Card/Card.module.css +82 -0
  41. package/src/components/Card/Card.tsx +34 -0
  42. package/src/components/Card/index.ts +1 -0
  43. package/src/components/Center/Center.module.css +15 -0
  44. package/src/components/Center/Center.tsx +28 -0
  45. package/src/components/Center/index.ts +1 -0
  46. package/src/components/Checkbox/Checkbox.module.css +120 -0
  47. package/src/components/Checkbox/Checkbox.tsx +133 -0
  48. package/src/components/Checkbox/index.ts +1 -0
  49. package/src/components/CheckboxGroup/CheckboxGroup.module.css +30 -0
  50. package/src/components/CheckboxGroup/CheckboxGroup.tsx +88 -0
  51. package/src/components/CheckboxGroup/index.ts +1 -0
  52. package/src/components/Cluster/Cluster.module.css +25 -0
  53. package/src/components/Cluster/Cluster.tsx +26 -0
  54. package/src/components/Cluster/index.ts +1 -0
  55. package/src/components/CodeBlock/CodeBlock.module.css +74 -0
  56. package/src/components/CodeBlock/CodeBlock.tsx +53 -0
  57. package/src/components/CodeBlock/highlight.ts +73 -0
  58. package/src/components/CodeBlock/index.ts +1 -0
  59. package/src/components/Collapsible/Collapsible.module.css +75 -0
  60. package/src/components/Collapsible/Collapsible.tsx +71 -0
  61. package/src/components/Collapsible/index.ts +1 -0
  62. package/src/components/Container/Container.module.css +14 -0
  63. package/src/components/Container/Container.tsx +19 -0
  64. package/src/components/Container/index.ts +1 -0
  65. package/src/components/CopyButton/CopyButton.module.css +125 -0
  66. package/src/components/CopyButton/CopyButton.tsx +160 -0
  67. package/src/components/CopyButton/index.ts +1 -0
  68. package/src/components/Dial/Dial.module.css +344 -0
  69. package/src/components/Dial/Dial.tsx +332 -0
  70. package/src/components/Dial/index.ts +1 -0
  71. package/src/components/Dialog/Dialog.module.css +190 -0
  72. package/src/components/Dialog/Dialog.tsx +100 -0
  73. package/src/components/Dialog/index.ts +1 -0
  74. package/src/components/Divider/Divider.module.css +39 -0
  75. package/src/components/Divider/Divider.tsx +34 -0
  76. package/src/components/Divider/index.ts +1 -0
  77. package/src/components/DropdownMenu/DropdownMenu.module.css +134 -0
  78. package/src/components/DropdownMenu/DropdownMenu.tsx +215 -0
  79. package/src/components/DropdownMenu/index.ts +1 -0
  80. package/src/components/EmptyState/EmptyState.module.css +66 -0
  81. package/src/components/EmptyState/EmptyState.tsx +38 -0
  82. package/src/components/EmptyState/index.ts +1 -0
  83. package/src/components/Fab/Fab.module.css +176 -0
  84. package/src/components/Fab/Fab.tsx +117 -0
  85. package/src/components/Fab/index.ts +1 -0
  86. package/src/components/Fieldset/Fieldset.module.css +34 -0
  87. package/src/components/Fieldset/Fieldset.tsx +41 -0
  88. package/src/components/Fieldset/index.ts +1 -0
  89. package/src/components/FormField/FormField.module.css +62 -0
  90. package/src/components/FormField/FormField.tsx +91 -0
  91. package/src/components/FormField/index.ts +2 -0
  92. package/src/components/Grid/Grid.module.css +39 -0
  93. package/src/components/Grid/Grid.tsx +35 -0
  94. package/src/components/Grid/index.ts +1 -0
  95. package/src/components/HoldToConfirm/HoldToConfirm.module.css +175 -0
  96. package/src/components/HoldToConfirm/HoldToConfirm.tsx +334 -0
  97. package/src/components/HoldToConfirm/index.ts +1 -0
  98. package/src/components/IconButton/IconButton.module.css +78 -0
  99. package/src/components/IconButton/IconButton.tsx +35 -0
  100. package/src/components/IconButton/index.ts +1 -0
  101. package/src/components/Input/Input.module.css +157 -0
  102. package/src/components/Input/Input.tsx +133 -0
  103. package/src/components/Input/index.ts +1 -0
  104. package/src/components/InputGroup/InputGroup.module.css +146 -0
  105. package/src/components/InputGroup/InputGroup.tsx +90 -0
  106. package/src/components/InputGroup/index.ts +1 -0
  107. package/src/components/Kbd/Kbd.module.css +28 -0
  108. package/src/components/Kbd/Kbd.tsx +38 -0
  109. package/src/components/Kbd/index.ts +1 -0
  110. package/src/components/Link/Link.module.css +65 -0
  111. package/src/components/Link/Link.tsx +41 -0
  112. package/src/components/Link/index.ts +1 -0
  113. package/src/components/LivePill/LivePill.module.css +207 -0
  114. package/src/components/LivePill/LivePill.tsx +182 -0
  115. package/src/components/LivePill/index.ts +1 -0
  116. package/src/components/Meter/Meter.module.css +91 -0
  117. package/src/components/Meter/Meter.tsx +109 -0
  118. package/src/components/Meter/index.ts +1 -0
  119. package/src/components/MorphButton/MorphButton.module.css +152 -0
  120. package/src/components/MorphButton/MorphButton.tsx +203 -0
  121. package/src/components/MorphButton/index.ts +1 -0
  122. package/src/components/NumberInput/NumberInput.module.css +104 -0
  123. package/src/components/NumberInput/NumberInput.tsx +252 -0
  124. package/src/components/NumberInput/index.ts +2 -0
  125. package/src/components/Pagination/Pagination.module.css +88 -0
  126. package/src/components/Pagination/Pagination.tsx +126 -0
  127. package/src/components/Pagination/index.ts +1 -0
  128. package/src/components/PasswordInput/PasswordInput.module.css +64 -0
  129. package/src/components/PasswordInput/PasswordInput.tsx +63 -0
  130. package/src/components/PasswordInput/index.ts +2 -0
  131. package/src/components/PickerWheel/PickerWheel.module.css +123 -0
  132. package/src/components/PickerWheel/PickerWheel.tsx +326 -0
  133. package/src/components/PickerWheel/index.ts +1 -0
  134. package/src/components/Popover/Popover.module.css +78 -0
  135. package/src/components/Popover/Popover.tsx +117 -0
  136. package/src/components/Popover/index.ts +1 -0
  137. package/src/components/ProgressBar/ProgressBar.module.css +61 -0
  138. package/src/components/ProgressBar/ProgressBar.tsx +48 -0
  139. package/src/components/ProgressBar/index.ts +1 -0
  140. package/src/components/Prose/Prose.module.css +115 -0
  141. package/src/components/Prose/Prose.tsx +14 -0
  142. package/src/components/Prose/index.ts +1 -0
  143. package/src/components/Radio/Radio.module.css +106 -0
  144. package/src/components/Radio/Radio.tsx +115 -0
  145. package/src/components/Radio/index.ts +1 -0
  146. package/src/components/Retime/Retime.tsx +116 -0
  147. package/src/components/Retime/index.ts +1 -0
  148. package/src/components/RulerScrubber/RulerScrubber.module.css +146 -0
  149. package/src/components/RulerScrubber/RulerScrubber.tsx +209 -0
  150. package/src/components/RulerScrubber/index.ts +1 -0
  151. package/src/components/ScrollArea/ScrollArea.module.css +72 -0
  152. package/src/components/ScrollArea/ScrollArea.tsx +172 -0
  153. package/src/components/ScrollArea/index.ts +1 -0
  154. package/src/components/SearchInput/SearchInput.module.css +53 -0
  155. package/src/components/SearchInput/SearchInput.tsx +104 -0
  156. package/src/components/SearchInput/index.ts +2 -0
  157. package/src/components/SegmentedControl/SegmentedControl.module.css +150 -0
  158. package/src/components/SegmentedControl/SegmentedControl.tsx +169 -0
  159. package/src/components/SegmentedControl/index.ts +1 -0
  160. package/src/components/Select/Select.module.css +204 -0
  161. package/src/components/Select/Select.tsx +254 -0
  162. package/src/components/Select/index.ts +1 -0
  163. package/src/components/Sheet/Sheet.module.css +228 -0
  164. package/src/components/Sheet/Sheet.tsx +449 -0
  165. package/src/components/Sheet/index.ts +1 -0
  166. package/src/components/Skeleton/Skeleton.module.css +56 -0
  167. package/src/components/Skeleton/Skeleton.tsx +37 -0
  168. package/src/components/Skeleton/index.ts +1 -0
  169. package/src/components/Slider/Slider.module.css +155 -0
  170. package/src/components/Slider/Slider.tsx +200 -0
  171. package/src/components/Slider/index.ts +1 -0
  172. package/src/components/Spinner/Spinner.module.css +50 -0
  173. package/src/components/Spinner/Spinner.tsx +29 -0
  174. package/src/components/Spinner/index.ts +1 -0
  175. package/src/components/Split/Split.module.css +29 -0
  176. package/src/components/Split/Split.tsx +33 -0
  177. package/src/components/Split/index.ts +1 -0
  178. package/src/components/SplitFlap/SplitFlap.module.css +107 -0
  179. package/src/components/SplitFlap/SplitFlap.tsx +225 -0
  180. package/src/components/SplitFlap/index.ts +1 -0
  181. package/src/components/Stack/Stack.module.css +17 -0
  182. package/src/components/Stack/Stack.tsx +19 -0
  183. package/src/components/Stack/index.ts +1 -0
  184. package/src/components/SwipeDeck/SwipeDeck.module.css +250 -0
  185. package/src/components/SwipeDeck/SwipeDeck.tsx +350 -0
  186. package/src/components/SwipeDeck/index.ts +1 -0
  187. package/src/components/Switch/Switch.module.css +97 -0
  188. package/src/components/Switch/Switch.tsx +147 -0
  189. package/src/components/Switch/index.ts +1 -0
  190. package/src/components/Table/Table.module.css +369 -0
  191. package/src/components/Table/Table.tsx +368 -0
  192. package/src/components/Table/index.ts +1 -0
  193. package/src/components/TableOfContents/TableOfContents.module.css +107 -0
  194. package/src/components/TableOfContents/TableOfContents.tsx +93 -0
  195. package/src/components/TableOfContents/index.ts +1 -0
  196. package/src/components/Tabs/Tabs.module.css +101 -0
  197. package/src/components/Tabs/Tabs.tsx +190 -0
  198. package/src/components/Tabs/index.ts +1 -0
  199. package/src/components/Tag/Tag.module.css +120 -0
  200. package/src/components/Tag/Tag.tsx +109 -0
  201. package/src/components/Tag/index.ts +1 -0
  202. package/src/components/Textarea/Textarea.module.css +79 -0
  203. package/src/components/Textarea/Textarea.tsx +130 -0
  204. package/src/components/Textarea/index.ts +1 -0
  205. package/src/components/ThemeToggle/ThemeToggle.module.css +21 -0
  206. package/src/components/ThemeToggle/ThemeToggle.tsx +69 -0
  207. package/src/components/ThemeToggle/index.ts +1 -0
  208. package/src/components/Toast/Toast.module.css +202 -0
  209. package/src/components/Toast/Toast.tsx +473 -0
  210. package/src/components/Toast/index.ts +1 -0
  211. package/src/components/Toggle/Toggle.module.css +94 -0
  212. package/src/components/Toggle/Toggle.tsx +50 -0
  213. package/src/components/Toggle/index.ts +1 -0
  214. package/src/components/Tooltip/Tooltip.module.css +34 -0
  215. package/src/components/Tooltip/Tooltip.tsx +154 -0
  216. package/src/components/Tooltip/index.ts +1 -0
  217. package/src/components/VisuallyHidden/VisuallyHidden.module.css +13 -0
  218. package/src/components/VisuallyHidden/VisuallyHidden.tsx +12 -0
  219. package/src/components/VisuallyHidden/index.ts +1 -0
  220. package/src/internal/FieldMessage.module.css +49 -0
  221. package/src/internal/FieldMessage.tsx +44 -0
  222. package/src/internal/Portal.tsx +7 -0
  223. package/src/internal/Roll.module.css +31 -0
  224. package/src/internal/Roll.tsx +20 -0
  225. package/src/internal/cx.ts +3 -0
  226. package/src/internal/feel.ts +355 -0
  227. package/src/internal/fling.ts +118 -0
  228. package/src/internal/focus.ts +94 -0
  229. package/src/internal/icons.module.css +62 -0
  230. package/src/internal/icons.tsx +511 -0
  231. package/src/internal/keyboard.ts +62 -0
  232. package/src/internal/layers.ts +85 -0
  233. package/src/internal/liquid.ts +248 -0
  234. package/src/internal/liquidMatter.ts +168 -0
  235. package/src/internal/liquidMore.ts +686 -0
  236. package/src/internal/liquidPath.ts +519 -0
  237. package/src/internal/mergeRefs.ts +10 -0
  238. package/src/internal/motion.ts +37 -0
  239. package/src/internal/relativeTime.ts +26 -0
  240. package/src/internal/scrollFrame.ts +157 -0
  241. package/src/internal/softPress.ts +299 -0
  242. package/src/internal/space.ts +6 -0
  243. package/src/internal/useControllable.ts +21 -0
  244. package/src/internal/useFloating.ts +85 -0
  245. package/src/internal/usePresence.ts +15 -0
  246. package/src/internal/useScrub.ts +160 -0
  247. package/src/tokens.css +727 -0
@@ -0,0 +1,344 @@
1
+ .root {
2
+ display: grid;
3
+ justify-items: center;
4
+ gap: var(--gooee-space-6);
5
+ width: 100%;
6
+ color: var(--gooee-color-fg);
7
+ }
8
+
9
+ .head {
10
+ display: grid;
11
+ justify-items: center;
12
+ gap: var(--gooee-space-1);
13
+ text-align: center;
14
+ }
15
+
16
+ .label {
17
+ font-size: var(--gooee-text-sm);
18
+ color: var(--gooee-color-fg-muted);
19
+ }
20
+
21
+ .readout {
22
+ font-size: var(--gooee-text-4xl);
23
+ font-weight: var(--gooee-weight-semibold);
24
+ letter-spacing: var(--gooee-tracking-tight);
25
+ line-height: 1;
26
+ }
27
+
28
+ .detail {
29
+ font-size: var(--gooee-text-sm);
30
+ color: var(--gooee-color-fg-muted);
31
+ font-variant-numeric: tabular-nums;
32
+ }
33
+
34
+ /* Every dial: grabbed, not selected, and never scrolled by a finger on it. */
35
+ .knob,
36
+ .mercuryHit,
37
+ .arcStage {
38
+ position: relative;
39
+ cursor: grab;
40
+ outline: none;
41
+ user-select: none;
42
+ -webkit-user-select: none;
43
+ -webkit-tap-highlight-color: transparent;
44
+ }
45
+
46
+ .knob[data-moving],
47
+ .mercuryHit[data-moving],
48
+ .arcStage[data-moving] {
49
+ cursor: grabbing;
50
+ }
51
+
52
+ /* Printed knob */
53
+
54
+ .printed {
55
+ --num-r: calc(var(--gooee-dial-size) * -0.29);
56
+ }
57
+
58
+ .bezel {
59
+ position: relative;
60
+ display: grid;
61
+ place-items: center;
62
+ width: var(--gooee-dial-ring);
63
+ height: var(--gooee-dial-ring);
64
+ border-radius: var(--gooee-radius-full);
65
+ border: var(--gooee-line) solid var(--gooee-color-border);
66
+ }
67
+
68
+ .index {
69
+ position: absolute;
70
+ top: var(--gooee-space-1);
71
+ left: 50%;
72
+ width: var(--gooee-indicator);
73
+ height: var(--gooee-space-4);
74
+ margin-left: calc(var(--gooee-indicator) / -2);
75
+ border-radius: var(--gooee-radius-full);
76
+ background: var(--gooee-color-fg);
77
+ }
78
+
79
+ .knob {
80
+ width: var(--gooee-dial-size);
81
+ height: var(--gooee-dial-size);
82
+ border-radius: var(--gooee-radius-full);
83
+ background: var(--gooee-color-surface-raised);
84
+ box-shadow: var(--gooee-shadow-2), inset 0 0 0 var(--gooee-line) var(--gooee-color-border);
85
+ touch-action: none;
86
+ }
87
+
88
+ .knob:focus-visible {
89
+ box-shadow: var(--gooee-focus-ring), var(--gooee-shadow-2);
90
+ }
91
+
92
+ .face {
93
+ position: absolute;
94
+ inset: 0;
95
+ border-radius: inherit;
96
+ }
97
+
98
+ .spoke,
99
+ .numAt {
100
+ position: absolute;
101
+ left: 50%;
102
+ top: 50%;
103
+ width: 0;
104
+ height: 0;
105
+ }
106
+
107
+ .numAt {
108
+ left: 0;
109
+ top: 0;
110
+ }
111
+
112
+ .tick {
113
+ position: absolute;
114
+ left: calc(var(--gooee-indicator) / -2);
115
+ top: calc(var(--gooee-dial-size) / -2 + var(--gooee-space-3));
116
+ width: var(--gooee-indicator);
117
+ height: var(--gooee-space-3);
118
+ border-radius: var(--gooee-radius-full);
119
+ transform-origin: top center;
120
+ }
121
+
122
+ .tick[data-major] {
123
+ height: var(--gooee-space-5);
124
+ }
125
+
126
+ /* On a long scale the plain steps are hairlines, so they read as a fine ruler, not a solid band. */
127
+ .tick[data-fine] {
128
+ left: calc(var(--gooee-line) / -2);
129
+ width: var(--gooee-line);
130
+ height: var(--gooee-space-2);
131
+ }
132
+
133
+ /* The amount: a thin ink arc on the ring, from min to the index. A vector stroke, so its edges stay
134
+ smooth at any size (a gradient mask would leave them stepped). */
135
+ .fill {
136
+ position: absolute;
137
+ inset: calc(var(--gooee-line) * -1);
138
+ width: calc(100% + var(--gooee-line) * 2);
139
+ height: calc(100% + var(--gooee-line) * 2);
140
+ overflow: visible;
141
+ transform: rotate(-90deg);
142
+ pointer-events: none;
143
+ }
144
+
145
+ .fill circle {
146
+ cx: 50%;
147
+ cy: 50%;
148
+ r: calc(50% - var(--gooee-indicator) / 2);
149
+ fill: none;
150
+ stroke: var(--gooee-color-fg);
151
+ stroke-width: var(--gooee-indicator);
152
+ stroke-linecap: round;
153
+ }
154
+
155
+ .grip {
156
+ position: absolute;
157
+ top: 35%;
158
+ left: 50%;
159
+ width: var(--gooee-indicator);
160
+ height: var(--gooee-space-5);
161
+ margin-left: calc(var(--gooee-indicator) / -2);
162
+ border-radius: var(--gooee-radius-full);
163
+ background: var(--gooee-color-border-strong);
164
+ pointer-events: none;
165
+ }
166
+
167
+ .tick[data-strong] {
168
+ left: calc(var(--gooee-indicator) * -1);
169
+ width: calc(var(--gooee-indicator) * 2);
170
+ }
171
+
172
+ .num {
173
+ position: absolute;
174
+ left: 0;
175
+ top: 0;
176
+ font-size: var(--gooee-text-sm);
177
+ font-variant-numeric: tabular-nums;
178
+ white-space: nowrap;
179
+ line-height: 1;
180
+ }
181
+
182
+ .cap {
183
+ position: absolute;
184
+ inset: 35%;
185
+ border-radius: var(--gooee-radius-full);
186
+ border: var(--gooee-line) solid var(--gooee-color-border);
187
+ background: var(--gooee-color-surface-sunken);
188
+ }
189
+
190
+ /* Mercury */
191
+
192
+ .mercury {
193
+ gap: var(--gooee-space-4);
194
+ }
195
+
196
+ .mercuryHit {
197
+ width: min(100%, calc(var(--gooee-dial-ring) + var(--gooee-space-9)));
198
+ border-radius: var(--gooee-radius-panel);
199
+ touch-action: none;
200
+ }
201
+
202
+ .mercuryHit:focus-visible {
203
+ box-shadow: var(--gooee-focus-ring);
204
+ }
205
+
206
+ .mercurySvg {
207
+ display: block;
208
+ width: 100%;
209
+ height: auto;
210
+ overflow: visible;
211
+ }
212
+
213
+ .metal {
214
+ fill: var(--gooee-color-fg);
215
+ }
216
+
217
+ .groove {
218
+ fill: none;
219
+ stroke: color-mix(in srgb, var(--gooee-color-inverse-fg) 22%, transparent);
220
+ stroke-width: var(--gooee-line);
221
+ }
222
+
223
+ .dot {
224
+ fill: var(--gooee-color-border-strong);
225
+ }
226
+
227
+ .dot[data-on] {
228
+ fill: var(--gooee-color-accent);
229
+ }
230
+
231
+ .level {
232
+ font-family: var(--gooee-font-sans);
233
+ font-size: var(--gooee-text-sm);
234
+ fill: var(--gooee-color-fg-muted);
235
+ }
236
+
237
+ .level[data-on] {
238
+ fill: var(--gooee-color-accent);
239
+ font-weight: var(--gooee-weight-semibold);
240
+ }
241
+
242
+ /* Speed arc */
243
+
244
+ .arc {
245
+ gap: var(--gooee-space-5);
246
+ }
247
+
248
+ .arcStage {
249
+ --rim: calc(var(--gooee-ruler-h) / 2);
250
+ width: 100%;
251
+ height: var(--gooee-ruler-h);
252
+ border-radius: var(--gooee-radius-md);
253
+ /* A sideways swipe turns it; up and down still scrolls the page. */
254
+ touch-action: pan-y;
255
+ }
256
+
257
+ .arcStage:focus-visible {
258
+ box-shadow: var(--gooee-focus-ring);
259
+ }
260
+
261
+ .arcClip {
262
+ position: absolute;
263
+ inset: 0;
264
+ overflow: hidden;
265
+ border-radius: inherit;
266
+ mask-image: linear-gradient(90deg, transparent, var(--gooee-color-fg) 16%, var(--gooee-color-fg) 84%, transparent);
267
+ }
268
+
269
+ .hub {
270
+ position: absolute;
271
+ left: 50%;
272
+ top: calc(var(--rim) + var(--gooee-dial-arc-radius));
273
+ width: 0;
274
+ height: 0;
275
+ }
276
+
277
+ .disc {
278
+ position: absolute;
279
+ left: calc(var(--gooee-dial-arc-radius) * -1);
280
+ top: calc(var(--gooee-dial-arc-radius) * -1);
281
+ width: calc(var(--gooee-dial-arc-radius) * 2);
282
+ height: calc(var(--gooee-dial-arc-radius) * 2);
283
+ border-radius: var(--gooee-radius-full);
284
+ background: var(--gooee-color-surface-sunken);
285
+ box-shadow: inset 0 var(--gooee-line) 0 var(--gooee-color-border-strong);
286
+ }
287
+
288
+ .arcMark {
289
+ position: absolute;
290
+ left: 0;
291
+ top: 0;
292
+ width: 0;
293
+ height: 0;
294
+ }
295
+
296
+ .arcTick {
297
+ position: absolute;
298
+ left: calc(var(--gooee-indicator) / -2);
299
+ bottom: 0;
300
+ width: var(--gooee-indicator);
301
+ height: var(--gooee-space-3);
302
+ border-radius: var(--gooee-radius-full);
303
+ transform-origin: bottom center;
304
+ }
305
+
306
+ .arcTick[data-tier='mid'] {
307
+ height: var(--gooee-space-4);
308
+ }
309
+
310
+ .arcTick[data-tier='major'] {
311
+ height: var(--gooee-space-6);
312
+ }
313
+
314
+ .arcNum {
315
+ position: absolute;
316
+ left: 0;
317
+ top: var(--gooee-space-4);
318
+ font-size: var(--gooee-text-xs);
319
+ font-variant-numeric: tabular-nums;
320
+ white-space: nowrap;
321
+ transform-origin: top center;
322
+ }
323
+
324
+ .arcStrong {
325
+ position: absolute;
326
+ left: calc(var(--gooee-dot) / -2);
327
+ top: var(--gooee-space-8);
328
+ width: var(--gooee-dot);
329
+ height: var(--gooee-dot);
330
+ border-radius: var(--gooee-radius-full);
331
+ background: var(--gooee-color-fg-muted);
332
+ }
333
+
334
+ .arcIndex {
335
+ position: absolute;
336
+ z-index: 1;
337
+ left: 50%;
338
+ top: var(--gooee-space-3);
339
+ width: var(--gooee-indicator);
340
+ height: var(--gooee-space-5);
341
+ margin-left: calc(var(--gooee-indicator) / -2);
342
+ border-radius: var(--gooee-radius-full);
343
+ background: var(--gooee-color-fg);
344
+ }
@@ -0,0 +1,332 @@
1
+ 'use client'
2
+
3
+ import { useId, useLayoutEffect, useRef, useState, type ComponentPropsWithRef, type PointerEvent, type ReactNode } from 'react'
4
+ import { cx } from '../../internal/cx'
5
+ import { clamp, lastStep, pull, roundTo, steps, wheelSteps, stepKey } from '../../internal/feel'
6
+ import { Roll } from '../../internal/Roll'
7
+ import { useControllable } from '../../internal/useControllable'
8
+ import { ink, sideways, tokenNumber, useOnChange, useScrub } from '../../internal/useScrub'
9
+ import styles from './Dial.module.css'
10
+
11
+ export type DialProps = Omit<ComponentPropsWithRef<'div'>, 'defaultValue' | 'onChange' | 'children'> & {
12
+ /** Visible name of the dial, also read by screen readers. */
13
+ label: string
14
+ /** The value, when you control it. */
15
+ value?: number
16
+ /** Starting value when you do not control it. Undefined starts at min. */
17
+ defaultValue?: number
18
+ /** Called once the dial comes to rest on a new value. */
19
+ onValueChange?: (value: number) => void
20
+ /** Called with the value under the index while the dial still turns. */
21
+ onScrub?: (value: number) => void
22
+ /** Lowest value. */
23
+ min?: number
24
+ /** Highest value. */
25
+ max?: number
26
+ /** Size of one step. Every step is a mark the dial is drawn onto. */
27
+ step?: number
28
+ /** Values with a printed label. Page Up and Page Down jump between them. Defaults to min and max. */
29
+ marks?: number[]
30
+ /** Values drawn stronger, such as the usual setting. */
31
+ strong?: number[]
32
+ /** "printed": the scale is printed on the knob and turns under a fixed index. "mercury": a solid knob with a few named levels. "arc": the rim of a large dial, swiped sideways. */
33
+ variant?: 'printed' | 'mercury' | 'arc'
34
+ /** Turns the value into the readout and what screen readers hear. */
35
+ formatValue?: (value: number) => string
36
+ /** Turns a mark into its printed label. Defaults to formatValue. */
37
+ formatMark?: (value: number) => string
38
+ /** A line under the readout, such as what the value means. */
39
+ detail?: ReactNode
40
+ /** A double click goes back to this value. */
41
+ resetValue?: number
42
+ /** A short buzz on each step while it turns, on phones that can (Android). */
43
+ haptics?: boolean
44
+ }
45
+
46
+ // The printed and mercury dials sweep 270 degrees, with the dead part at the bottom.
47
+ const SWEEP = 270
48
+
49
+ // Mercury is drawn in this box (SVG units): knob, bump and level dots.
50
+ const W = 280
51
+ const H = 252
52
+ const CX = W / 2
53
+ const CY = 128
54
+ const KNOB = 58
55
+ const DOT = 84
56
+ const polar = (deg: number, r: number) => [CX + r * Math.sin((deg * Math.PI) / 180), CY - r * Math.cos((deg * Math.PI) / 180)] as const
57
+
58
+ /** A drag around a centre: the change in angle since the last move, never the angle itself, so a press never jumps. */
59
+ function turn(unitsPerDeg: number, centre: (r: DOMRect) => { x: number; y: number }) {
60
+ return (e: PointerEvent<HTMLElement>, last: { x: number; y: number }, el: HTMLElement) => {
61
+ const c = centre(el.getBoundingClientRect())
62
+ // Near the centre the angle swings wildly, so it does not count.
63
+ if (Math.hypot(e.clientX - c.x, e.clientY - c.y) < 16) return 0
64
+ let d = ((Math.atan2(e.clientY - c.y, e.clientX - c.x) - Math.atan2(last.y - c.y, last.x - c.x)) * 180) / Math.PI
65
+ if (d > 180) d -= 360
66
+ if (d < -180) d += 360
67
+ return d * unitsPerDeg * (e.shiftKey ? 0.25 : 1)
68
+ }
69
+ }
70
+
71
+ /** Where a tap sits around a centre, in degrees clockwise from the top, or null too near the centre to tell. */
72
+ function angleAt(e: PointerEvent<HTMLElement>, centre: (r: DOMRect) => { x: number; y: number }) {
73
+ const c = centre(e.currentTarget.getBoundingClientRect())
74
+ if (Math.hypot(e.clientX - c.x, e.clientY - c.y) < 16) return null
75
+ return (Math.atan2(e.clientX - c.x, c.y - e.clientY) * 180) / Math.PI
76
+ }
77
+
78
+ const mercuryCentre = (r: DOMRect) => ({ x: r.left + r.width / 2, y: r.top + (r.height * CY) / H })
79
+ const knobCentre = (r: DOMRect) => ({ x: r.left + r.width / 2, y: r.top + r.height / 2 })
80
+
81
+ export function Dial({
82
+ label,
83
+ value: valueProp,
84
+ defaultValue,
85
+ onValueChange,
86
+ onScrub,
87
+ min = 0,
88
+ max = 100,
89
+ step = 1,
90
+ marks,
91
+ strong = [],
92
+ variant = 'printed',
93
+ formatValue = String,
94
+ formatMark,
95
+ detail,
96
+ resetValue,
97
+ haptics = false,
98
+ className,
99
+ ...rest
100
+ }: DialProps) {
101
+ const labelId = useId()
102
+ const detailId = useId()
103
+ const goo = useId().replace(/:/g, '')
104
+ const top = lastStep(min, max, step)
105
+ const [raw, setValue] = useControllable(valueProp, defaultValue ?? min, onValueChange)
106
+ const value = clamp(raw, min, top)
107
+ const all = steps(min, max, step)
108
+ const labelled = (marks ?? [min, max]).map((v) => roundTo(v, step, min))
109
+ const strongSet = new Set(strong.map((v) => roundTo(v, step, min)))
110
+ const land = (p: number) => clamp(roundTo(p, step, min), min, top)
111
+ const markText = formatMark ?? formatValue
112
+ const stepDeg = SWEEP / Math.max(1, all.length - 1)
113
+ // The arc's rim: its radius and the length of one step along it, both tokens.
114
+ const [rim, setRim] = useState<{ r: number; gap: number } | null>(null)
115
+ const wheel = useRef(wheelSteps())
116
+
117
+ const sc = useScrub({
118
+ value,
119
+ min,
120
+ max: top,
121
+ edge: step * (variant === 'arc' ? 0.8 : variant === 'mercury' ? 0.12 : 0.6),
122
+ land,
123
+ coast: variant === 'arc' ? 0.2 : 0,
124
+ maxSpeed: 160 * step,
125
+ move:
126
+ variant === 'arc'
127
+ ? (e, last) => (-(e.clientX - last.x) / (rim?.gap || 1)) * step * (e.shiftKey ? 0.25 : 1)
128
+ : variant === 'mercury'
129
+ ? turn(step / stepDeg, mercuryCentre)
130
+ : turn((max - min) / SWEEP, knobCentre),
131
+ key: (k, t) => stepKey(k, t, { min, max, step, marks: labelled }),
132
+ // A tap without a drag goes to the mark under it, so the dial works with one plain press.
133
+ tap: (e, at) => {
134
+ if (variant === 'arc') {
135
+ if (!rim?.gap || !rim.r) return null
136
+ const r = e.currentTarget.getBoundingClientRect()
137
+ // The rim curves, so the tap's sideways distance becomes a length along the arc.
138
+ const along = rim.r * Math.asin(clamp((e.clientX - (r.left + r.width / 2)) / rim.r, -1, 1))
139
+ return land(at + (along / rim.gap) * step)
140
+ }
141
+ if (variant === 'mercury') {
142
+ const a = angleAt(e, mercuryCentre)
143
+ // Past either end of the sweep, land clamps to the nearer end (the dead part is split at the bottom).
144
+ return a === null ? null : land(min + ((a + 135) / stepDeg) * step)
145
+ }
146
+ const a = angleAt(e, knobCentre)
147
+ if (a === null) return null
148
+ // The printed face turns, so the tap is read on the face: min at 0 and max 270 degrees back from it.
149
+ const back = (((((at - min) / (max - min || 1)) * SWEEP - a) % 360) + 360) % 360
150
+ if (back > SWEEP) return back < SWEEP + (360 - SWEEP) / 2 ? top : min
151
+ return land(min + (back / SWEEP) * (max - min))
152
+ },
153
+ wheel:
154
+ variant === 'arc'
155
+ ? (e, t) => {
156
+ const dx = sideways(e)
157
+ if (dx === null || !rim?.gap) return null
158
+ const n = wheel.current(dx, rim.gap, e.timeStamp)
159
+ const to = clamp(roundTo(t + n * step, step, min), min, top)
160
+ return to === t && (t === min || t === top) ? null : to
161
+ }
162
+ : undefined,
163
+ onSettle: setValue,
164
+ haptics,
165
+ })
166
+
167
+ useLayoutEffect(() => {
168
+ if (variant !== 'arc') return
169
+ const el = sc.ref.current
170
+ setRim({ r: tokenNumber(el, '--gooee-dial-arc-radius'), gap: tokenNumber(el, '--gooee-dial-arc-gap') })
171
+ }, [variant, sc.ref])
172
+
173
+ const shown = land(sc.at)
174
+ useOnChange(shown, onScrub)
175
+
176
+ const index = all.indexOf(value)
177
+ const slider = {
178
+ ref: sc.ref,
179
+ role: 'slider',
180
+ tabIndex: 0,
181
+ 'aria-labelledby': labelId,
182
+ 'aria-describedby': detail ? detailId : undefined,
183
+ 'aria-valuemin': min,
184
+ 'aria-valuemax': top,
185
+ 'aria-valuenow': value,
186
+ 'aria-valuetext': variant === 'mercury' && index >= 0 ? `${formatValue(value)}, ${index + 1} of ${all.length}` : formatValue(value),
187
+ 'data-moving': sc.moving || undefined,
188
+ onDoubleClick: resetValue === undefined ? undefined : () => sc.go(land(resetValue)),
189
+ ...sc.handlers,
190
+ }
191
+
192
+ const head = (
193
+ <div className={styles.head}>
194
+ <span id={labelId} className={styles.label}>
195
+ {label}
196
+ </span>
197
+ <Roll text={formatValue(shown)} className={styles.readout} still={sc.moving} />
198
+ {detail && (
199
+ <span id={detailId} className={styles.detail}>
200
+ {detail}
201
+ </span>
202
+ )}
203
+ </div>
204
+ )
205
+
206
+ if (variant === 'mercury') {
207
+ const angle = -135 + ((sc.at - min) / step) * stepDeg
208
+ const [bx, by] = polar(angle, KNOB)
209
+ return (
210
+ <div className={cx(styles.root, styles.mercury, className)} {...rest}>
211
+ {head}
212
+ <div className={styles.mercuryHit} {...slider}>
213
+ <svg viewBox={`0 0 ${W} ${H}`} className={styles.mercurySvg} aria-hidden>
214
+ <defs>
215
+ <filter id={goo} x="-20%" y="-20%" width="140%" height="140%">
216
+ <feGaussianBlur in="SourceGraphic" stdDeviation="5" result="blur" />
217
+ <feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 22 -9" result="goo" />
218
+ <feComposite in="SourceGraphic" in2="goo" operator="atop" />
219
+ </filter>
220
+ </defs>
221
+ {all.map((v, i) => {
222
+ const a = -135 + i * stepDeg
223
+ const [x, y] = polar(a, DOT)
224
+ const [lx, ly] = polar(a, DOT + 22)
225
+ const on = v === shown
226
+ return (
227
+ <g key={v}>
228
+ <circle cx={x} cy={y} r={3.5} className={styles.dot} data-on={on || undefined} />
229
+ <text x={lx} y={ly} textAnchor={Math.abs(a) < 1 ? 'middle' : a < 0 ? 'end' : 'start'} dominantBaseline="middle" className={styles.level} data-on={on || undefined}>
230
+ {markText(v)}
231
+ </text>
232
+ </g>
233
+ )
234
+ })}
235
+ <g filter={`url(#${goo})`} className={styles.metal}>
236
+ <circle cx={CX} cy={CY} r={KNOB} />
237
+ <circle cx={bx} cy={by} r={10} />
238
+ {all.map((v, i) => {
239
+ const p = pull(sc.at - v, step)
240
+ const [x, y] = polar(-135 + i * stepDeg, DOT - 12 * p)
241
+ return <circle key={v} cx={x} cy={y} r={p * 9} />
242
+ })}
243
+ </g>
244
+ <circle cx={CX} cy={CY} r={KNOB - 14} className={styles.groove} />
245
+ </svg>
246
+ </div>
247
+ </div>
248
+ )
249
+ }
250
+
251
+ if (variant === 'arc') {
252
+ const degPerStep = rim && rim.r ? (rim.gap / rim.r) * (180 / Math.PI) : 0
253
+ return (
254
+ <div className={cx(styles.root, styles.arc, className)} {...rest}>
255
+ {head}
256
+ <div className={styles.arcStage} {...slider}>
257
+ <span className={styles.arcIndex} aria-hidden />
258
+ <div className={styles.arcClip} aria-hidden>
259
+ <div className={styles.hub}>
260
+ <span className={styles.disc} />
261
+ {degPerStep > 0 &&
262
+ all.map((v, i) => {
263
+ const a = ((v - sc.at) / step) * degPerStep
264
+ if (Math.abs(a) > 22) return null
265
+ const p = pull(sc.at - v, step * 1.2)
266
+ const tier = labelled.includes(v) ? 'major' : i % 2 === 0 ? 'mid' : 'minor'
267
+ return (
268
+ <span key={v} className={styles.arcMark} style={{ transform: `rotate(${a}deg) translateY(calc(var(--gooee-dial-arc-radius) * -1))` }}>
269
+ <i className={styles.arcTick} data-tier={tier} style={{ background: ink(p, 'var(--gooee-color-border-strong)', 'var(--gooee-color-accent)'), transform: `scaleY(${1 + p * 0.7})` }} />
270
+ {tier === 'major' && (
271
+ <span className={styles.arcNum} style={{ color: ink(p), transform: `translateX(-50%) scale(${1 + p * 0.3})` }}>
272
+ {markText(v)}
273
+ </span>
274
+ )}
275
+ {strongSet.has(v) && <span className={styles.arcStrong} />}
276
+ </span>
277
+ )
278
+ })}
279
+ </div>
280
+ </div>
281
+ </div>
282
+ </div>
283
+ )
284
+ }
285
+
286
+ const turned = ((sc.at - min) / (max - min || 1)) * SWEEP
287
+ // The face prints min, the middle and max unless marks say otherwise; the keys still jump by marks.
288
+ const printed = marks ? labelled : [...new Set([min, roundTo((min + max) / 2, step, min), top])]
289
+ // A longer tick every ten steps on a long scale, so the amount can be counted at a glance.
290
+ const tenth = all.length > 20 ? step * 10 : 0
291
+ const isMajor = (v: number) => printed.includes(v) || (tenth > 0 && Math.abs((v - min) / tenth - Math.round((v - min) / tenth)) < 1e-6)
292
+ // Every step gets a tick while they fit round the knob (thinner past 49); past that only the long ones.
293
+ const dense = all.length > 49
294
+ const ticks = all.length <= 121 ? all : all.filter((v) => isMajor(v) || strongSet.has(v))
295
+ return (
296
+ <div className={cx(styles.root, styles.printed, className)} {...rest}>
297
+ {head}
298
+ <div className={styles.bezel}>
299
+ <span className={styles.index} aria-hidden />
300
+ {/* How much: the ring fills from min (where the face has turned it) up to the index. */}
301
+ <svg className={styles.fill} aria-hidden>
302
+ {/* A negative dash length is invalid and draws the whole ring, so the arc is clamped and left out at min. */}
303
+ {turned > 0.5 && <circle pathLength={360} strokeDasharray={`${Math.min(turned, 360)} 360`} />}
304
+ </svg>
305
+ <div className={styles.knob} {...slider}>
306
+ <div className={styles.face} style={{ transform: `rotate(${turned}deg)` }} aria-hidden>
307
+ {ticks.map((v) => {
308
+ const at = (-(v - min) / (max - min || 1)) * SWEEP
309
+ const p = pull(sc.at - v, step)
310
+ const major = isMajor(v)
311
+ return (
312
+ <span key={v} className={styles.spoke} style={{ transform: `rotate(${at}deg)` }}>
313
+ <i className={styles.tick} data-major={major || undefined} data-fine={(dense && !major) || undefined} data-strong={strongSet.has(v) || undefined} data-current={v === shown || undefined} style={{ background: ink(p, 'var(--gooee-color-border-strong)', 'var(--gooee-color-accent)'), transform: `scaleY(${1 + p * 0.5})` }} />
314
+ {printed.includes(v) && (
315
+ <span className={styles.numAt} style={{ transform: `translateY(var(--num-r)) rotate(${-(at + turned)}deg)` }}>
316
+ <span className={styles.num} style={{ color: ink(p), transform: `translate(-50%, -50%) scale(${1 + p * 0.45})`, fontWeight: `calc(var(--gooee-weight-medium) + (var(--gooee-weight-semibold) - var(--gooee-weight-medium)) * ${p.toFixed(3)})` }}>
317
+ {markText(v)}
318
+ </span>
319
+ </span>
320
+ )}
321
+ </span>
322
+ )
323
+ })}
324
+ <span className={styles.cap} />
325
+ </div>
326
+ {/* The grip: an indent on the cap that points at the value under the index, so it reads as a knob to turn. */}
327
+ <span className={styles.grip} aria-hidden />
328
+ </div>
329
+ </div>
330
+ </div>
331
+ )
332
+ }
@@ -0,0 +1 @@
1
+ export * from './Dial'