gooee 0.50.0 → 0.51.1

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 (172) hide show
  1. package/README.md +17 -4
  2. package/package.json +5 -3
  3. package/scripts/add.js +28 -6
  4. package/src/components/Accordion/Accordion.vue +62 -0
  5. package/src/components/Accordion/AccordionItem.vue +45 -0
  6. package/src/components/Accordion/accordionContext.ts +6 -0
  7. package/src/components/Alert/Alert.tsx +7 -27
  8. package/src/components/Alert/Alert.vue +59 -0
  9. package/src/components/AlertDialog/AlertDialog.vue +126 -0
  10. package/src/components/AnimatedNumber/AnimatedNumber.vue +36 -0
  11. package/src/components/AspectRatio/AspectRatio.vue +17 -0
  12. package/src/components/Avatar/Avatar.vue +56 -0
  13. package/src/components/AvatarGroup/AvatarGroup.vue +42 -0
  14. package/src/components/Badge/Badge.vue +32 -0
  15. package/src/components/Breadcrumb/Breadcrumb.vue +58 -0
  16. package/src/components/Button/Button.vue +130 -0
  17. package/src/components/ButtonGroup/ButtonGroup.tsx +4 -21
  18. package/src/components/ButtonGroup/ButtonGroup.vue +33 -0
  19. package/src/components/Card/Card.vue +34 -0
  20. package/src/components/Center/Center.vue +32 -0
  21. package/src/components/Checkbox/Checkbox.tsx +8 -25
  22. package/src/components/Checkbox/Checkbox.vue +108 -0
  23. package/src/components/CheckboxGroup/CheckboxGroup.vue +76 -0
  24. package/src/components/Cluster/Cluster.vue +34 -0
  25. package/src/components/CodeBlock/CodeBlock.vue +45 -0
  26. package/src/components/Collapsible/Collapsible.vue +59 -0
  27. package/src/components/Container/Container.vue +22 -0
  28. package/src/components/CopyButton/CopyButton.tsx +3 -49
  29. package/src/components/CopyButton/CopyButton.vue +116 -0
  30. package/src/components/Dial/Dial.tsx +12 -120
  31. package/src/components/Dial/Dial.vue +228 -0
  32. package/src/components/Dialog/Dialog.vue +139 -0
  33. package/src/components/Divider/Divider.vue +27 -0
  34. package/src/components/DropdownMenu/DropdownMenu.tsx +11 -46
  35. package/src/components/DropdownMenu/DropdownMenu.vue +185 -0
  36. package/src/components/EmptyState/EmptyState.vue +33 -0
  37. package/src/components/Fab/Fab.tsx +4 -14
  38. package/src/components/Fab/Fab.vue +115 -0
  39. package/src/components/Fieldset/Fieldset.vue +42 -0
  40. package/src/components/FormField/FormField.tsx +2 -17
  41. package/src/components/FormField/FormField.vue +64 -0
  42. package/src/components/Grid/Grid.vue +43 -0
  43. package/src/components/HoldToConfirm/HoldToConfirm.tsx +13 -143
  44. package/src/components/HoldToConfirm/HoldToConfirm.vue +281 -0
  45. package/src/components/IconButton/IconButton.vue +25 -0
  46. package/src/components/Input/Input.vue +112 -0
  47. package/src/components/InputGroup/InputGroup.vue +102 -0
  48. package/src/components/Kbd/Kbd.tsx +2 -12
  49. package/src/components/Kbd/Kbd.vue +21 -0
  50. package/src/components/Link/Link.vue +38 -0
  51. package/src/components/LivePill/LivePill.tsx +11 -39
  52. package/src/components/LivePill/LivePill.vue +152 -0
  53. package/src/components/Meter/Meter.vue +88 -0
  54. package/src/components/MorphButton/MorphButton.tsx +11 -67
  55. package/src/components/MorphButton/MorphButton.vue +120 -0
  56. package/src/components/NumberInput/NumberInput.tsx +11 -48
  57. package/src/components/NumberInput/NumberInput.vue +184 -0
  58. package/src/components/Pagination/Pagination.tsx +2 -15
  59. package/src/components/Pagination/Pagination.vue +87 -0
  60. package/src/components/Pagination/range.ts +15 -0
  61. package/src/components/PasswordInput/PasswordInput.vue +53 -0
  62. package/src/components/PickerWheel/DateWheel.vue +48 -0
  63. package/src/components/PickerWheel/PickerWheel.tsx +15 -129
  64. package/src/components/PickerWheel/PickerWheel.vue +77 -0
  65. package/src/components/PickerWheel/TimeWheel.vue +50 -0
  66. package/src/components/PickerWheel/WheelColumn.vue +70 -0
  67. package/src/components/Popover/Popover.vue +108 -0
  68. package/src/components/ProgressBar/ProgressBar.vue +48 -0
  69. package/src/components/Prose/Prose.vue +18 -0
  70. package/src/components/Radio/Radio.vue +49 -0
  71. package/src/components/Radio/RadioGroup.vue +69 -0
  72. package/src/components/Retime/Retime.tsx +7 -40
  73. package/src/components/Retime/Retime.vue +64 -0
  74. package/src/components/RulerScrubber/RulerScrubber.tsx +9 -38
  75. package/src/components/RulerScrubber/RulerScrubber.vue +166 -0
  76. package/src/components/ScrollArea/ScrollArea.tsx +17 -129
  77. package/src/components/ScrollArea/ScrollArea.vue +58 -0
  78. package/src/components/SearchInput/SearchInput.tsx +2 -15
  79. package/src/components/SearchInput/SearchInput.vue +70 -0
  80. package/src/components/SegmentedControl/SegmentedControl.tsx +7 -51
  81. package/src/components/SegmentedControl/SegmentedControl.vue +111 -0
  82. package/src/components/Select/Select.tsx +16 -47
  83. package/src/components/Select/Select.vue +236 -0
  84. package/src/components/Sheet/Sheet.tsx +52 -231
  85. package/src/components/Sheet/Sheet.vue +249 -0
  86. package/src/components/Skeleton/Skeleton.vue +38 -0
  87. package/src/components/Slider/Slider.tsx +25 -84
  88. package/src/components/Slider/Slider.vue +113 -0
  89. package/src/components/Spinner/Spinner.vue +30 -0
  90. package/src/components/Split/Split.vue +34 -0
  91. package/src/components/SplitFlap/SplitFlap.tsx +11 -175
  92. package/src/components/SplitFlap/SplitFlap.vue +52 -0
  93. package/src/components/Stack/Stack.vue +22 -0
  94. package/src/components/SwipeDeck/SwipeDeck.tsx +30 -194
  95. package/src/components/SwipeDeck/SwipeDeck.vue +168 -0
  96. package/src/components/Switch/Switch.tsx +6 -75
  97. package/src/components/Switch/Switch.vue +66 -0
  98. package/src/components/Table/Table.module.css +12 -3
  99. package/src/components/Table/Table.tsx +8 -59
  100. package/src/components/Table/Table.vue +274 -0
  101. package/src/components/TableOfContents/TableOfContents.vue +90 -0
  102. package/src/components/Tabs/Tab.vue +37 -0
  103. package/src/components/Tabs/TabList.vue +47 -0
  104. package/src/components/Tabs/TabPanel.vue +26 -0
  105. package/src/components/Tabs/Tabs.module.css +2 -2
  106. package/src/components/Tabs/Tabs.tsx +11 -84
  107. package/src/components/Tabs/Tabs.vue +33 -0
  108. package/src/components/Tabs/tabsContext.ts +15 -0
  109. package/src/components/Tag/Tag.tsx +6 -26
  110. package/src/components/Tag/Tag.vue +63 -0
  111. package/src/components/Textarea/Textarea.tsx +2 -22
  112. package/src/components/Textarea/Textarea.vue +120 -0
  113. package/src/components/ThemeToggle/ThemeToggle.tsx +10 -84
  114. package/src/components/ThemeToggle/ThemeToggle.vue +90 -0
  115. package/src/components/Toast/Toast.tsx +34 -264
  116. package/src/components/Toast/Toast.vue +138 -0
  117. package/src/components/Toast/ToastItem.vue +108 -0
  118. package/src/components/Toggle/Toggle.vue +52 -0
  119. package/src/components/Tooltip/Tooltip.tsx +17 -48
  120. package/src/components/Tooltip/Tooltip.vue +95 -0
  121. package/src/components/VisuallyHidden/VisuallyHidden.vue +17 -0
  122. package/src/internal/FieldMessage.vue +41 -0
  123. package/src/internal/Roll.vue +20 -0
  124. package/src/internal/focus.ts +4 -47
  125. package/src/internal/icons.module.css +39 -27
  126. package/src/internal/layers.ts +7 -61
  127. package/src/internal/motion/alert.ts +17 -0
  128. package/src/internal/motion/buttonGroup.ts +21 -0
  129. package/src/internal/motion/checkbox.ts +39 -0
  130. package/src/internal/motion/collapseOut.ts +26 -0
  131. package/src/internal/motion/copyButton.ts +48 -0
  132. package/src/internal/motion/dial.ts +137 -0
  133. package/src/internal/motion/fab.ts +14 -0
  134. package/src/internal/motion/floating.ts +58 -0
  135. package/src/internal/motion/focus.ts +53 -0
  136. package/src/internal/motion/formField.ts +19 -0
  137. package/src/internal/motion/holdToConfirm.ts +147 -0
  138. package/src/internal/motion/keys.ts +42 -0
  139. package/src/internal/motion/layers.ts +78 -0
  140. package/src/internal/motion/listbox.ts +69 -0
  141. package/src/internal/motion/livePill.ts +71 -0
  142. package/src/internal/motion/menuKeys.ts +58 -0
  143. package/src/internal/motion/morphButton.ts +71 -0
  144. package/src/internal/motion/numberInput.ts +57 -0
  145. package/src/internal/motion/pickerWheel.ts +166 -0
  146. package/src/internal/motion/retime.ts +45 -0
  147. package/src/internal/motion/ruler.ts +57 -0
  148. package/src/internal/motion/scrollArea.ts +133 -0
  149. package/src/internal/motion/scrubLook.ts +15 -0
  150. package/src/internal/motion/segmented.ts +63 -0
  151. package/src/internal/motion/sheetDetents.ts +271 -0
  152. package/src/internal/motion/slider.ts +108 -0
  153. package/src/internal/motion/splitFlap.ts +205 -0
  154. package/src/internal/motion/swipeDeck.ts +236 -0
  155. package/src/internal/motion/switchThumb.ts +83 -0
  156. package/src/internal/motion/table.ts +77 -0
  157. package/src/internal/motion/tabs.ts +105 -0
  158. package/src/internal/motion/textarea.ts +22 -0
  159. package/src/internal/motion/themeIcon.ts +91 -0
  160. package/src/internal/motion/themeReveal.ts +71 -0
  161. package/src/internal/motion/toast.ts +291 -0
  162. package/src/internal/motion/tooltip.ts +58 -0
  163. package/src/internal/themeReveal.ts +3 -61
  164. package/src/internal/useFloating.ts +9 -49
  165. package/src/internal/useScrub.ts +1 -13
  166. package/src/internal/vue/trigger.ts +18 -0
  167. package/src/internal/vue/useFloating.ts +38 -0
  168. package/src/internal/vue/usePresence.ts +21 -0
  169. package/src/internal/vue/useScrub.ts +40 -0
  170. package/src/internal/vueIcons.ts +134 -0
  171. package/src/tokens.css +5 -0
  172. package/src/internal/relativeTime.ts +0 -26
