gooee 0.48.0 → 0.51.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 (185) hide show
  1. package/package.json +4 -2
  2. package/scripts/add.js +28 -6
  3. package/src/components/Accordion/Accordion.vue +62 -0
  4. package/src/components/Accordion/AccordionItem.vue +45 -0
  5. package/src/components/Accordion/accordionContext.ts +6 -0
  6. package/src/components/Alert/Alert.tsx +7 -27
  7. package/src/components/Alert/Alert.vue +59 -0
  8. package/src/components/AlertDialog/AlertDialog.vue +126 -0
  9. package/src/components/AnimatedNumber/AnimatedNumber.vue +36 -0
  10. package/src/components/AspectRatio/AspectRatio.vue +17 -0
  11. package/src/components/Avatar/Avatar.vue +56 -0
  12. package/src/components/AvatarGroup/AvatarGroup.vue +42 -0
  13. package/src/components/Badge/Badge.vue +32 -0
  14. package/src/components/Breadcrumb/Breadcrumb.vue +58 -0
  15. package/src/components/Button/Button.vue +130 -0
  16. package/src/components/ButtonGroup/ButtonGroup.tsx +4 -21
  17. package/src/components/ButtonGroup/ButtonGroup.vue +33 -0
  18. package/src/components/Card/Card.vue +34 -0
  19. package/src/components/Center/Center.vue +32 -0
  20. package/src/components/Checkbox/Checkbox.tsx +8 -25
  21. package/src/components/Checkbox/Checkbox.vue +108 -0
  22. package/src/components/CheckboxGroup/CheckboxGroup.vue +76 -0
  23. package/src/components/Cluster/Cluster.vue +34 -0
  24. package/src/components/CodeBlock/CodeBlock.vue +45 -0
  25. package/src/components/Collapsible/Collapsible.vue +59 -0
  26. package/src/components/Container/Container.vue +22 -0
  27. package/src/components/CopyButton/CopyButton.tsx +3 -49
  28. package/src/components/CopyButton/CopyButton.vue +116 -0
  29. package/src/components/Dial/Dial.tsx +12 -120
  30. package/src/components/Dial/Dial.vue +228 -0
  31. package/src/components/Dialog/Dialog.vue +139 -0
  32. package/src/components/Divider/Divider.vue +27 -0
  33. package/src/components/DropdownMenu/DropdownMenu.tsx +11 -46
  34. package/src/components/DropdownMenu/DropdownMenu.vue +185 -0
  35. package/src/components/EmptyState/EmptyState.vue +33 -0
  36. package/src/components/Fab/Fab.tsx +4 -14
  37. package/src/components/Fab/Fab.vue +115 -0
  38. package/src/components/Fieldset/Fieldset.vue +42 -0
  39. package/src/components/FormField/FormField.tsx +2 -17
  40. package/src/components/FormField/FormField.vue +64 -0
  41. package/src/components/Grid/Grid.vue +43 -0
  42. package/src/components/HoldToConfirm/HoldToConfirm.tsx +13 -142
  43. package/src/components/HoldToConfirm/HoldToConfirm.vue +281 -0
  44. package/src/components/IconButton/IconButton.vue +25 -0
  45. package/src/components/Input/Input.vue +112 -0
  46. package/src/components/InputGroup/InputGroup.vue +102 -0
  47. package/src/components/Kbd/Kbd.tsx +2 -12
  48. package/src/components/Kbd/Kbd.vue +21 -0
  49. package/src/components/Link/Link.vue +38 -0
  50. package/src/components/LivePill/LivePill.tsx +12 -40
  51. package/src/components/LivePill/LivePill.vue +152 -0
  52. package/src/components/Meter/Meter.vue +88 -0
  53. package/src/components/MorphButton/MorphButton.tsx +11 -67
  54. package/src/components/MorphButton/MorphButton.vue +120 -0
  55. package/src/components/NumberInput/NumberInput.tsx +11 -48
  56. package/src/components/NumberInput/NumberInput.vue +184 -0
  57. package/src/components/Pagination/Pagination.tsx +2 -15
  58. package/src/components/Pagination/Pagination.vue +87 -0
  59. package/src/components/Pagination/range.ts +15 -0
  60. package/src/components/PasswordInput/PasswordInput.vue +53 -0
  61. package/src/components/PickerWheel/DateWheel.vue +48 -0
  62. package/src/components/PickerWheel/PickerWheel.tsx +15 -129
  63. package/src/components/PickerWheel/PickerWheel.vue +77 -0
  64. package/src/components/PickerWheel/TimeWheel.vue +50 -0
  65. package/src/components/PickerWheel/WheelColumn.vue +70 -0
  66. package/src/components/Popover/Popover.vue +108 -0
  67. package/src/components/ProgressBar/ProgressBar.vue +48 -0
  68. package/src/components/Prose/Prose.vue +18 -0
  69. package/src/components/Radio/Radio.vue +49 -0
  70. package/src/components/Radio/RadioGroup.vue +69 -0
  71. package/src/components/Retime/Retime.tsx +7 -40
  72. package/src/components/Retime/Retime.vue +64 -0
  73. package/src/components/RulerScrubber/RulerScrubber.tsx +9 -38
  74. package/src/components/RulerScrubber/RulerScrubber.vue +166 -0
  75. package/src/components/ScrollArea/ScrollArea.tsx +17 -129
  76. package/src/components/ScrollArea/ScrollArea.vue +58 -0
  77. package/src/components/SearchInput/SearchInput.tsx +2 -15
  78. package/src/components/SearchInput/SearchInput.vue +70 -0
  79. package/src/components/SegmentedControl/SegmentedControl.tsx +7 -51
  80. package/src/components/SegmentedControl/SegmentedControl.vue +111 -0
  81. package/src/components/Select/Select.tsx +16 -47
  82. package/src/components/Select/Select.vue +236 -0
  83. package/src/components/Sheet/Sheet.tsx +52 -231
  84. package/src/components/Sheet/Sheet.vue +249 -0
  85. package/src/components/Skeleton/Skeleton.vue +38 -0
  86. package/src/components/Slider/Slider.tsx +25 -84
  87. package/src/components/Slider/Slider.vue +113 -0
  88. package/src/components/Spinner/Spinner.vue +30 -0
  89. package/src/components/Split/Split.vue +34 -0
  90. package/src/components/SplitFlap/SplitFlap.tsx +11 -175
  91. package/src/components/SplitFlap/SplitFlap.vue +52 -0
  92. package/src/components/Stack/Stack.vue +22 -0
  93. package/src/components/SwipeDeck/SwipeDeck.tsx +30 -194
  94. package/src/components/SwipeDeck/SwipeDeck.vue +168 -0
  95. package/src/components/Switch/Switch.tsx +6 -75
  96. package/src/components/Switch/Switch.vue +66 -0
  97. package/src/components/Table/Table.module.css +12 -3
  98. package/src/components/Table/Table.tsx +8 -59
  99. package/src/components/Table/Table.vue +274 -0
  100. package/src/components/TableOfContents/TableOfContents.vue +90 -0
  101. package/src/components/Tabs/Tab.vue +37 -0
  102. package/src/components/Tabs/TabList.vue +47 -0
  103. package/src/components/Tabs/TabPanel.vue +26 -0
  104. package/src/components/Tabs/Tabs.module.css +2 -2
  105. package/src/components/Tabs/Tabs.tsx +11 -84
  106. package/src/components/Tabs/Tabs.vue +33 -0
  107. package/src/components/Tabs/tabsContext.ts +15 -0
  108. package/src/components/Tag/Tag.tsx +6 -26
  109. package/src/components/Tag/Tag.vue +63 -0
  110. package/src/components/Textarea/Textarea.tsx +2 -22
  111. package/src/components/Textarea/Textarea.vue +120 -0
  112. package/src/components/ThemeToggle/ThemeToggle.tsx +10 -84
  113. package/src/components/ThemeToggle/ThemeToggle.vue +90 -0
  114. package/src/components/Toast/Toast.tsx +34 -264
  115. package/src/components/Toast/Toast.vue +138 -0
  116. package/src/components/Toast/ToastItem.vue +108 -0
  117. package/src/components/Toggle/Toggle.vue +52 -0
  118. package/src/components/Tooltip/Tooltip.tsx +17 -48
  119. package/src/components/Tooltip/Tooltip.vue +95 -0
  120. package/src/components/VisuallyHidden/VisuallyHidden.vue +17 -0
  121. package/src/internal/FieldMessage.vue +41 -0
  122. package/src/internal/Roll.vue +20 -0
  123. package/src/internal/fling.ts +29 -106
  124. package/src/internal/focus.ts +4 -79
  125. package/src/internal/icons.module.css +39 -27
  126. package/src/internal/layers.ts +7 -61
  127. package/src/internal/liquid.ts +26 -213
  128. package/src/internal/liquidMatter.ts +9 -181
  129. package/src/internal/liquidMore.ts +6 -669
  130. package/src/internal/motion/alert.ts +17 -0
  131. package/src/internal/motion/buttonGroup.ts +21 -0
  132. package/src/internal/motion/checkbox.ts +39 -0
  133. package/src/internal/motion/collapseOut.ts +26 -0
  134. package/src/internal/motion/copyButton.ts +48 -0
  135. package/src/internal/motion/dial.ts +137 -0
  136. package/src/internal/motion/fab.ts +14 -0
  137. package/src/internal/motion/fling.ts +147 -0
  138. package/src/internal/motion/floating.ts +58 -0
  139. package/src/internal/motion/focus.ts +88 -0
  140. package/src/internal/motion/formField.ts +19 -0
  141. package/src/internal/motion/holdToConfirm.ts +147 -0
  142. package/src/internal/motion/index.ts +20 -0
  143. package/src/internal/motion/keys.ts +42 -0
  144. package/src/internal/motion/layers.ts +78 -0
  145. package/src/internal/motion/liquid.ts +241 -0
  146. package/src/internal/motion/liquidMatter.ts +198 -0
  147. package/src/internal/motion/liquidMore.ts +676 -0
  148. package/src/internal/motion/listbox.ts +69 -0
  149. package/src/internal/motion/livePill.ts +71 -0
  150. package/src/internal/motion/menuKeys.ts +58 -0
  151. package/src/internal/motion/morphButton.ts +71 -0
  152. package/src/internal/motion/numberInput.ts +57 -0
  153. package/src/internal/motion/pickerWheel.ts +166 -0
  154. package/src/internal/motion/retime.ts +45 -0
  155. package/src/internal/motion/ruler.ts +57 -0
  156. package/src/internal/motion/scrollArea.ts +133 -0
  157. package/src/internal/motion/scrollFrame.ts +152 -0
  158. package/src/internal/motion/scrubLook.ts +15 -0
  159. package/src/internal/motion/scrubber.ts +154 -0
  160. package/src/internal/motion/segmented.ts +63 -0
  161. package/src/internal/motion/sheetDetents.ts +271 -0
  162. package/src/internal/motion/slider.ts +108 -0
  163. package/src/internal/motion/softPress.ts +334 -0
  164. package/src/internal/motion/splitFlap.ts +205 -0
  165. package/src/internal/motion/swipeDeck.ts +236 -0
  166. package/src/internal/motion/switchThumb.ts +83 -0
  167. package/src/internal/motion/table.ts +77 -0
  168. package/src/internal/motion/tabs.ts +105 -0
  169. package/src/internal/motion/textarea.ts +22 -0
  170. package/src/internal/motion/themeIcon.ts +91 -0
  171. package/src/internal/motion/themeReveal.ts +71 -0
  172. package/src/internal/motion/toast.ts +291 -0
  173. package/src/internal/motion/tooltip.ts +58 -0
  174. package/src/internal/scrollFrame.ts +4 -145
  175. package/src/internal/softPress.ts +27 -289
  176. package/src/internal/themeReveal.ts +3 -61
  177. package/src/internal/useFloating.ts +9 -49
  178. package/src/internal/useScrub.ts +15 -120
  179. package/src/internal/vue/trigger.ts +18 -0
  180. package/src/internal/vue/useFloating.ts +38 -0
  181. package/src/internal/vue/usePresence.ts +21 -0
  182. package/src/internal/vue/useScrub.ts +40 -0
  183. package/src/internal/vueIcons.ts +134 -0
  184. package/src/tokens.css +5 -0
  185. package/src/internal/relativeTime.ts +0 -26
