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
@@ -1,108 +1,9 @@
1
1
  import { useLayoutEffect, useRef, type RefObject } from 'react'
2
- import { bezier } from './feel'
3
- import { body, BEND, boxPath, flowScene, loopsPath, pincher, trace, type Box } from './liquidPath'
4
- import { morphCurve, motionMs, prefersReducedMotion, type MotionToken } from './motion'
2
+ import { createFlow, type Place } from './motion/liquidMatter'
5
3
 
6
- // The page side of liquid matter (the maths is in liquidPath.ts): an SVG layer that exists only while a
7
- // part moves, a frame loop, and the flowing highlight Tabs and SegmentedControl share.
4
+ export { castShadow, frames, layer, morphEase, motionFor, shadowOf, type Place } from './motion/liquidMatter'
8
5
 
9
- const NS = 'http://www.w3.org/2000/svg'
10
-
11
- export const morphEase = () => bezier(morphCurve())
12
-
13
- /** A duration token in ms, or 0 when motion is reduced. */
14
- export const motionFor = (token: MotionToken) => (prefersReducedMotion() ? 0 : motionMs(token))
15
-
16
- type Shadow = { x: number; y: number; blur: number; colour: string }
17
-
18
- /** An element's outer box shadows. A shadow that is only a spread (a 1px ring) comes back as `ring`, to draw as a stroke. */
19
- export function shadowOf(el: Element) {
20
- const shadows: Shadow[] = []
21
- let ring: { colour: string; width: number } | null = null
22
- for (const part of getComputedStyle(el).boxShadow.split(/,(?![^(]*\))/)) {
23
- if (part.trim() === 'none' || part.includes('inset')) continue
24
- const colour = part.match(/rgba?\([^)]*\)|#[\da-f]+/i)?.[0] ?? 'currentColor'
25
- const [x = 0, y = 0, blur = 0, spread = 0] = (part.replace(colour, '').match(/-?[\d.]+px/g) ?? []).map(parseFloat)
26
- if (spread > 0 && !x && !y && !blur) ring = { colour, width: spread }
27
- else shadows.push({ x, y, blur, colour })
28
- }
29
- return { shadows, ring }
30
- }
31
-
32
- let filterId = 0
33
-
34
- /**
35
- * Casts `shadows` from the layer's paths the way box-shadow does: each one blurred from the shape on its
36
- * own, then merged. A chain of CSS drop-shadows would shadow the shadows too, so the drawing would come out
37
- * darker than the part it stands in for and jump at the hand-over.
38
- */
39
- export function castShadow(svg: SVGSVGElement, shadows: Shadow[]) {
40
- if (!shadows.length) return
41
- const el = (tag: string, attrs: Record<string, string | number>, parent: Element) => {
42
- const node = parent.appendChild(document.createElementNS(NS, tag))
43
- for (const [k, v] of Object.entries(attrs)) node.setAttribute(k, String(v))
44
- return node
45
- }
46
- const { width, height } = svg.getBoundingClientRect()
47
- const m = Math.max(...shadows.map((s) => Math.max(Math.abs(s.x), Math.abs(s.y)) + s.blur * 1.5)) + 2
48
- const id = `gooee-shadow-${++filterId}`
49
- const filter = el('filter', { id, filterUnits: 'userSpaceOnUse', x: -m, y: -m, width: width + m * 2, height: height + m * 2, 'color-interpolation-filters': 'sRGB' }, el('defs', {}, svg))
50
- shadows.forEach((s, i) => {
51
- el('feGaussianBlur', { in: 'SourceAlpha', stdDeviation: s.blur / 2 }, filter)
52
- el('feOffset', { dx: s.x, dy: s.y, result: `b${i}` }, filter)
53
- el('feFlood', { 'flood-color': s.colour }, filter)
54
- el('feComposite', { in2: `b${i}`, operator: 'in', result: `s${i}` }, filter)
55
- })
56
- // box-shadow paints its first shadow on top, so they merge last to first, under the shape.
57
- const merge = el('feMerge', {}, filter)
58
- for (let i = shadows.length - 1; i >= 0; i--) el('feMergeNode', { in: `s${i}` }, merge)
59
- el('feMergeNode', { in: 'SourceGraphic' }, merge)
60
- const g = el('g', { filter: `url(#${id})` }, svg)
61
- for (const path of Array.from(svg.querySelectorAll(':scope > path'))) g.appendChild(path)
62
- }
63
-
64
- /** An SVG in `host`, before `before`, with `count` paths. It is marked data-gooee-liquid. */
65
- export function layer(host: Element, className: string, before: Node | null, count = 1) {
66
- const svg = document.createElementNS(NS, 'svg')
67
- svg.setAttribute('class', className)
68
- svg.setAttribute('aria-hidden', 'true')
69
- svg.setAttribute('data-gooee-liquid', '')
70
- const paths = Array.from({ length: count }, () => svg.appendChild(document.createElementNS(NS, 'path')))
71
- host.insertBefore(svg, before)
72
- return { svg, paths }
73
- }
74
-
75
- /**
76
- * Draws frame 0 now (so the part's new CSS state never shows first), then one per frame over `ms`
77
- * with progress 0 to 1, then calls `done`. Returns a stop.
78
- */
79
- export function frames(ms: number, draw: (u: number, now: number) => void, done: () => void) {
80
- const t0 = performance.now()
81
- draw(0, t0)
82
- let id = 0
83
- const tick = (now: number) => {
84
- const u = Math.min(1, Math.max(0, (now - t0) / ms))
85
- draw(u, now)
86
- if (u >= 1) done()
87
- else id = requestAnimationFrame(tick)
88
- }
89
- id = requestAnimationFrame(tick)
90
- return () => cancelAnimationFrame(id)
91
- }
92
-
93
- /** A highlight's place in its row: its start edge and its width. */
94
- export type Place = { x: number; w: number }
95
-
96
- type Flow = { front: Box; rest: Box; stop: () => void; svg: SVGSVGElement; pin: ReturnType<typeof pincher> }
97
-
98
- /**
99
- * Flow: when the choice changes, the highlight `mark` runs to the new place on a neck that thins and
100
- * breaks, and what is left drains after it and joins by 60% of the move (liquidPath flowScene). While
101
- * it moves the mark is hidden and an SVG in `host` draws it; at rest the mark is back, exact. A flow
102
- * caught half way starts from the shape on screen. `line` draws a thin underline, which only splits
103
- * and joins. `ink` gets the drawn outline each frame (null at the end), for text that changes colour
104
- * under the liquid. `cls` is the layer's class.
105
- */
6
+ /** React's hold on createFlow (motion/liquidMatter.ts): runs the flow when the choice or its place changes. */
106
7
  export function useFlow(
107
8
  host: RefObject<HTMLElement | null>,
108
9
  mark: RefObject<HTMLElement | null>,
@@ -113,87 +14,14 @@ export function useFlow(
113
14
  line = false,
114
15
  ink?: (outline: string | null) => void,
115
16
  ) {
116
- const last = useRef<{ place: Place; choice: unknown } | null>(null)
117
- const run = useRef<Flow | null>(null)
118
- const end = () => {
119
- const f = run.current
120
- if (!f) return
121
- f.stop()
122
- f.svg.remove()
123
- run.current = null
124
- delete mark.current?.dataset.flowing
125
- delete host.current?.dataset.flowing
126
- ink?.(null)
127
- }
17
+ const inkRef = useRef(ink)
18
+ inkRef.current = ink
19
+ const flow = useRef<ReturnType<typeof createFlow>>(null)
20
+ flow.current ??= createFlow(() => host.current, () => mark.current, { cls, line, ink: (d) => inkRef.current?.(d) })
128
21
  useLayoutEffect(() => {
129
- const root = host.current
130
- const m = mark.current
131
- const prev = last.current
132
- // A new choice arrives a render before its place is measured: wait for the place.
133
- if (!place || (prev && prev.place.x === place.x && prev.place.w === place.w)) return
134
- last.current = { place, choice }
135
- if (!root || !m || !prev || !ready || prev.choice === choice) {
136
- end()
137
- return
138
- }
139
- const ms = motionFor('morph-out')
140
- if (!ms) {
141
- end()
142
- return
143
- }
144
- const hh = m.offsetHeight / 2
145
- const cy = m.offsetTop + hh
146
- const r = Math.min(hh, parseFloat(getComputedStyle(m).borderTopLeftRadius) || 0)
147
- const boxOf = (p: Place): Box => ({ cx: p.x + p.w / 2, cy, hw: p.w / 2, hh, r })
148
- const to = boxOf(place)
149
- const from = run.current ?? { front: boxOf(prev.place), rest: boxOf(prev.place) }
150
- const e = morphEase()
151
- let f = run.current
152
- if (f) f.stop()
153
- else {
154
- const { svg, paths } = layer(root, cls, m.nextSibling)
155
- const look = getComputedStyle(m)
156
- const { shadows, ring } = shadowOf(m)
157
- paths[0].style.fill = look.backgroundColor
158
- if (ring && !line) {
159
- paths[0].style.stroke = ring.colour
160
- paths[0].style.strokeWidth = `${ring.width * 2}px`
161
- paths[0].style.paintOrder = 'stroke'
162
- }
163
- castShadow(svg, shadows)
164
- f = { front: from.front, rest: from.rest, stop: () => {}, svg, pin: pincher(e, motionFor('fast')) }
165
- run.current = f
166
- m.dataset.flowing = ''
167
- root.dataset.flowing = ''
168
- }
169
- const flow = f
170
- const path = flow.svg.querySelector('path') as SVGPathElement
171
- const lift = Math.max(BEND + 0.5, hh / 2)
172
- const settle = Math.max(BEND + 0.5, hh / 3)
173
- const start = { front: from.front, rest: from.rest }
174
- const draw = (u: number, now: number) => {
175
- const s = line ? flowScene(e, u, start.front, start.rest, to, 0, [BEND, hh], [hh, hh]) : flowScene(e, u, start.front, start.rest, to, hh / 6, [lift, lift], [settle, settle])
176
- flow.front = s.front
177
- flow.rest = s.rest
178
- let d: string
179
- if (line) {
180
- const a = s.front
181
- const b = s.rest
182
- // Two lines of one thickness on one row: one where they overlap, two apart.
183
- const lo = Math.min(a.cx - a.hw, b.cx - b.hw)
184
- const hi = Math.max(a.cx + a.hw, b.cx + b.hw)
185
- d = Math.abs(a.cx - b.cx) <= a.hw + b.hw ? boxPath({ cx: (lo + hi) / 2, cy, hw: (hi - lo) / 2, hh, r: hh }) : boxPath(a) + boxPath(b)
186
- } else {
187
- const p = flow.pin(body(s.front), body(s.rest), now)
188
- d = loopsPath(trace(p.sdf, [[s.front.cx, cy, 0, -1], [s.rest.cx, cy, 0, -1]]))
189
- }
190
- path.setAttribute('d', d)
191
- ink?.(d)
192
- }
193
- flow.stop = frames(ms, draw, end)
22
+ flow.current!.update(place, choice, ready)
194
23
  // Keyed on the choice and the place; the rest is read when it runs.
195
24
  // eslint-disable-next-line react-hooks/exhaustive-deps
196
25
  }, [choice, place?.x, place?.w, ready])
197
- // eslint-disable-next-line react-hooks/exhaustive-deps
198
- useLayoutEffect(() => () => end(), [])
26
+ useLayoutEffect(() => () => flow.current!.destroy(), [])
199
27
  }