@@ -0,0 +1,34 @@
1
+ <script setup lang="ts">
2
+ import { space, type Space } from '../../internal/space'
3
+ import styles from './Cluster.module.css'
4
+
5
+ // The Vue Cluster: the same look (Cluster.module.css) as the React one. Other attributes go to the element.
6
+ withDefaults(
7
+ defineProps<{
8
+ /** Space between items, as a step of the space scale (0 to 12, read as --gooee-space-N). */
9
+ gap?: Space
10
+ /** Space between wrapped rows. Defaults to the same step as gap. */
11
+ rowGap?: Space
12
+ /** Lines items up inside a row. "baseline" keeps mixed text sizes on one line. */
13
+ align?: 'start' | 'center' | 'end' | 'baseline' | 'stretch'
14
+ /** Places items along the row. "between" pushes the first and last item to the edges. */
15
+ justify?: 'start' | 'center' | 'end' | 'between'
16
+ /** Lets items flow onto the next row when they run out of room. */
17
+ wrap?: boolean
18
+ /** Element to render, so a row of links can be a nav or a list. */
19
+ as?: 'div' | 'section' | 'nav' | 'header' | 'footer' | 'ul' | 'ol'
20
+ }>(),
21
+ { gap: 3, align: 'center', justify: 'start', wrap: true, as: 'div' },
22
+ )
23
+ defineSlots<{ default?: () => unknown }>()
24
+ </script>
25
+
26
+ <template>
27
+ <component
28
+ :is="as"
29
+ :class="[styles.root, styles[`align-${align}`], styles[`justify-${justify}`], !wrap && styles.nowrap]"
30
+ :style="{ '--cluster-gap': space(gap), '--cluster-row-gap': space(rowGap ?? gap) }"
31
+ >
32
+ <slot />
33
+ </component>
34
+ </template>
@@ -0,0 +1,45 @@
1
+ <script setup lang="ts">
2
+ import { computed } from 'vue'
3
+ import CopyButton from '../CopyButton/CopyButton.vue'
4
+ import { guessLanguage, tokenize, type CodeLanguage } from './highlight'
5
+ import styles from './CodeBlock.module.css'
6
+
7
+ // The Vue CodeBlock: the same look (CodeBlock.module.css) and colouring (highlight.ts) as the React one.
8
+ const props = withDefaults(
9
+ defineProps<{
10
+ /** The code to show and copy. */
11
+ code: string
12
+ /** Sets the colouring. Undefined guesses from the first line. */
13
+ language?: CodeLanguage
14
+ /** File name or short title in the header row. Undefined shows the language. */
15
+ title?: string
16
+ /** Shows a line number before each line. They are never copied or read out. */
17
+ lineNumbers?: boolean
18
+ /** Shows the copy button in the header row. */
19
+ copyable?: boolean
20
+ /** Screen reader name for the copy button. */
21
+ copyLabel?: string
22
+ /** Screen reader name for the scrollable code. Undefined uses the title. */
23
+ label?: string
24
+ }>(),
25
+ { lineNumbers: false, copyable: true, copyLabel: 'Copy code' },
26
+ )
27
+ /** header: replaces the title in the header row, for example with tabs that switch the code. */
28
+ defineSlots<{ header?: () => unknown }>()
29
+
30
+ const NAMES: Record<CodeLanguage, string> = { tsx: 'TSX', html: 'HTML', css: 'CSS', shell: 'Terminal' }
31
+ const lang = computed(() => props.language ?? guessLanguage(props.code))
32
+ const numbers = computed(() => Array.from({ length: props.code.replace(/\n$/, '').split('\n').length }, (_, i) => i + 1).join('\n'))
33
+ const tokens = computed(() => tokenize(props.code, lang.value))
34
+ </script>
35
+
36
+ <template>
37
+ <div :class="styles.root">
38
+ <div :class="styles.head">
39
+ <slot name="header"><span :class="styles.title">{{ title ?? NAMES[lang] }}</span></slot>
40
+ <CopyButton v-if="copyable" :value="code" :label="copyLabel" size="sm" :class="styles.copy" />
41
+ </div>
42
+ <!-- Kept on one line: a pre keeps every space and line break in the template. -->
43
+ <pre :class="styles.pre" tabindex="0" :aria-label="label ?? (title ? `${title} code` : 'Code example')" :data-lines="lineNumbers || undefined"><span v-if="lineNumbers" :class="styles.gutter" aria-hidden="true">{{ numbers }}</span><code :class="styles.code"><template v-for="(t, i) in tokens" :key="i"><span v-if="t.kind" :class="styles[t.kind]">{{ t.text }}</span><template v-else>{{ t.text }}</template></template></code></pre>
44
+ </div>
45
+ </template>
@@ -0,0 +1,59 @@
1
+ <script setup lang="ts">
2
+ import { computed, ref, useId } from 'vue'
3
+ import { ChevronDownIcon } from '../../internal/vueIcons'
4
+ import styles from './Collapsible.module.css'
5
+
6
+ // The Vue Collapsible: the same look (Collapsible.module.css) as the React one. For your own button, use the
7
+ // trigger slot and bind what it gives: <template #trigger="t"><Button v-bind="t">Details</Button></template>.
8
+ const props = withDefaults(
9
+ defineProps<{
10
+ /** Text for the built-in toggle button. The label slot replaces it. */
11
+ label?: string
12
+ /** Starting open state when there is no v-model:open. */
13
+ defaultOpen?: boolean
14
+ /** Stops the panel from opening or closing. */
15
+ disabled?: boolean
16
+ }>(),
17
+ { defaultOpen: false },
18
+ )
19
+ /** Open state. Use v-model:open, or leave it out and the part keeps its own state. */
20
+ const model = defineModel<boolean | undefined>('open', { default: undefined })
21
+ const slots = defineSlots<{
22
+ default?: () => unknown
23
+ label?: () => unknown
24
+ trigger?: (props: { 'aria-expanded': boolean; 'aria-controls': string; disabled?: boolean; 'aria-disabled'?: boolean; onClick: () => void }) => unknown
25
+ }>()
26
+
27
+ const id = useId()
28
+ const local = ref(props.defaultOpen)
29
+ const open = computed(() => model.value ?? local.value)
30
+ const toggle = () => {
31
+ if (props.disabled) return
32
+ const next = !open.value
33
+ local.value = next
34
+ model.value = next
35
+ }
36
+ // Only set when disabled, so a trigger's own disabled attribute is kept otherwise.
37
+ const triggerProps = computed(() => ({
38
+ 'aria-expanded': open.value,
39
+ 'aria-controls': `${id}-panel`,
40
+ ...(props.disabled ? { disabled: true, 'aria-disabled': true } : null),
41
+ onClick: toggle,
42
+ }))
43
+ </script>
44
+
45
+ <template>
46
+ <div :class="styles.root" :data-open="open || undefined">
47
+ <slot v-if="slots.trigger" name="trigger" v-bind="triggerProps" />
48
+ <button v-else type="button" :class="styles.trigger" :aria-expanded="open" :aria-controls="`${id}-panel`" :disabled="disabled" @click="toggle">
49
+ <span :class="styles.label"><slot name="label">{{ label }}</slot></span>
50
+ <ChevronDownIcon :class="styles.chevron" />
51
+ </button>
52
+ <!-- Grid rows animate from 0fr to 1fr, so the height follows the content without measuring. -->
53
+ <div :id="`${id}-panel`" :class="styles.panel" :inert="!open">
54
+ <div :class="styles.inner">
55
+ <div :class="styles.content"><slot /></div>
56
+ </div>
57
+ </div>
58
+ </div>
59
+ </template>
@@ -0,0 +1,22 @@
1
+ <script setup lang="ts">
2
+ import { space, type Space } from '../../internal/space'
3
+ import styles from './Container.module.css'
4
+
5
+ // The Vue Container: the same look (Container.module.css) as the React one. Other attributes go to the element.
6
+ withDefaults(
7
+ defineProps<{
8
+ /** Widest the content gets, from the --gooee-container-* tokens. "full" never stops growing. */
9
+ size?: 'sm' | 'md' | 'lg' | 'xl' | 'full'
10
+ /** Space on the left and right, as a step of the space scale. The notch area on a phone wins when it is wider. */
11
+ padding?: Space
12
+ /** Element to render, such as main for the page body. */
13
+ as?: 'div' | 'main' | 'section' | 'article' | 'header' | 'footer'
14
+ }>(),
15
+ { size: 'lg', padding: 5, as: 'div' },
16
+ )
17
+ defineSlots<{ default?: () => unknown }>()
18
+ </script>
19
+
20
+ <template>
21
+ <component :is="as" :class="[styles.root, styles[size]]" :style="{ '--container-pad': space(padding) }"><slot /></component>
22
+ </template>
@@ -4,6 +4,7 @@ import { useEffect, useLayoutEffect, useRef, useState } from 'react'
4
4
  import { cx } from '../../internal/cx'