@@ -2,8 +2,7 @@
2
2
 
3
3
  import { useEffect, useId, useRef, useState, type ComponentPropsWithRef, type KeyboardEvent, type PointerEvent } from 'react'
4
4
  import { cx } from '../../internal/cx'
5
- import { bezier, nearestMark } from '../../internal/feel'
6
- import { morphCurve, motionMs, prefersReducedMotion } from '../../internal/motion'
5
+ import { createSlider } from '../../internal/motion/slider'
7
6
  import { useControllable } from '../../internal/useControllable'
8
7
  import styles from './Slider.module.css'
9
8
 
@@ -57,65 +56,25 @@ export function Slider({
57
56
  const [value, setValue] = useControllable(valueProp, defaultValue ?? min, onValueChange)
58
57
  // Where the thumb is drawn while it glides to a click or settles on a mark; the value is set already.
59
58
  const [shown, setShown] = useState<number | null>(null)
60
- // `grab` is how far from the thumb's centre it was picked up, so the thumb does not jump to the pointer.
61
- const press = useRef<{ x: number; lastX: number; moved: boolean; grab: number } | null>(null)
62
- const glide = useRef(0)
63
- const latest = useRef(value)
64
- latest.current = value
59
+ const latest = useRef({ value, min, max, step, marks })
60
+ latest.current = { value, min, max, step, marks }
61
+ const set = useRef(setValue)
62
+ set.current = setValue
63
+ // The glide, the grab and the landing on marks (motion/slider.ts).
64
+ const slider = useRef<ReturnType<typeof createSlider>>(null)
65
+ slider.current ??= createSlider(
66
+ () => latest.current,
67
+ (v) => {
68
+ latest.current = { ...latest.current, value: v }
69
+ set.current(v)
70
+ },
71
+ setShown,
72
+ )
65
73
  const at = shown ?? value
66
74
  const pct = max === min ? 0 : ((at - min) / (max - min)) * 100
67
75
  const text = formatValue(value)
68
- // A let-go within half of this (3% of the track) of a mark lands on it.
69
- const reach = (max - min) * 0.06
70
- const decimals = (String(step).split('.')[1] ?? '').length
71
- const toStep = (v: number) => Math.min(max, Math.max(min, Number((Math.round((v - min) / step) * step + min).toFixed(decimals))))
72
-
73
- useEffect(() => () => cancelAnimationFrame(glide.current), [])
74
-
75
- // The thumb travels from where it is drawn to `to` on the morph curve. A click and a landing both use it.
76
- function glideTo(from: number, to: number) {
77
- cancelAnimationFrame(glide.current)
78
- const ms = motionMs('morph-out')
79
- if (!ms || from === to || prefersReducedMotion()) return setShown(null)
80
- const ease = bezier(morphCurve())
81
- const t0 = performance.now()
82
- const tick = (now: number) => {
83
- const p = Math.min(1, (now - t0) / ms)
84
- setShown(p < 1 ? from + (to - from) * ease(p) : null)
85
- if (p < 1) glide.current = requestAnimationFrame(tick)
86
- }
87
- glide.current = requestAnimationFrame(tick)
88
- }
89
-
90
- // The value under the pointer, before any step, from the input's own geometry: the thumb's centre
91
- // runs from half a thumb in at each end.
92
- function track(input: HTMLInputElement) {
93
- const r = input.getBoundingClientRect()
94
- const thumb = parseFloat(getComputedStyle(input).getPropertyValue('--thumb')) || 0
95
- return { left: r.left + thumb / 2, width: Math.max(1, r.width - thumb), thumb }
96
- }
97
-
98
- function fromPointer(input: HTMLInputElement, x: number) {
99
- const t = track(input)
100
- return min + Math.min(1, Math.max(0, (x - t.left) / t.width)) * (max - min)
101
- }
102
-
103
- function change(input: HTMLInputElement, native: number) {
104
- const p = press.current
105
- const next = p && marks?.length ? toStep(fromPointer(input, p.lastX - p.grab)) : native
106
- // A press that has not moved is a click: the value jumps, the thumb glides there. Once it moves, the hand leads.
107
- if (p && !p.moved) glideTo(at, next)
108
- else if (shown !== null) {
109
- cancelAnimationFrame(glide.current)
110
- setShown(null)
111
- }
112
- latest.current = next
113
- setValue(next)
114
- }
115
76
 
116
- const endPress = () => {
117
- press.current = null
118
- }
77
+ useEffect(() => () => slider.current!.destroy(), [])
119
78
 
120
79
  return (
121
80
  <div className={cx(styles.root, className)} data-disabled={disabled || undefined}>
@@ -136,50 +95,32 @@ export function Slider({
136
95
  aria-valuenow={value}
137
96
  aria-valuetext={formatValue === String ? undefined : text}
138
97
  // Only "input": the browser's "change" on release carries the thumb's mid-glide place, not the value.
139
- onChange={(e) => e.nativeEvent.type === 'input' && change(e.currentTarget, Number(e.target.value))}
98
+ onChange={(e) => e.nativeEvent.type === 'input' && slider.current!.input(e.currentTarget, Number(e.target.value))}
140
99
  onPointerDown={(e: PointerEvent<HTMLInputElement>) => {
141
- const t = track(e.currentTarget)
142
- const centre = t.left + ((value - min) / (max - min || 1)) * t.width
143
- const grab = marks?.length && Math.abs(e.clientX - centre) <= t.thumb / 2 ? e.clientX - centre : 0
144
- press.current = { x: e.clientX, lastX: e.clientX, moved: false, grab }
100
+ slider.current!.down(e.currentTarget, e.clientX)
145
101
  onPointerDown?.(e)
146
102
  }}
147
103
  onPointerMove={(e: PointerEvent<HTMLInputElement>) => {
148
- const p = press.current
149
- if (p) {
150
- p.lastX = e.clientX
151
- if (Math.abs(e.clientX - p.x) > 3) p.moved = true
152
- }
104
+ slider.current!.move(e.clientX)
153
105
  onPointerMove?.(e)
154
106
  }}
155
107
  onPointerUp={(e: PointerEvent<HTMLInputElement>) => {
156
- endPress()
157
- // Let go near a mark: it lands on the mark.
158
- const now = latest.current
159
- const mark = marks?.length ? nearestMark(now, marks) : null
160
- if (mark !== null && mark !== now && Math.abs(mark - now) < reach / 2) {
161
- glideTo(at, mark)
162
- setValue(mark)
163
- }
108
+ slider.current!.up()
164
109
  onPointerUp?.(e)
165
110
  }}
166
111
  onPointerCancel={(e: PointerEvent<HTMLInputElement>) => {
167
- endPress()
112
+ slider.current!.end()
168
113
  onPointerCancel?.(e)
169
114
  }}
170
- onLostPointerCapture={endPress}
115
+ onLostPointerCapture={slider.current.end}
171
116
  onBlur={(e) => {
172
- endPress()
117
+ slider.current!.end()
173
118
  onBlur?.(e)
174
119
  }}
175
120
  onKeyDown={(e: KeyboardEvent<HTMLInputElement>) => {
176
- endPress()
121
+ slider.current!.end()
177
122
  onKeyDown?.(e)
178
- if (e.defaultPrevented || !marks?.length || (e.key !== 'PageUp' && e.key !== 'PageDown')) return
179
- const sorted = [...marks].sort((a, b) => a - b)
180
- const next = e.key === 'PageUp' ? (sorted.find((m) => m > value) ?? max) : ([...sorted].reverse().find((m) => m < value) ?? min)
181
- e.preventDefault()
182
- setValue(next)
123
+ if (!e.defaultPrevented && slider.current!.key(e.key)) e.preventDefault()
183
124
  }}
184
125
  {...rest}
185
126
  />
@@ -0,0 +1,113 @@
1
+ <script setup lang="ts">
2
+ import { computed, onBeforeUnmount, ref, useAttrs, useId } from 'vue'
3
+ import { createSlider } from '../../internal/motion/slider'
4
+ import styles from './Slider.module.css'
5
+
6
+ // The Vue Slider: the same look (Slider.module.css), glide and marks as the React one.
7
+ // Other attributes, such as name or a listener, go to the input. A class goes to the root, as in React.
8
+ defineOptions({ inheritAttrs: false })
9
+
10
+ const props = withDefaults(
11
+ defineProps<{
12
+ /** Visible name of the slider, also read by screen readers. */
13
+ label: string
14
+ /** Starting value when there is no v-model. Undefined starts at min. */
15
+ defaultValue?: number
16
+ /** Lowest value on the track. */
17
+ min?: number
18
+ /** Highest value on the track. */
19
+ max?: number
20
+ /** Size of each move, by drag or arrow key. */
21
+ step?: number
22
+ /** Shows the value next to the label and in a bubble while dragging. */
23
+ showValue?: boolean
24
+ /** Turns the number into the text shown and read by screen readers. */
25
+ formatValue?: (value: number) => string
26
+ /** Values the thumb is drawn to as it passes, shown as dots on the track. Let go near one and it lands on it; Page Up and Page Down jump between them. */
27
+ marks?: number[]
28
+ disabled?: boolean
29
+ id?: string
30
+ }>(),
31
+ { min: 0, max: 100, step: 1, showValue: true, formatValue: String },
32
+ )
33
+
34
+ /** The value. Use v-model, or leave it out and the slider keeps its own value. */
35
+ const model = defineModel<number>()
36
+ const local = ref(props.defaultValue ?? props.min)
37
+ const value = computed({
38
+ get: () => model.value ?? local.value,
39
+ set: (next: number) => {
40
+ local.value = next
41
+ model.value = next
42
+ },
43
+ })
44
+ const attrs = useAttrs()
45
+ const inputAttrs = computed(() => {
46
+ const { class: _, ...rest } = attrs
47
+ return rest
48
+ })
49
+
50
+ const auto = useId()
51
+ const inputId = computed(() => props.id ?? auto)
52
+ // Where the thumb is drawn while it glides to a click or settles on a mark; the value is set already.
53
+ const shown = ref<number | null>(null)
54
+ const at = computed(() => shown.value ?? value.value)
55
+ const pct = computed(() => (props.max === props.min ? 0 : ((at.value - props.min) / (props.max - props.min)) * 100))
56
+ const text = computed(() => props.formatValue(value.value))
57
+
58
+ // The glide, the grab and the landing on marks (motion/slider.ts).
59
+ const slider = createSlider(
60
+ () => ({ value: value.value, min: props.min, max: props.max, step: props.step, marks: props.marks }),
61
+ (v) => (value.value = v),
62
+ (v) => (shown.value = v),
63
+ )
64
+ onBeforeUnmount(slider.destroy)
65
+
66
+ const onInput = (e: Event) => {
67
+ const input = e.target as HTMLInputElement
68
+ slider.input(input, Number(input.value))
69
+ // A v-model that holds its value keeps the thumb where it was.
70
+ input.value = String(at.value)
71
+ }
72
+ const onKeydown = (e: KeyboardEvent) => {
73
+ slider.end()
74
+ if (!e.defaultPrevented && slider.key(e.key)) e.preventDefault()
75
+ }
76
+ </script>
77
+
78
+ <template>
79
+ <div :class="[styles.root, attrs.class]" :data-disabled="disabled || undefined">
80
+ <div :class="styles.head">
81
+ <label :for="inputId" :class="styles.label">{{ label }}</label>
82
+ <output v-if="showValue" :for="inputId" :class="styles.value" aria-hidden="true">{{ text }}</output>
83
+ </div>
84
+ <div :class="styles.trackWrap" :data-gliding="shown !== null || undefined" :style="{ '--pct': `${pct}%`, '--p': pct / 100 }">
85
+ <input
86
+ v-bind="inputAttrs"
87
+ :id="inputId"
88
+ type="range"
89
+ :class="styles.input"
90
+ :min="min"
91
+ :max="max"
92
+ :step="shown === null ? step : 'any'"
93
+ :value="at"
94
+ :disabled="disabled"
95
+ :aria-valuenow="value"
96
+ :aria-valuetext="formatValue === String ? undefined : text"
97
+ @input="onInput"
98
+ @pointerdown="slider.down($event.currentTarget as HTMLInputElement, $event.clientX)"
99
+ @pointermove="slider.move($event.clientX)"
100
+ @pointerup="slider.up()"
101
+ @pointercancel="slider.end()"
102
+ @lostpointercapture="slider.end()"
103
+ @blur="slider.end()"
104
+ @keydown="onKeydown"
105
+ />
106
+ <span v-if="showValue" :class="styles.bubble" aria-hidden="true">{{ text }}</span>
107
+ <!-- After the bubble, which CSS shows from the input just before it. -->
108
+ <span v-if="marks?.length" :class="styles.marks" aria-hidden="true">
109
+ <span v-for="m in marks" :key="m" :class="styles.mark" :data-on="m === value || undefined" :style="{ '--m': (m - min) / (max - min || 1) }" />
110
+ </span>
111
+ </div>
112
+ </div>
113
+ </template>
@@ -0,0 +1,30 @@
1
+ <script setup lang="ts">
2
+ import { onMounted, ref } from 'vue'
3
+ import styles from './Spinner.module.css'
4
+
5
+ // The Vue Spinner: the same look (Spinner.module.css) as the React one.
6
+
7
+ withDefaults(
8
+ defineProps<{
9
+ /** Diameter of the spinner. */
10
+ size?: 'sm' | 'md' | 'lg'
11
+ /** Spoken to screen readers. Pass null when a parent already announces the busy state. */
12
+ label?: string | null
13
+ }>(),
14
+ { size: 'md', label: 'Loading' },
15
+ )
16
+
17
+ // The label lands after the empty live region is mounted, so screen readers hear it.
18
+ const mounted = ref(false)
19
+ onMounted(() => (mounted.value = true))
20
+ </script>
21
+
22
+ <template>
23
+ <span :class="[styles.root, styles[size]]" :role="label ? 'status' : undefined">
24
+ <svg :class="styles.svg" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
25
+ <circle :class="styles.track" cx="12" cy="12" r="9.5" />
26
+ <circle :class="styles.arc" cx="12" cy="12" r="9.5" pathLength="100" />
27
+ </svg>
28
+ <span v-if="label" :class="styles.srOnly">{{ mounted ? label : null }}</span>
29
+ </span>
30
+ </template>
@@ -0,0 +1,34 @@
1
+ <script setup lang="ts">
2
+ import { computed } from 'vue'
3
+ import { space, type Space } from '../../internal/space'
4
+ import styles from './Split.module.css'
5
+
6
+ // The Vue Split: the same look (Split.module.css) as the React one. The sidebar slot is the narrow column;
7
+ // leave it out for one column. Other attributes go to the outer box.
8
+ const props = withDefaults(
9
+ defineProps<{
10
+ /** Which side the sidebar sits on. It also comes first ("start") or last ("end") when the columns stack. */
11
+ side?: 'start' | 'end'
12
+ /** Width of the sidebar, from the --gooee-split-side-* tokens. */
13
+ sidebarWidth?: 'sm' | 'md' | 'lg'
14
+ /** Space between the columns, and between them once stacked, as a step of the space scale. */
15
+ gap?: Space
16
+ /** What shows once the columns stack: both, only main, or only the sidebar. */
17
+ stacked?: 'both' | 'main' | 'sidebar'
18
+ }>(),
19
+ { side: 'start', sidebarWidth: 'md', gap: 7, stacked: 'both' },
20
+ )
21
+ const slots = defineSlots<{ default?: () => unknown; sidebar?: () => unknown }>()
22
+ const hasSide = computed(() => !!slots.sidebar)
23
+ </script>
24
+
25
+ <!-- The outer box is the query container: an element cannot query its own width. -->
26
+ <template>
27
+ <div :class="styles.root" :style="{ '--split-gap': space(gap), '--split-side': `var(--gooee-split-side-${sidebarWidth})` }">
28
+ <div :class="[styles.inner, hasSide ? styles[side] : styles.solo]" :data-stacked="stacked">
29
+ <div v-if="hasSide && side === 'start'" :class="styles.side"><slot name="sidebar" /></div>
30
+ <div :class="styles.main"><slot /></div>
31
+ <div v-if="hasSide && side === 'end'" :class="styles.side"><slot name="sidebar" /></div>
32
+ </div>
33
+ </div>
34
+ </template>
@@ -2,9 +2,11 @@
2
2
 
3
3
  import { useEffect, useRef, useState, type ComponentPropsWithRef } from 'react'
4
4
  import { cx } from '../../internal/cx'
5
- import { easing, readMotionMs } from '../../internal/motion'
5
+ import { createSplitFlap, flapCellsHtml, SPLIT_FLAP_CHARS, type FlapLook } from '../../internal/motion/splitFlap'
6
6
  import styles from './SplitFlap.module.css'
7
7
 
8
+ export { SPLIT_FLAP_CHARS }
9
+
8
10
  export type SplitFlapProps = Omit<ComponentPropsWithRef<'span'>, 'children'> & {
9
11
  /** The text the board shows. A change flips each cell forward through the drum to its new letter. */
10
12
  value: string
@@ -20,199 +22,33 @@ export type SplitFlapProps = Omit<ComponentPropsWithRef<'span'>, 'children'> & {
20
22
  onSettle?: (value: string) => void
21
23
  }
22
24
 
23
- /** The drum of a real board: a blank, letters, digits and a few marks. */
24
- export const SPLIT_FLAP_CHARS = ' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789:.,-+%/'
25
-
26
- // A fold of about 90ms, fast steps of 40ms, and the last three slow down. A cell passes 8 letters at
27
- // most, and the cells start one after another within 350ms, so a whole change ends inside a second.
28
- const FOLD = 90
29
- const FAST = 40
30
- const TAIL = [70, 100, 140]
31
- const MAX_STEPS = 8
32
- const STAGGER = 35
33
- const CASCADE_CAP = 350
34
- // The fast motion token at its base, so Retime scales the board with everything else.
35
- const FAST_TOKEN = 140
36
-
37
- type Cell = { root: HTMLSpanElement; top: HTMLSpanElement; bottom: HTMLSpanElement; shown: string }
38
-
39
- /** The letters a cell passes on its way from `from` to `to`, at most MAX_STEPS, ending on `to`. */
40
- function route(from: string, to: string, drum: string) {
41
- const a = drum.indexOf(from)
42
- const b = drum.indexOf(to)
43
- if (a < 0 || b < 0) return from === to ? [] : [to]
44
- const n = Math.min((b - a + drum.length) % drum.length, MAX_STEPS)
45
- return Array.from({ length: n }, (_, i) => drum[(b - n + 1 + i + drum.length) % drum.length])
46
- }
47
-
48
- /** The wait before each step: fast in the middle, slow for the last three. */
49
- const gaps = (n: number) => Array.from({ length: n }, (_, i) => (n - 1 - i < TAIL.length ? TAIL[TAIL.length - n + i] : FAST))
50
-
51
- const NBSP = ' '
52
- const shownChar = (ch: string) => (ch === ' ' ? NBSP : ch)
53
- const escape = (ch: string) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;' })[ch] ?? ch
54
-
55
- const halfHtml = (cls: string, ch: string) => `<span class="${cls}"><span class="${styles.glyph}">${escape(shownChar(ch))}</span></span>`
56
- const cellHtml = (ch: string) => `<span class="${styles.cell}">${halfHtml(styles.top, ch)}${halfHtml(styles.bottom, ch)}</span>`
57
-
58
- const fromHtml = (html: string) => {
59
- const t = document.createElement('template')
60
- t.innerHTML = html
61
- return t.content.firstElementChild as HTMLSpanElement
62
- }
63
-
64
- const makeCell = (ch: string): Cell => {
65
- const root = fromHtml(cellHtml(ch))
66
- return { root, top: root.children[0] as HTMLSpanElement, bottom: root.children[1] as HTMLSpanElement, shown: ch }
67
- }
68
-
69
- const setHalf = (h: Element, ch: string) => {
70
- ;(h.firstElementChild as HTMLElement).textContent = shownChar(ch)
71
- }
25
+ const LOOK: FlapLook = { cell: styles.cell, top: styles.top, bottom: styles.bottom, glyph: styles.glyph, flap: styles.flap, front: styles.front, back: styles.back }
72
26
 
73
27
  export function SplitFlap({ value, length = 0, size = 'md', chars = SPLIT_FLAP_CHARS, announce = true, onSettle, className, ...rest }: SplitFlapProps) {
74
28
  const target = value.padEnd(length, ' ')
75
29
  // The first cells come with the markup, so a server page shows the board before any script runs.
76
- const [first] = useState(() => ({ __html: [...target].map(cellHtml).join('') }))
30
+ const [first] = useState(() => ({ __html: flapCellsHtml(LOOK, target) }))
77
31
  const [said, setSaid] = useState(value)
78
32
  const board = useRef<HTMLSpanElement>(null)
79
- const cells = useRef<Cell[] | null>(null)
80
- const timers = useRef<number[]>([])
81
- const anims = useRef(new Set<Animation>())
82
- const run = useRef(0)
83
- const shrinkEnd = useRef<(() => void) | null>(null)
33
+ const flap = useRef<ReturnType<typeof createSplitFlap> | null>(null)
84
34
  const settle = useRef(onSettle)
85
35
  settle.current = onSettle
86
36
 
87
- const stopAll = () => {
88
- timers.current.forEach(clearTimeout)
89
- timers.current = []
90
- anims.current.forEach((a) => a.finish())
91
- anims.current.clear()
92
- shrinkEnd.current?.()
93
- // Caught mid-run, each cell carries on from the letter it was showing.
94
- for (const c of cells.current ?? []) setHalf(c.bottom, c.shown)
95
- }
96
-
37
+ // The board runs in motion/splitFlap.ts. The first cells came with the markup.
97
38
  useEffect(() => {
98
39
  const b = board.current
99
40
  if (!b) return
100
- if (!cells.current) {
101
- cells.current = [...b.children].map((root, i) => ({ root: root as HTMLSpanElement, top: root.children[0] as HTMLSpanElement, bottom: root.children[1] as HTMLSpanElement, shown: [...target][i] ?? ' ' }))
41
+ if (!flap.current) {
42
+ flap.current = createSplitFlap(b, LOOK, target)
102
43
  return
103
44
  }
104
- const id = ++run.current
105
- const live = () => id === run.current
106
- const running = timers.current.length > 0 || anims.current.size > 0
107
- stopAll()
108
- const done = () => {
109
- if (!live()) return
110
- timers.current = []
45
+ flap.current.show(target, chars, () => {
111
46
  setSaid(value)
112
47
  settle.current?.(value)
113
- }
114
- const list = cells.current
115
- if (list.map((c) => c.shown).join('') === target) {
116
- if (running) done()
117
- return
118
- }
119
-
120
- const scale = readMotionMs('fast') / FAST_TOKEN
121
- // Reduced motion: the new text at once, with no flips and no morph.
122
- if (!scale) {
123
- cells.current = [...target].map(makeCell)
124
- b.replaceChildren(...cells.current.map((c) => c.root))
125
- done()
126
- return
127
- }
128
-
129
- const n0 = list.length
130
- const n1 = target.length
131
- const radius = getComputedStyle(b).borderRadius || '0px'
132
- const grow = { duration: readMotionMs('morph'), easing: easing('morph') }
133
- const shrink = { duration: readMotionMs('morph-out'), easing: easing('morph') }
134
- let left = 0
135
- const landed = () => {
136
- if (--left === 0) done()
137
- }
138
-
139
- // Longer: the new cells are laid out at once, and the board's edge grows over them.
140
- if (n1 > n0) {
141
- const before = b.offsetWidth
142
- for (let i = n0; i < n1; i++) {
143
- const c = makeCell(' ')
144
- list.push(c)
145
- b.append(c.root)
146
- }
147
- const wider = b.offsetWidth - before
148
- const a = b.animate({ clipPath: [`inset(0 ${wider}px 0 0 round ${radius})`, `inset(0 0 0 0 round ${radius})`] }, grow)
149
- anims.current.add(a)
150
- a.finished.then(() => anims.current.delete(a), () => {})
151
- }
152
-
153
- // Shorter: the board's edge folds over the extra cells while the rest flip, then they go.
154
- if (n1 < n0) {
155
- const keep = list.slice(0, n1)
156
- const box = b.getBoundingClientRect()
157
- const edge = keep.length ? keep[keep.length - 1].root.getBoundingClientRect().right : box.left
158
- const a = b.animate({ clipPath: [`inset(0 0 0 0 round ${radius})`, `inset(0 ${box.right - edge}px 0 0 round ${radius})`] }, { ...shrink, fill: 'forwards' })
159
- left++
160
- const end = () => {
161
- shrinkEnd.current = null
162
- list.slice(n1).forEach((c) => c.root.remove())
163
- cells.current = keep
164
- a.cancel()
165
- if (live()) landed()
166
- }
167
- shrinkEnd.current = end
168
- a.finished.then(() => shrinkEnd.current === end && end(), () => {})
169
- }
170
-
171
- const goal = [...target]
172
- const changed = goal.map((ch, i) => (list[i].shown !== ch ? i : -1)).filter((i) => i >= 0)
173
- const stagger = Math.min(STAGGER, CASCADE_CAP / Math.max(1, changed.length))
174
- left += changed.length
175
- if (!left) return done()
176
-
177
- const flip = (cell: Cell, next: string, last: boolean, fold: number) => {
178
- const prev = cell.shown
179
- cell.shown = next
180
- setHalf(cell.top, next)
181
- // The falling flap: the old letter's top half in front, the new letter's bottom half behind.
182
- const flap = fromHtml(`<span class="${styles.flap}">${halfHtml(styles.front, prev)}${halfHtml(styles.back, next)}</span>`)
183
- cell.root.append(flap)
184
- const a = flap.animate([{ transform: 'rotateX(0deg)' }, { transform: 'rotateX(-180deg)' }], { duration: fold, easing: easing('morph') })
185
- anims.current.add(a)
186
- const end = () => {
187
- anims.current.delete(a)
188
- setHalf(cell.bottom, next)
189
- flap.remove()
190
- if (last && live()) landed()
191
- }
192
- a.finished.then(end, end)
193
- }
194
-
195
- changed.forEach((i, order) => {
196
- const cell = list[i]
197
- const path = route(cell.shown, goal[i], chars)
198
- const wait = gaps(path.length)
199
- let t = order * stagger
200
- path.forEach((next, k) => {
201
- timers.current.push(window.setTimeout(() => flip(cell, next, k === path.length - 1, Math.max(FOLD, wait[k]) * scale), t * scale))
202
- t += wait[k]
203
- })
204
48
  })
205
49
  }, [target])
206
50
 
207
- useEffect(
208
- () => () => {
209
- // Gone: the run is over, so a cancelled flip ends without calling onSettle.
210
- run.current++
211
- timers.current.forEach(clearTimeout)
212
- anims.current.forEach((a) => a.cancel())
213
- },
214
- [],
215
- )
51
+ useEffect(() => () => flap.current?.destroy(), [])
216
52
 
217
53
  return (
218
54
  <span className={cx(styles.root, className)} data-size={size} {...rest}>
@@ -0,0 +1,52 @@
1
+ <script setup lang="ts">
2
+ import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
3
+ import { createSplitFlap, flapCellsHtml, SPLIT_FLAP_CHARS, type FlapLook } from '../../internal/motion/splitFlap'
4
+ import styles from './SplitFlap.module.css'
5
+
6
+ // The Vue SplitFlap: the same look (SplitFlap.module.css) and flips (motion/splitFlap.ts) as the React one.
7
+ // Other attributes go to the root.
8
+ const props = withDefaults(
9
+ defineProps<{
10
+ /** The text the board shows. A change flips each cell forward through the drum to its new letter. */
11
+ value: string
12
+ /** At least this many cells: shorter text is padded with blank ones, so a column keeps its width. */
13
+ length?: number
14
+ /** Text size of the cells. */
15
+ size?: 'sm' | 'md' | 'lg'
16
+ /** The drum's letters, in the order a cell passes them. A letter that is not on it flips straight in. */
17
+ chars?: string
18
+ /** Says the new text to screen readers once, when the board has landed. Turn off when one message covers several boards. */
19
+ announce?: boolean
20
+ }>(),
21
+ { length: 0, size: 'md', chars: SPLIT_FLAP_CHARS, announce: true },
22
+ )
23
+ /** settle: fires once with the text when every cell has landed. */
24
+ const emit = defineEmits<{ settle: [value: string] }>()
25
+
26
+ const LOOK: FlapLook = { cell: styles.cell, top: styles.top, bottom: styles.bottom, glyph: styles.glyph, flap: styles.flap, front: styles.front, back: styles.back }
27
+ const target = computed(() => props.value.padEnd(props.length, ' '))
28
+ // The first cells come with the markup, so a server page shows the board before any script runs.
29
+ const first = flapCellsHtml(LOOK, target.value)
30
+ const said = ref(props.value)
31
+ const board = ref<HTMLSpanElement | null>(null)
32
+ let flap: ReturnType<typeof createSplitFlap> | null = null
33
+
34
+ onMounted(() => {
35
+ if (board.value) flap = createSplitFlap(board.value, LOOK, target.value)
36
+ })
37
+ watch(target, (t) => {
38
+ const value = props.value
39
+ flap?.show(t, props.chars, () => {
40
+ said.value = value
41
+ emit('settle', value)
42
+ })
43
+ })
44
+ onBeforeUnmount(() => flap?.destroy())
45
+ </script>
46
+
47
+ <template>
48
+ <span :class="styles.root" :data-size="size">
49
+ <span :class="styles.sr" :aria-live="announce ? 'polite' : undefined" aria-atomic="true">{{ said }}</span>
50
+ <span ref="board" :class="styles.board" aria-hidden="true" v-html="first" />
51
+ </span>
52
+ </template>
@@ -0,0 +1,22 @@
1
+ <script setup lang="ts">
2
+ import { space, type Space } from '../../internal/space'
3
+ import styles from './Stack.module.css'
4
+
5
+ // The Vue Stack: the same look (Stack.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
+ /** Lines items up across the stack. "stretch" makes each item full width. */
11
+ align?: 'stretch' | 'start' | 'center' | 'end'
12
+ /** Element to render, so the stack can be a list, a section or a form. */
13
+ as?: 'div' | 'section' | 'article' | 'aside' | 'nav' | 'header' | 'footer' | 'main' | 'form' | 'fieldset' | 'ul' | 'ol'
14
+ }>(),
15
+ { gap: 5, align: 'stretch', as: 'div' },
16
+ )
17
+ defineSlots<{ default?: () => unknown }>()
18
+ </script>
19
+
20
+ <template>
21
+ <component :is="as" :class="[styles.root, styles[align]]" :style="{ '--stack-gap': space(gap) }"><slot /></component>
22
+ </template>