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