5
5
  import { CopyIcon, XIcon } from '../../internal/icons'
6
6
  import { copyRun, type CopyRun } from '../../internal/liquidMore'
7
+ import { capShift, writeText } from '../../internal/motion/copyButton'
7
8
  import styles from './CopyButton.module.css'
8
9
 
9
10
  export type CopyButtonProps = {
@@ -27,27 +28,6 @@ export type CopyButtonProps = {
27
28
  className?: string
28
29
  }
29
30
 
30
- async function writeText(text: string) {
31
- try {
32
- await navigator.clipboard.writeText(text)
33
- return true
34
- } catch {
35
- // Fallback for http pages and older browsers.
36
- const ta = document.createElement('textarea')
37
- ta.value = text
38
- ta.setAttribute('readonly', '')
39
- ta.style.position = 'fixed'
40
- ta.style.opacity = '0'
41
- const prev = document.activeElement as HTMLElement | null
42
- document.body.appendChild(ta)
43
- ta.select()
44
- const ok = document.execCommand('copy')
45
- ta.remove()
46
- prev?.focus()
47
- return ok
48
- }
49
- }
50
-
51
31
  export function CopyButton({
52
32
  value,
53
33
  label = 'Copy',
@@ -88,34 +68,8 @@ export function CopyButton({
88
68
  }, [copied, status])
89
69
  useLayoutEffect(() => () => run.current?.stop(), [])
90
70
 
91
- // With a label, the icon sits on the middle of the label's capital letters, not of its line.
92
- useLayoutEffect(() => {
93
- const root = rootRef.current
94
- const icons = iconsRef.current
95
- const text = labelRef.current?.firstChild
96
- root?.style.removeProperty('--cap-shift')
97
- if (!root || !icons || !text) return
98
- const place = () => {
99
- root.style.removeProperty('--cap-shift')
100
- const range = document.createRange()
101
- range.selectNodeContents(text)
102
- const box = range.getBoundingClientRect()
103
- const look = getComputedStyle(root)
104
- const pen = document.createElement('canvas').getContext('2d')
105
- if (!pen || !box.height) return
106
- pen.font = `${look.fontWeight} ${look.fontSize} ${look.fontFamily}`
107
- const m = pen.measureText('H')
108
- const cap = box.top + m.fontBoundingBoxAscent - m.actualBoundingBoxAscent / 2
109
- const r = icons.getBoundingClientRect()
110
- root.style.setProperty('--cap-shift', `${Math.round((cap - r.top - r.height / 2) * 100) / 100}px`)
111
- }
112
- place()
113
- let live = true
114
- document.fonts?.ready.then(() => live && place())
115
- return () => {
116
- live = false
117
- }
118
- }, [showLabel, label, size])
71
+ // With a label, the icon sits on the middle of the label's capital letters (motion/copyButton.ts).
72
+ useLayoutEffect(() => capShift(rootRef.current, iconsRef.current, labelRef.current?.firstChild), [showLabel, label, size])
119
73
 
120
74
  const copy = async () => {
121
75
  const ok = await writeText(value)
@@ -0,0 +1,116 @@
1
+ <script setup lang="ts">
2
+ import { computed, onBeforeUnmount, ref, watch } from 'vue'
3
+ import { CopyIcon, XIcon } from '../../internal/vueIcons'
4
+ import { copyRun, type CopyRun } from '../../internal/motion/liquidMore'
5
+ import { capShift, writeText } from '../../internal/motion/copyButton'
6
+ import styles from './CopyButton.module.css'
7
+
8
+ // The Vue CopyButton: the same look (CopyButton.module.css), drop and check as the React one.
9
+ const props = withDefaults(
10
+ defineProps<{
11
+ /** Text to put on the clipboard. */
12
+ value: string
13
+ /** Accessible name, and the visible text when showLabel is on. */
14
+ label?: string
15
+ /** Shown and spoken after a successful copy. */
16
+ copiedLabel?: string
17
+ /** Shown and spoken when the browser blocks the copy. */
18
+ failedLabel?: string
19
+ /** Shows the label as text next to the icon. */
20
+ showLabel?: boolean
21
+ /** Size of the button. */
22
+ size?: 'sm' | 'md'
23
+ /** How long the check or the failed state stays, in ms. */
24
+ resetAfter?: number
25
+ }>(),
26
+ { label: 'Copy', copiedLabel: 'Copied', failedLabel: 'Could not copy', showLabel: false, size: 'md', resetAfter: 1800 },
27
+ )
28
+ /** Fires after the text is copied, with the copied text. Not fired if copying fails. */
29
+ const emit = defineEmits<{ copy: [value: string] }>()
30
+
31
+ const status = ref<'idle' | 'copied' | 'failed'>('idle')
32
+ let timer: number | undefined
33
+
34
+ const rootEl = ref<HTMLButtonElement | null>(null)
35
+ const iconsEl = ref<HTMLSpanElement | null>(null)
36
+ const labelEl = ref<HTMLSpanElement | null>(null)
37
+ let pressedAt: [number, number] | null = null
38
+ let run: CopyRun | null = null
39
+
40
+ // A copy pours a drop from where it was pressed into the icon (motion/liquidMore.ts); going idle plays it back.
41
+ const copied = computed(() => status.value === 'copied')
42
+ watch(
43
+ copied,
44
+ (now) => {
45
+ const icons = iconsEl.value
46
+ // A failed copy shows its cross at once, with nothing poured.
47
+ if (!icons || status.value === 'failed') {
48
+ run?.stop()
49
+ run = null
50
+ return
51
+ }
52
+ const at = pressedAt
53
+ pressedAt = null
54
+ run = copyRun(icons, now ? 1 : 0, at, styles.pour, run)
55
+ },
56
+ { flush: 'post' },
57
+ )
58
+
59
+ // With a label, the icon sits on the middle of the label's capital letters (motion/copyButton.ts).
60
+ let unplace = () => {}
61
+ watch(
62
+ [() => props.showLabel, () => props.label, () => props.size, labelEl],
63
+ () => {
64
+ unplace()
65
+ unplace = capShift(rootEl.value, iconsEl.value, labelEl.value?.firstChild)
66
+ },
67
+ { flush: 'post' },
68
+ )
69
+
70
+ onBeforeUnmount(() => {
71
+ window.clearTimeout(timer)
72
+ unplace()
73
+ run?.stop()
74
+ })
75
+
76
+ const copy = async () => {
77
+ const ok = await writeText(props.value)
78
+ status.value = ok ? 'copied' : 'failed'
79
+ if (ok) emit('copy', props.value)
80
+ window.clearTimeout(timer)
81
+ timer = window.setTimeout(() => (status.value = 'idle'), props.resetAfter)
82
+ }
83
+
84
+ const onClick = (e: MouseEvent) => {
85
+ const r = iconsEl.value?.getBoundingClientRect()
86
+ // A key press (no pointer) pours from the icon's middle.
87
+ pressedAt = r && e.detail ? [e.clientX - r.left, e.clientY - r.top] : null
88
+ copy()
89
+ }
90
+ </script>
91
+
92
+ <template>
93
+ <button
94
+ ref="rootEl"
95
+ type="button"
96
+ :class="[styles.root, styles[size], showLabel && styles.withLabel]"
97
+ :data-copied="status === 'copied' || undefined"
98
+ :data-failed="status === 'failed' || undefined"
99
+ :aria-label="showLabel ? undefined : label"
100
+ @click="onClick"
101
+ >
102
+ <span ref="iconsEl" :class="styles.icons" aria-hidden="true">
103
+ <CopyIcon :class="styles.copy" />
104
+ <svg viewBox="0 0 24 24" :class="styles.check">
105
+ <path d="M5 12.5l4.5 4.5L19 7.5" pathLength="1" />
106
+ </svg>
107
+ <XIcon :class="styles.fail" />
108
+ </span>
109
+ <span v-if="showLabel" :class="styles.labels">
110
+ <span ref="labelEl" :class="styles.labelIdle">{{ label }}</span>
111
+ <span :class="styles.labelDone" aria-hidden="true">{{ copiedLabel }}</span>
112
+ <span :class="styles.labelFailed" aria-hidden="true">{{ failedLabel }}</span>
113
+ </span>
114
+ <span :class="styles.srOnly" aria-live="polite">{{ status === 'copied' ? copiedLabel : status === 'failed' ? failedLabel : '' }}</span>
115
+ </button>
116
+ </template>
@@ -1,11 +1,12 @@
1
1
  'use client'
2
2
 
3
- import { useEffect, useId, useLayoutEffect, useRef, useState, type ComponentPropsWithRef, type PointerEvent, type ReactNode } from 'react'
3
+ import { useEffect, useId, useLayoutEffect, useRef, useState, type ComponentPropsWithRef, type ReactNode } from 'react'
4
4
  import { cx } from '../../internal/cx'
5
- import { clamp, lastStep, pull, roundTo, steps, wheelSteps, stepKey } from '../../internal/feel'
5
+ import { clamp, pull, roundTo, wheelSteps } from '../../internal/feel'
6
+ import { arcTouch, CX, CY, DOT, dialScale, dialScrub, H, KNOB, polar, SWEEP, W, type Rim } from '../../internal/motion/dial'
6
7
  import { Roll } from '../../internal/Roll'
7
8
  import { useControllable } from '../../internal/useControllable'
8
- import { ink, sideways, tokenNumber, useOnChange, useScrub } from '../../internal/useScrub'
9
+ import { ink, tokenNumber, useOnChange, useScrub } from '../../internal/useScrub'
9
10
  import styles from './Dial.module.css'
10
11
 
11
12
  export type DialProps = Omit<ComponentPropsWithRef<'div'>, 'defaultValue' | 'onChange' | 'children'> & {
@@ -43,41 +44,6 @@ export type DialProps = Omit<ComponentPropsWithRef<'div'>, 'defaultValue' | 'onC
43
44
  haptics?: boolean
44
45
  }
45
46
 
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
47
  export function Dial({
82
48
  label,
83
49
  value: valueProp,
@@ -101,68 +67,18 @@ export function Dial({
101
67
  const labelId = useId()
102
68
  const detailId = useId()
103
69
  const goo = useId().replace(/:/g, '')
104
- const top = lastStep(min, max, step)
70
+ const scale = { min, max, step, marks, variant }
71
+ const { top, all, labelled, land, stepDeg } = dialScale(scale)
105
72
  const [raw, setValue] = useControllable(valueProp, defaultValue ?? min, onValueChange)
106
73
  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
74
  const strongSet = new Set(strong.map((v) => roundTo(v, step, min)))
110
- const land = (p: number) => clamp(roundTo(p, step, min), min, top)
111
75
  const markText = formatMark ?? formatValue
112
- const stepDeg = SWEEP / Math.max(1, all.length - 1)
113
76
  // 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)
77
+ const [rim, setRim] = useState<Rim | null>(null)
115
78
  const wheel = useRef(wheelSteps())
116
79
 
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
- })
80
+ // The drag, keys, tap and wheel (motion/dial.ts) on the shared scrubber.
81
+ const sc = useScrub({ value, ...dialScrub(scale, rim, wheel.current), onSettle: setValue, haptics })
166
82
 
167
83
  useLayoutEffect(() => {
168
84
  if (variant !== 'arc') return
@@ -170,35 +86,11 @@ export function Dial({
170
86
  setRim({ r: tokenNumber(el, '--gooee-dial-arc-radius'), gap: tokenNumber(el, '--gooee-dial-arc-gap') })
171
87
  }, [variant, sc.ref])
172
88
 
173
- // The arc lets an up-and-down swipe scroll the page, but a finger following the curve also moves up or
174
- // down. Once a touch moves more sideways than half its rise, it is a turn: the page stops taking it.
89
+ // The arc takes only sideways touches, so the page still scrolls under a finger on it (motion/dial.ts).
175
90
  useEffect(() => {
176
- if (variant !== 'arc') return
177
91
  const el = sc.ref.current
178
- if (!el) return
179
- let from: { x: number; y: number } | null = null
180
- let turning = false
181
- const start = (e: TouchEvent) => {
182
- from = { x: e.touches[0].clientX, y: e.touches[0].clientY }
183
- turning = false
184
- }
185
- const move = (e: TouchEvent) => {
186
- if (!from) return
187
- if (!turning) {
188
- const dx = Math.abs(e.touches[0].clientX - from.x)
189
- const dy = Math.abs(e.touches[0].clientY - from.y)
190
- if (dx + dy < 2) return
191
- turning = dx > dy / 2
192
- if (!turning) from = null
193
- }
194
- if (turning && e.cancelable) e.preventDefault()
195
- }
196
- el.addEventListener('touchstart', start, { passive: true })
197
- el.addEventListener('touchmove', move, { passive: false })
198
- return () => {
199
- el.removeEventListener('touchstart', start)
200
- el.removeEventListener('touchmove', move)
201
- }
92
+ if (variant !== 'arc' || !el) return
93
+ return arcTouch(el)
202
94
  }, [variant, sc.ref])
203
95
 
204
96
  const shown = land(sc.at)