gooee 0.0.0-stage → 0.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +99 -2
- package/package.json +36 -4
- package/scripts/add.js +533 -0
- package/scripts/pro-components.json +82 -0
- package/src/base.css +39 -0
- package/src/components/Accordion/Accordion.module.css +90 -0
- package/src/components/Accordion/Accordion.tsx +125 -0
- package/src/components/Accordion/index.ts +1 -0
- package/src/components/Alert/Alert.module.css +121 -0
- package/src/components/Alert/Alert.tsx +90 -0
- package/src/components/Alert/index.ts +1 -0
- package/src/components/AlertDialog/AlertDialog.module.css +2 -0
- package/src/components/AlertDialog/AlertDialog.tsx +108 -0
- package/src/components/AlertDialog/index.ts +1 -0
- package/src/components/AnimatedNumber/AnimatedNumber.module.css +48 -0
- package/src/components/AnimatedNumber/AnimatedNumber.tsx +52 -0
- package/src/components/AnimatedNumber/index.ts +1 -0
- package/src/components/AspectRatio/AspectRatio.module.css +15 -0
- package/src/components/AspectRatio/AspectRatio.tsx +12 -0
- package/src/components/AspectRatio/index.ts +1 -0
- package/src/components/Avatar/Avatar.module.css +62 -0
- package/src/components/Avatar/Avatar.tsx +55 -0
- package/src/components/Avatar/index.ts +3 -0
- package/src/components/AvatarGroup/AvatarGroup.module.css +53 -0
- package/src/components/AvatarGroup/AvatarGroup.tsx +43 -0
- package/src/components/AvatarGroup/index.ts +1 -0
- package/src/components/Badge/Badge.module.css +69 -0
- package/src/components/Badge/Badge.tsx +25 -0
- package/src/components/Badge/index.ts +1 -0
- package/src/components/Breadcrumb/Breadcrumb.module.css +104 -0
- package/src/components/Breadcrumb/Breadcrumb.tsx +76 -0
- package/src/components/Breadcrumb/index.ts +1 -0
- package/src/components/Button/Button.module.css +191 -0
- package/src/components/Button/Button.tsx +148 -0
- package/src/components/Button/index.ts +1 -0
- package/src/components/ButtonGroup/ButtonGroup.module.css +59 -0
- package/src/components/ButtonGroup/ButtonGroup.tsx +45 -0
- package/src/components/ButtonGroup/index.ts +1 -0
- package/src/components/Card/Card.module.css +82 -0
- package/src/components/Card/Card.tsx +34 -0
- package/src/components/Card/index.ts +1 -0
- package/src/components/Center/Center.module.css +15 -0
- package/src/components/Center/Center.tsx +28 -0
- package/src/components/Center/index.ts +1 -0
- package/src/components/Checkbox/Checkbox.module.css +120 -0
- package/src/components/Checkbox/Checkbox.tsx +133 -0
- package/src/components/Checkbox/index.ts +1 -0
- package/src/components/CheckboxGroup/CheckboxGroup.module.css +30 -0
- package/src/components/CheckboxGroup/CheckboxGroup.tsx +88 -0
- package/src/components/CheckboxGroup/index.ts +1 -0
- package/src/components/Cluster/Cluster.module.css +25 -0
- package/src/components/Cluster/Cluster.tsx +26 -0
- package/src/components/Cluster/index.ts +1 -0
- package/src/components/CodeBlock/CodeBlock.module.css +74 -0
- package/src/components/CodeBlock/CodeBlock.tsx +53 -0
- package/src/components/CodeBlock/highlight.ts +73 -0
- package/src/components/CodeBlock/index.ts +1 -0
- package/src/components/Collapsible/Collapsible.module.css +75 -0
- package/src/components/Collapsible/Collapsible.tsx +71 -0
- package/src/components/Collapsible/index.ts +1 -0
- package/src/components/Container/Container.module.css +14 -0
- package/src/components/Container/Container.tsx +19 -0
- package/src/components/Container/index.ts +1 -0
- package/src/components/CopyButton/CopyButton.module.css +125 -0
- package/src/components/CopyButton/CopyButton.tsx +160 -0
- package/src/components/CopyButton/index.ts +1 -0
- package/src/components/Dial/Dial.module.css +344 -0
- package/src/components/Dial/Dial.tsx +332 -0
- package/src/components/Dial/index.ts +1 -0
- package/src/components/Dialog/Dialog.module.css +190 -0
- package/src/components/Dialog/Dialog.tsx +100 -0
- package/src/components/Dialog/index.ts +1 -0
- package/src/components/Divider/Divider.module.css +39 -0
- package/src/components/Divider/Divider.tsx +34 -0
- package/src/components/Divider/index.ts +1 -0
- package/src/components/DropdownMenu/DropdownMenu.module.css +134 -0
- package/src/components/DropdownMenu/DropdownMenu.tsx +215 -0
- package/src/components/DropdownMenu/index.ts +1 -0
- package/src/components/EmptyState/EmptyState.module.css +66 -0
- package/src/components/EmptyState/EmptyState.tsx +38 -0
- package/src/components/EmptyState/index.ts +1 -0
- package/src/components/Fab/Fab.module.css +176 -0
- package/src/components/Fab/Fab.tsx +117 -0
- package/src/components/Fab/index.ts +1 -0
- package/src/components/Fieldset/Fieldset.module.css +34 -0
- package/src/components/Fieldset/Fieldset.tsx +41 -0
- package/src/components/Fieldset/index.ts +1 -0
- package/src/components/FormField/FormField.module.css +62 -0
- package/src/components/FormField/FormField.tsx +91 -0
- package/src/components/FormField/index.ts +2 -0
- package/src/components/Grid/Grid.module.css +39 -0
- package/src/components/Grid/Grid.tsx +35 -0
- package/src/components/Grid/index.ts +1 -0
- package/src/components/HoldToConfirm/HoldToConfirm.module.css +175 -0
- package/src/components/HoldToConfirm/HoldToConfirm.tsx +334 -0
- package/src/components/HoldToConfirm/index.ts +1 -0
- package/src/components/IconButton/IconButton.module.css +78 -0
- package/src/components/IconButton/IconButton.tsx +35 -0
- package/src/components/IconButton/index.ts +1 -0
- package/src/components/Input/Input.module.css +157 -0
- package/src/components/Input/Input.tsx +133 -0
- package/src/components/Input/index.ts +1 -0
- package/src/components/InputGroup/InputGroup.module.css +146 -0
- package/src/components/InputGroup/InputGroup.tsx +90 -0
- package/src/components/InputGroup/index.ts +1 -0
- package/src/components/Kbd/Kbd.module.css +28 -0
- package/src/components/Kbd/Kbd.tsx +38 -0
- package/src/components/Kbd/index.ts +1 -0
- package/src/components/Link/Link.module.css +65 -0
- package/src/components/Link/Link.tsx +41 -0
- package/src/components/Link/index.ts +1 -0
- package/src/components/LivePill/LivePill.module.css +207 -0
- package/src/components/LivePill/LivePill.tsx +182 -0
- package/src/components/LivePill/index.ts +1 -0
- package/src/components/Meter/Meter.module.css +91 -0
- package/src/components/Meter/Meter.tsx +109 -0
- package/src/components/Meter/index.ts +1 -0
- package/src/components/MorphButton/MorphButton.module.css +152 -0
- package/src/components/MorphButton/MorphButton.tsx +203 -0
- package/src/components/MorphButton/index.ts +1 -0
- package/src/components/NumberInput/NumberInput.module.css +104 -0
- package/src/components/NumberInput/NumberInput.tsx +252 -0
- package/src/components/NumberInput/index.ts +2 -0
- package/src/components/Pagination/Pagination.module.css +88 -0
- package/src/components/Pagination/Pagination.tsx +126 -0
- package/src/components/Pagination/index.ts +1 -0
- package/src/components/PasswordInput/PasswordInput.module.css +64 -0
- package/src/components/PasswordInput/PasswordInput.tsx +63 -0
- package/src/components/PasswordInput/index.ts +2 -0
- package/src/components/PickerWheel/PickerWheel.module.css +123 -0
- package/src/components/PickerWheel/PickerWheel.tsx +326 -0
- package/src/components/PickerWheel/index.ts +1 -0
- package/src/components/Popover/Popover.module.css +78 -0
- package/src/components/Popover/Popover.tsx +117 -0
- package/src/components/Popover/index.ts +1 -0
- package/src/components/ProgressBar/ProgressBar.module.css +61 -0
- package/src/components/ProgressBar/ProgressBar.tsx +48 -0
- package/src/components/ProgressBar/index.ts +1 -0
- package/src/components/Prose/Prose.module.css +115 -0
- package/src/components/Prose/Prose.tsx +14 -0
- package/src/components/Prose/index.ts +1 -0
- package/src/components/Radio/Radio.module.css +106 -0
- package/src/components/Radio/Radio.tsx +115 -0
- package/src/components/Radio/index.ts +1 -0
- package/src/components/Retime/Retime.tsx +116 -0
- package/src/components/Retime/index.ts +1 -0
- package/src/components/RulerScrubber/RulerScrubber.module.css +146 -0
- package/src/components/RulerScrubber/RulerScrubber.tsx +209 -0
- package/src/components/RulerScrubber/index.ts +1 -0
- package/src/components/ScrollArea/ScrollArea.module.css +72 -0
- package/src/components/ScrollArea/ScrollArea.tsx +172 -0
- package/src/components/ScrollArea/index.ts +1 -0
- package/src/components/SearchInput/SearchInput.module.css +53 -0
- package/src/components/SearchInput/SearchInput.tsx +104 -0
- package/src/components/SearchInput/index.ts +2 -0
- package/src/components/SegmentedControl/SegmentedControl.module.css +150 -0
- package/src/components/SegmentedControl/SegmentedControl.tsx +169 -0
- package/src/components/SegmentedControl/index.ts +1 -0
- package/src/components/Select/Select.module.css +204 -0
- package/src/components/Select/Select.tsx +254 -0
- package/src/components/Select/index.ts +1 -0
- package/src/components/Sheet/Sheet.module.css +228 -0
- package/src/components/Sheet/Sheet.tsx +449 -0
- package/src/components/Sheet/index.ts +1 -0
- package/src/components/Skeleton/Skeleton.module.css +56 -0
- package/src/components/Skeleton/Skeleton.tsx +37 -0
- package/src/components/Skeleton/index.ts +1 -0
- package/src/components/Slider/Slider.module.css +155 -0
- package/src/components/Slider/Slider.tsx +200 -0
- package/src/components/Slider/index.ts +1 -0
- package/src/components/Spinner/Spinner.module.css +50 -0
- package/src/components/Spinner/Spinner.tsx +29 -0
- package/src/components/Spinner/index.ts +1 -0
- package/src/components/Split/Split.module.css +29 -0
- package/src/components/Split/Split.tsx +33 -0
- package/src/components/Split/index.ts +1 -0
- package/src/components/SplitFlap/SplitFlap.module.css +107 -0
- package/src/components/SplitFlap/SplitFlap.tsx +225 -0
- package/src/components/SplitFlap/index.ts +1 -0
- package/src/components/Stack/Stack.module.css +17 -0
- package/src/components/Stack/Stack.tsx +19 -0
- package/src/components/Stack/index.ts +1 -0
- package/src/components/SwipeDeck/SwipeDeck.module.css +250 -0
- package/src/components/SwipeDeck/SwipeDeck.tsx +350 -0
- package/src/components/SwipeDeck/index.ts +1 -0
- package/src/components/Switch/Switch.module.css +97 -0
- package/src/components/Switch/Switch.tsx +147 -0
- package/src/components/Switch/index.ts +1 -0
- package/src/components/Table/Table.module.css +369 -0
- package/src/components/Table/Table.tsx +368 -0
- package/src/components/Table/index.ts +1 -0
- package/src/components/TableOfContents/TableOfContents.module.css +107 -0
- package/src/components/TableOfContents/TableOfContents.tsx +93 -0
- package/src/components/TableOfContents/index.ts +1 -0
- package/src/components/Tabs/Tabs.module.css +101 -0
- package/src/components/Tabs/Tabs.tsx +190 -0
- package/src/components/Tabs/index.ts +1 -0
- package/src/components/Tag/Tag.module.css +120 -0
- package/src/components/Tag/Tag.tsx +109 -0
- package/src/components/Tag/index.ts +1 -0
- package/src/components/Textarea/Textarea.module.css +79 -0
- package/src/components/Textarea/Textarea.tsx +130 -0
- package/src/components/Textarea/index.ts +1 -0
- package/src/components/ThemeToggle/ThemeToggle.module.css +21 -0
- package/src/components/ThemeToggle/ThemeToggle.tsx +69 -0
- package/src/components/ThemeToggle/index.ts +1 -0
- package/src/components/Toast/Toast.module.css +202 -0
- package/src/components/Toast/Toast.tsx +473 -0
- package/src/components/Toast/index.ts +1 -0
- package/src/components/Toggle/Toggle.module.css +94 -0
- package/src/components/Toggle/Toggle.tsx +50 -0
- package/src/components/Toggle/index.ts +1 -0
- package/src/components/Tooltip/Tooltip.module.css +34 -0
- package/src/components/Tooltip/Tooltip.tsx +154 -0
- package/src/components/Tooltip/index.ts +1 -0
- package/src/components/VisuallyHidden/VisuallyHidden.module.css +13 -0
- package/src/components/VisuallyHidden/VisuallyHidden.tsx +12 -0
- package/src/components/VisuallyHidden/index.ts +1 -0
- package/src/internal/FieldMessage.module.css +49 -0
- package/src/internal/FieldMessage.tsx +44 -0
- package/src/internal/Portal.tsx +7 -0
- package/src/internal/Roll.module.css +31 -0
- package/src/internal/Roll.tsx +20 -0
- package/src/internal/cx.ts +3 -0
- package/src/internal/feel.ts +355 -0
- package/src/internal/fling.ts +118 -0
- package/src/internal/focus.ts +94 -0
- package/src/internal/icons.module.css +62 -0
- package/src/internal/icons.tsx +511 -0
- package/src/internal/keyboard.ts +62 -0
- package/src/internal/layers.ts +85 -0
- package/src/internal/liquid.ts +248 -0
- package/src/internal/liquidMatter.ts +168 -0
- package/src/internal/liquidMore.ts +686 -0
- package/src/internal/liquidPath.ts +519 -0
- package/src/internal/mergeRefs.ts +10 -0
- package/src/internal/motion.ts +37 -0
- package/src/internal/relativeTime.ts +26 -0
- package/src/internal/scrollFrame.ts +157 -0
- package/src/internal/softPress.ts +299 -0
- package/src/internal/space.ts +6 -0
- package/src/internal/useControllable.ts +21 -0
- package/src/internal/useFloating.ts +85 -0
- package/src/internal/usePresence.ts +15 -0
- package/src/internal/useScrub.ts +160 -0
- package/src/tokens.css +727 -0
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
// Feel: how a value moves under the hand. A drag follows the hand one to one; a let-go coasts a capped
|
|
2
|
+
// distance and lands on the morph curve, starting at the hand's speed. Plain TypeScript with no
|
|
3
|
+
// framework and no styling, so it can stand on its own. Every time is passed in, so a duration of 0
|
|
4
|
+
// (reduced motion) keeps each result and drops the motion.
|
|
5
|
+
|
|
6
|
+
/** A cubic-bezier's four numbers. */
|
|
7
|
+
export type Curve = [number, number, number, number]
|
|
8
|
+
|
|
9
|
+
/** The numbers of --gooee-ease-morph, for when the token cannot be read. */
|
|
10
|
+
export const MORPH: Curve = [0.2, 0, 0, 1]
|
|
11
|
+
|
|
12
|
+
export const clamp = (v: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, v))
|
|
13
|
+
|
|
14
|
+
/** `n` folded into 0 to `size`, for lists that loop. */
|
|
15
|
+
export const wrap = (n: number, size: number) => ((n % size) + size) % size
|
|
16
|
+
|
|
17
|
+
/** `v` on the nearest step counted from `origin`, without float dust, so 0.1 + 0.2 is 0.3. */
|
|
18
|
+
export const roundTo = (v: number, step: number, origin = 0) => Number((Math.round((v - origin) / step) * step + origin).toFixed(10))
|
|
19
|
+
|
|
20
|
+
/** The last step at or below `max`, counted from `min`. */
|
|
21
|
+
export const lastStep = (min: number, max: number, step: number) => roundTo(min + Math.floor((max - min) / step + 1e-9) * step, step, min)
|
|
22
|
+
|
|
23
|
+
/** Every step from `min` to `max`. */
|
|
24
|
+
export const steps = (min: number, max: number, step: number) => Array.from({ length: Math.floor((max - min) / step + 1e-9) + 1 }, (_, i) => roundTo(min + i * step, step, min))
|
|
25
|
+
|
|
26
|
+
/** The mark nearest to `value`, or null when there are none. */
|
|
27
|
+
export function nearestMark(value: number, marks: number[]): number | null {
|
|
28
|
+
let best: number | null = null
|
|
29
|
+
for (const m of marks) if (best === null || Math.abs(m - value) < Math.abs(best - value)) best = m
|
|
30
|
+
return best
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** 1 on the mark, 0 at the edge of its reach, smooth in between. Drives size and ink. */
|
|
34
|
+
export function pull(distance: number, reach: number) {
|
|
35
|
+
if (reach <= 0) return distance === 0 ? 1 : 0
|
|
36
|
+
const t = Math.min(1, Math.abs(distance) / reach)
|
|
37
|
+
return 0.5 + 0.5 * Math.cos(Math.PI * t)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Past an edge a drag still moves, less the further it goes, and never more than `size`. */
|
|
41
|
+
export function rubber(over: number, size: number) {
|
|
42
|
+
if (size <= 0) return 0
|
|
43
|
+
return Math.sign(over) * (1 - 1 / ((Math.abs(over) * 0.55) / size + 1)) * size
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The hand's speed when it lets go, in units per second, from its last moves inside `window` ms. */
|
|
47
|
+
export function speedTracker(window = 100) {
|
|
48
|
+
let samples: { t: number; x: number }[] = []
|
|
49
|
+
return {
|
|
50
|
+
add(x: number, t = performance.now()) {
|
|
51
|
+
samples = [...samples.filter((s) => t - s.t <= window), { t, x }]
|
|
52
|
+
},
|
|
53
|
+
speed(t = performance.now()) {
|
|
54
|
+
const recent = samples.filter((s) => t - s.t <= window)
|
|
55
|
+
if (recent.length < 2) return 0
|
|
56
|
+
const a = recent[0]
|
|
57
|
+
const b = recent[recent.length - 1]
|
|
58
|
+
return b.t > a.t ? ((b.x - a.x) / (b.t - a.t)) * 1000 : 0
|
|
59
|
+
},
|
|
60
|
+
reset() {
|
|
61
|
+
samples = []
|
|
62
|
+
},
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** A cubic-bezier as a function from a share of the time (0 to 1) to a share of the way. */
|
|
67
|
+
export function bezier([x1, y1, x2, y2]: Curve) {
|
|
68
|
+
const along = (a: number, b: number, t: number) => 3 * a * t * (1 - t) ** 2 + 3 * b * t * t * (1 - t) + t ** 3
|
|
69
|
+
return (x: number) => {
|
|
70
|
+
if (x <= 0) return 0
|
|
71
|
+
if (x >= 1) return 1
|
|
72
|
+
let lo = 0
|
|
73
|
+
let hi = 1
|
|
74
|
+
let t = x
|
|
75
|
+
for (let i = 0; i < 24; i++) {
|
|
76
|
+
const at = along(x1, x2, t)
|
|
77
|
+
if (Math.abs(at - x) < 1e-5) break
|
|
78
|
+
if (at < x) lo = t
|
|
79
|
+
else hi = t
|
|
80
|
+
t = (lo + hi) / 2
|
|
81
|
+
}
|
|
82
|
+
return along(y1, y2, t)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export type MorphOptions = {
|
|
87
|
+
from: number
|
|
88
|
+
to: number
|
|
89
|
+
/** Units per second at the start. Toward `to`, a let-go carries on at the hand's speed, so the move takes less time. */
|
|
90
|
+
velocity?: number
|
|
91
|
+
/** How long the move takes from rest, in ms. 0 jumps straight to `to`. */
|
|
92
|
+
duration: number
|
|
93
|
+
/** The curve. Defaults to the morph curve. */
|
|
94
|
+
curve?: Curve
|
|
95
|
+
onFrame: (value: number) => void
|
|
96
|
+
onDone?: () => void
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Runs from `from` to `to` on the curve and stops there. Returns a stop function. */
|
|
100
|
+
export function morphTo({ from, to, velocity = 0, duration, curve = MORPH, onFrame, onDone }: MorphOptions) {
|
|
101
|
+
if (!duration || from === to) {
|
|
102
|
+
onFrame(to)
|
|
103
|
+
onDone?.()
|
|
104
|
+
return () => {}
|
|
105
|
+
}
|
|
106
|
+
const D = to - from
|
|
107
|
+
// The curve starts at y1 / x1 times its average speed. A let-go toward `to` shortens the move until
|
|
108
|
+
// that start speed is the hand's, but never below 40% of the time, so a hard throw still lands softly.
|
|
109
|
+
const lead = curve[0] > 0 ? curve[1] / curve[0] : 1
|
|
110
|
+
const toward = Math.sign(velocity) === Math.sign(D) ? Math.abs(velocity) : 0
|
|
111
|
+
const ms = toward ? clamp(((lead * Math.abs(D)) / toward) * 1000, duration * 0.4, duration) : duration
|
|
112
|
+
const ease = bezier(curve)
|
|
113
|
+
const t0 = performance.now()
|
|
114
|
+
let raf = 0
|
|
115
|
+
const finish = () => {
|
|
116
|
+
cancelAnimationFrame(raf)
|
|
117
|
+
clearTimeout(backstop)
|
|
118
|
+
onFrame(to)
|
|
119
|
+
onDone?.()
|
|
120
|
+
}
|
|
121
|
+
// Frames can stall (a hidden tab, a slow phone), so a timer lands it in real time if they do.
|
|
122
|
+
const backstop = setTimeout(finish, ms + 50)
|
|
123
|
+
raf = requestAnimationFrame(function step(now) {
|
|
124
|
+
const t = (now - t0) / ms
|
|
125
|
+
if (t >= 1) return finish()
|
|
126
|
+
onFrame(from + D * ease(t))
|
|
127
|
+
raf = requestAnimationFrame(step)
|
|
128
|
+
})
|
|
129
|
+
return () => {
|
|
130
|
+
cancelAnimationFrame(raf)
|
|
131
|
+
clearTimeout(backstop)
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export type GlideOptions = Omit<MorphOptions, 'to' | 'onDone'> & {
|
|
136
|
+
/** Where it comes to rest, given where the coast would end. */
|
|
137
|
+
land: (end: number) => number
|
|
138
|
+
/** How far a flick carries: its speed times this, in seconds. 0 lands under the hand. */
|
|
139
|
+
coast?: number
|
|
140
|
+
/** The fastest a flick may go, in units per second, so a hard throw still stops near the hand. */
|
|
141
|
+
maxSpeed?: number
|
|
142
|
+
onDone?: (to: number) => void
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* A let-go: it lands on `land(end)`, where `end` is as far as the flick would coast, on the morph
|
|
147
|
+
* curve at the hand's speed. With a duration of 0 it lands at once, on the place under the hand.
|
|
148
|
+
*/
|
|
149
|
+
export function glide({ from, velocity = 0, land, coast = 0.2, maxSpeed = Infinity, duration, curve, onFrame, onDone }: GlideOptions) {
|
|
150
|
+
if (!duration) {
|
|
151
|
+
const to = land(from)
|
|
152
|
+
onFrame(to)
|
|
153
|
+
onDone?.(to)
|
|
154
|
+
return { to, stop: () => {} }
|
|
155
|
+
}
|
|
156
|
+
const v = clamp(velocity, -maxSpeed, maxSpeed)
|
|
157
|
+
const to = land(from + v * coast)
|
|
158
|
+
return { to, stop: morphTo({ from, to, velocity: v, duration, curve, onFrame, onDone: () => onDone?.(to) }) }
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** A number that moves toward a target on the curve, over `time()` ms from where it is. A time of 0 jumps. */
|
|
162
|
+
export function follow({ value = 0, time, curve, onFrame }: { value?: number; time: () => number; curve?: Curve; onFrame: (value: number) => void }) {
|
|
163
|
+
let at = value
|
|
164
|
+
let to = value
|
|
165
|
+
let stop = () => {}
|
|
166
|
+
return {
|
|
167
|
+
get value() {
|
|
168
|
+
return at
|
|
169
|
+
},
|
|
170
|
+
set(target: number) {
|
|
171
|
+
if (target === to) return
|
|
172
|
+
to = target
|
|
173
|
+
stop()
|
|
174
|
+
stop = morphTo({ from: at, to, duration: time(), curve, onFrame: (v) => onFrame((at = v)) })
|
|
175
|
+
},
|
|
176
|
+
stop() {
|
|
177
|
+
stop()
|
|
178
|
+
},
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export type KeyRange = { min: number; max: number; step: number; marks?: number[] }
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* The same keys everywhere: Up or Right one step more, Down or Left one step less, Page Up and Page
|
|
186
|
+
* Down to the next mark (or ten steps), Home and End to the ends. Null for any other key.
|
|
187
|
+
*/
|
|
188
|
+
export function stepKey(key: string, value: number, { min, max: end, step, marks = [] }: KeyRange) {
|
|
189
|
+
const max = lastStep(min, end, step)
|
|
190
|
+
const by = (n: number) => clamp(roundTo(value + n * step, step, min), min, max)
|
|
191
|
+
const sorted = [...marks].sort((a, b) => a - b)
|
|
192
|
+
if (key === 'ArrowUp' || key === 'ArrowRight') return by(1)
|
|
193
|
+
if (key === 'ArrowDown' || key === 'ArrowLeft') return by(-1)
|
|
194
|
+
if (key === 'PageUp') return sorted.length ? (sorted.find((m) => m > value + 1e-9) ?? max) : by(10)
|
|
195
|
+
if (key === 'PageDown') return sorted.length ? ([...sorted].reverse().find((m) => m < value - 1e-9) ?? min) : by(-10)
|
|
196
|
+
if (key === 'Home') return min
|
|
197
|
+
if (key === 'End') return max
|
|
198
|
+
return null
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** Wheel deltas into whole steps of `per` px: by default about one mouse wheel notch, while a trackpad adds up. */
|
|
202
|
+
export function wheelSteps() {
|
|
203
|
+
let acc = 0
|
|
204
|
+
let last = 0
|
|
205
|
+
return (delta: number, per = 100, t = performance.now()) => {
|
|
206
|
+
// A pause starts a fresh gesture, so half a step left from before does not count.
|
|
207
|
+
if (t - last > 400) acc = 0
|
|
208
|
+
last = t
|
|
209
|
+
acc += delta
|
|
210
|
+
const n = Math.trunc(acc / per)
|
|
211
|
+
acc -= n * per
|
|
212
|
+
return n
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export type ScrubOptions = {
|
|
217
|
+
/** Where it starts. */
|
|
218
|
+
value: number
|
|
219
|
+
/** Leave both out for a loop. */
|
|
220
|
+
min?: number
|
|
221
|
+
max?: number
|
|
222
|
+
/** How far a drag stretches past an end, in units. */
|
|
223
|
+
edge?: number
|
|
224
|
+
/** The value a position comes to rest on. */
|
|
225
|
+
land: (at: number) => number
|
|
226
|
+
/** How far a flick coasts: its speed times this, in seconds. */
|
|
227
|
+
coast?: number
|
|
228
|
+
/** The fastest a flick may go, in units per second. */
|
|
229
|
+
maxSpeed?: number
|
|
230
|
+
/** How long a glide takes in ms, read at each start. 0 is reduced motion: the same result, no glide. */
|
|
231
|
+
duration: () => number
|
|
232
|
+
/** The glide's curve, read at each start. */
|
|
233
|
+
curve?: () => Curve
|
|
234
|
+
onFrame?: (at: number) => void
|
|
235
|
+
onMoving?: (moving: boolean) => void
|
|
236
|
+
/** A new resting value came under the hand. */
|
|
237
|
+
onMark?: (value: number) => void
|
|
238
|
+
/** It came to rest on a value. */
|
|
239
|
+
onSettle?: (value: number) => void
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** One value under a hand: grab, drag, let go, or go straight to a value. */
|
|
243
|
+
export function createScrub(options: ScrubOptions) {
|
|
244
|
+
let o = options
|
|
245
|
+
let at = o.value
|
|
246
|
+
let raw = o.value
|
|
247
|
+
let target = o.value
|
|
248
|
+
let moving = false
|
|
249
|
+
let dragged = false
|
|
250
|
+
let lastMark = o.value
|
|
251
|
+
let stop = () => {}
|
|
252
|
+
const tracker = speedTracker()
|
|
253
|
+
|
|
254
|
+
const bounded = () => o.min !== undefined && o.max !== undefined
|
|
255
|
+
const inRange = (v: number) => (bounded() ? clamp(v, o.min!, o.max!) : v)
|
|
256
|
+
const stretch = (r: number) => {
|
|
257
|
+
if (!bounded()) return r
|
|
258
|
+
const edge = o.edge ?? 0
|
|
259
|
+
if (r < o.min!) return o.min! + rubber(r - o.min!, edge)
|
|
260
|
+
if (r > o.max!) return o.max! + rubber(r - o.max!, edge)
|
|
261
|
+
return r
|
|
262
|
+
}
|
|
263
|
+
const setMoving = (m: boolean) => {
|
|
264
|
+
if (moving === m) return
|
|
265
|
+
moving = m
|
|
266
|
+
o.onMoving?.(m)
|
|
267
|
+
}
|
|
268
|
+
const paint = (p: number) => {
|
|
269
|
+
at = p
|
|
270
|
+
o.onFrame?.(p)
|
|
271
|
+
const m = o.land(inRange(p))
|
|
272
|
+
if (m !== lastMark) {
|
|
273
|
+
lastMark = m
|
|
274
|
+
o.onMark?.(m)
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
const done = (to: number) => {
|
|
278
|
+
target = to
|
|
279
|
+
setMoving(false)
|
|
280
|
+
o.onSettle?.(to)
|
|
281
|
+
}
|
|
282
|
+
const run = (velocity: number, land: (end: number) => number, coast: number) => {
|
|
283
|
+
stop()
|
|
284
|
+
setMoving(true)
|
|
285
|
+
const g = glide({ from: at, velocity, land, coast, maxSpeed: o.maxSpeed, duration: o.duration(), curve: o.curve?.(), onFrame: paint, onDone: done })
|
|
286
|
+
target = g.to
|
|
287
|
+
stop = g.stop
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return {
|
|
291
|
+
/** Where it is drawn now, between values while it moves. */
|
|
292
|
+
get at() {
|
|
293
|
+
return at
|
|
294
|
+
},
|
|
295
|
+
/** Where it is going, or where it rests. */
|
|
296
|
+
get target() {
|
|
297
|
+
return target
|
|
298
|
+
},
|
|
299
|
+
get moving() {
|
|
300
|
+
return moving
|
|
301
|
+
},
|
|
302
|
+
/** Swaps in new options, such as fresh callbacks after a render. */
|
|
303
|
+
update(next: Partial<ScrubOptions>) {
|
|
304
|
+
o = { ...o, ...next }
|
|
305
|
+
},
|
|
306
|
+
/** The hand comes down: whatever moved stops where it is. */
|
|
307
|
+
grab(t?: number) {
|
|
308
|
+
stop()
|
|
309
|
+
raw = at
|
|
310
|
+
dragged = false
|
|
311
|
+
tracker.reset()
|
|
312
|
+
tracker.add(raw, t)
|
|
313
|
+
},
|
|
314
|
+
/** The hand moves it by `delta` units. */
|
|
315
|
+
drag(delta: number, t?: number) {
|
|
316
|
+
dragged = true
|
|
317
|
+
setMoving(true)
|
|
318
|
+
raw += delta
|
|
319
|
+
tracker.add(raw, t)
|
|
320
|
+
paint(stretch(raw))
|
|
321
|
+
},
|
|
322
|
+
/** The hand lets go: it coasts at the hand's speed and lands on a value. */
|
|
323
|
+
release(t?: number) {
|
|
324
|
+
// Let go past an end, it glides back from the stretch with no speed of its own.
|
|
325
|
+
const outside = bounded() && (at < o.min! || at > o.max!)
|
|
326
|
+
const speed = dragged && !outside ? tracker.speed(t) : 0
|
|
327
|
+
dragged = false
|
|
328
|
+
run(speed, (end) => o.land(inRange(end)), o.coast ?? 0.2)
|
|
329
|
+
},
|
|
330
|
+
/** The hand was taken away (the page scrolled instead): it lands where it is, with no speed. */
|
|
331
|
+
cancel() {
|
|
332
|
+
dragged = false
|
|
333
|
+
run(0, (end) => o.land(inRange(end)), 0)
|
|
334
|
+
},
|
|
335
|
+
/** Glides to `to` and rests there. */
|
|
336
|
+
go(to: number) {
|
|
337
|
+
run(0, () => to, 0)
|
|
338
|
+
},
|
|
339
|
+
/** Puts it on `to` at once, with no motion. */
|
|
340
|
+
place(to: number) {
|
|
341
|
+
stop()
|
|
342
|
+
raw = to
|
|
343
|
+
lastMark = to
|
|
344
|
+
paint(to)
|
|
345
|
+
done(to)
|
|
346
|
+
},
|
|
347
|
+
/** Stops any motion where it is. */
|
|
348
|
+
stop() {
|
|
349
|
+
stop()
|
|
350
|
+
setMoving(false)
|
|
351
|
+
},
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export type Scrub = ReturnType<typeof createScrub>
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { useEffect, useRef, type PointerEvent, type RefObject } from 'react'
|
|
2
|
+
import { morphTo, rubber, speedTracker } from './feel'
|
|
3
|
+
import { morphCurve, readMotionMs } from './motion'
|
|
4
|
+
|
|
5
|
+
export { rubber, speedTracker }
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A let-go: runs from `from` to `to` on the morph curve, starting at `velocity` (units per second), so
|
|
9
|
+
* it carries on at the hand's speed. From rest it takes --gooee-motion-morph-out: Retime slows it,
|
|
10
|
+
* reduced motion (0ms) jumps. Returns a stop function.
|
|
11
|
+
*/
|
|
12
|
+
export function release(from: number, to: number, velocity: number, onFrame: (value: number) => void, onDone?: () => void) {
|
|
13
|
+
return morphTo({ from, to, velocity, duration: readMotionMs('morph-out'), curve: morphCurve(), onFrame, onDone })
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A dialog panel that the hand drags along one axis and lets go of. `fling` glides it to a place at
|
|
18
|
+
* the hand's speed. While it runs, data-fluid on the panel turns its CSS motion off; once the parent
|
|
19
|
+
* closes it on the way out, the CSS close keyframes stay off too, so they do not start over.
|
|
20
|
+
*/
|
|
21
|
+
export function useFling(ref: RefObject<HTMLElement | null>, open: boolean, axis: 'x' | 'y') {
|
|
22
|
+
const at = useRef(0)
|
|
23
|
+
const target = useRef(0)
|
|
24
|
+
const stop = useRef(() => {})
|
|
25
|
+
|
|
26
|
+
const paint = (v: number) => {
|
|
27
|
+
at.current = v
|
|
28
|
+
if (ref.current) ref.current.style.transform = v ? `translate${axis === 'x' ? 'X' : 'Y'}(${v}px)` : ''
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const fling = (to: number, speed: number) => {
|
|
32
|
+
const el = ref.current
|
|
33
|
+
if (!el) return
|
|
34
|
+
stop.current()
|
|
35
|
+
target.current = to
|
|
36
|
+
el.setAttribute('data-fluid', '')
|
|
37
|
+
stop.current = release(at.current, to, speed, paint, () => {
|
|
38
|
+
if (to === 0) el.removeAttribute('data-fluid')
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
useEffect(() => () => stop.current(), [])
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
// Opened again, even mid-close on the same panel: it starts at rest, not where the old glide was going.
|
|
45
|
+
if (open) {
|
|
46
|
+
stop.current()
|
|
47
|
+
target.current = 0
|
|
48
|
+
paint(0)
|
|
49
|
+
ref.current?.removeAttribute('data-fluid')
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
// Closed by Esc or a tap while gliding back: the CSS close takes over from where it is.
|
|
53
|
+
if (target.current !== 0) return
|
|
54
|
+
stop.current()
|
|
55
|
+
ref.current?.removeAttribute('data-fluid')
|
|
56
|
+
}, [open])
|
|
57
|
+
|
|
58
|
+
return { at, paint, fling, stop: () => stop.current() }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Past this share of its height, or flicked down this fast (px per second), a let-go closes the sheet.
|
|
62
|
+
const CLOSE_RATIO = 0.3
|
|
63
|
+
const CLOSE_SPEED = 500
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A bottom sheet the hand drags down to close. Returns pointer handlers for the part it is held by. A
|
|
67
|
+
* let-go past a third of its height, or a flick down, closes it; any other let-go glides it back.
|
|
68
|
+
* `can` is asked at each press, so a part can take hold only in its phone layout, or only by its header.
|
|
69
|
+
*/
|
|
70
|
+
export function useDragClose(ref: RefObject<HTMLElement | null>, open: boolean, onClose: () => void, can: (e: PointerEvent<HTMLElement>) => boolean = () => true) {
|
|
71
|
+
const drag = useRef<{ y: number; dy: number; pointer: number; speed: ReturnType<typeof speedTracker> } | null>(null)
|
|
72
|
+
const openRef = useRef(open)
|
|
73
|
+
openRef.current = open
|
|
74
|
+
const { at, paint, fling, stop } = useFling(ref, open, 'y')
|
|
75
|
+
|
|
76
|
+
const onPointerDown = (e: PointerEvent<HTMLElement>) => {
|
|
77
|
+
if ((e.target as HTMLElement).closest('button') || !can(e)) return
|
|
78
|
+
if (e.pointerType === 'mouse' && e.button !== 0) return
|
|
79
|
+
stop()
|
|
80
|
+
// Caught mid-glide, it carries on from where it is.
|
|
81
|
+
drag.current = { y: e.clientY - at.current, dy: at.current, pointer: e.pointerId, speed: speedTracker() }
|
|
82
|
+
drag.current.speed.add(at.current)
|
|
83
|
+
e.currentTarget.setPointerCapture(e.pointerId)
|
|
84
|
+
ref.current?.setAttribute('data-dragging', '')
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const onPointerMove = (e: PointerEvent<HTMLElement>) => {
|
|
88
|
+
const d = drag.current
|
|
89
|
+
const panel = ref.current
|
|
90
|
+
if (!d || !panel || d.pointer !== e.pointerId) return
|
|
91
|
+
const raw = e.clientY - d.y
|
|
92
|
+
d.dy = raw >= 0 ? raw : rubber(raw, panel.offsetHeight)
|
|
93
|
+
d.speed.add(d.dy)
|
|
94
|
+
paint(d.dy)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const onPointerUp = (e: PointerEvent<HTMLElement>) => {
|
|
98
|
+
const d = drag.current
|
|
99
|
+
const panel = ref.current
|
|
100
|
+
drag.current = null
|
|
101
|
+
if (!d || !panel) return
|
|
102
|
+
e.currentTarget.releasePointerCapture(d.pointer)
|
|
103
|
+
panel.removeAttribute('data-dragging')
|
|
104
|
+
const cancelled = e.type === 'pointercancel'
|
|
105
|
+
const speed = cancelled ? 0 : d.speed.speed()
|
|
106
|
+
const h = panel.offsetHeight
|
|
107
|
+
if (!cancelled && (d.dy > h * CLOSE_RATIO || (speed > CLOSE_SPEED && d.dy > 24))) {
|
|
108
|
+
fling(h, speed)
|
|
109
|
+
onClose()
|
|
110
|
+
// If the parent keeps it open, it glides back.
|
|
111
|
+
requestAnimationFrame(() => {
|
|
112
|
+
if (openRef.current) fling(0, 0)
|
|
113
|
+
})
|
|
114
|
+
} else fling(0, speed)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return { onPointerDown, onPointerMove, onPointerUp, onPointerCancel: onPointerUp }
|
|
118
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { useEffect, type RefObject } from 'react'
|
|
2
|
+
import { watchKeyboard } from './keyboard'
|
|
3
|
+
|
|
4
|
+
const FOCUSABLE =
|
|
5
|
+
'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"]), [contenteditable="true"]'
|
|
6
|
+
|
|
7
|
+
export function focusables(root: HTMLElement): HTMLElement[] {
|
|
8
|
+
return Array.from(root.querySelectorAll<HTMLElement>(FOCUSABLE)).filter(
|
|
9
|
+
(el) => !el.hasAttribute('inert') && el.getClientRects().length > 0,
|
|
10
|
+
)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Safari, on iPhone and on Mac, does not focus a button when it is tapped or clicked. So the control
|
|
14
|
+
// that opened a layer is often not the focused element; remember the last one pressed instead.
|
|
15
|
+
// Watched from the moment this file loads, since a layer only mounts after the press that opens it.
|
|
16
|
+
let lastPressed: HTMLElement | null = null
|
|
17
|
+
if (typeof document !== 'undefined') {
|
|
18
|
+
document.addEventListener(
|
|
19
|
+
'pointerdown',
|
|
20
|
+
(e) => {
|
|
21
|
+
lastPressed = (e.target instanceof Element ? e.target.closest<HTMLElement>(FOCUSABLE) : null) ?? null
|
|
22
|
+
},
|
|
23
|
+
true,
|
|
24
|
+
)
|
|
25
|
+
// Focus moved from code stays above a phone keyboard.
|
|
26
|
+
watchKeyboard()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Where focus should go back to: the focused element, unless it is the page or a box around the
|
|
30
|
+
// control that was just pressed. Then that control.
|
|
31
|
+
export function returnTarget(): HTMLElement | null {
|
|
32
|
+
const active = document.activeElement as HTMLElement | null
|
|
33
|
+
const pressed = lastPressed && lastPressed.isConnected ? lastPressed : null
|
|
34
|
+
if (pressed && (!active || active === document.body || (active !== pressed && active.contains(pressed)))) return pressed
|
|
35
|
+
return active
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function useFocusTrap(
|
|
39
|
+
ref: RefObject<HTMLElement | null>,
|
|
40
|
+
active: boolean,
|
|
41
|
+
options: { initialFocus?: RefObject<HTMLElement | null>; restore?: boolean } = {},
|
|
42
|
+
) {
|
|
43
|
+
const { initialFocus, restore = true } = options
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (!active) return
|
|
46
|
+
const root = ref.current
|
|
47
|
+
if (!root) return
|
|
48
|
+
const previous = returnTarget()
|
|
49
|
+
// Close buttons opt out of first focus, so focus lands on the content or the safe action.
|
|
50
|
+
const list = focusables(root)
|
|
51
|
+
const first = initialFocus?.current ?? list.find((el) => !el.hasAttribute('data-skip-initial-focus')) ?? list[0] ?? root
|
|
52
|
+
first.focus({ preventScroll: true })
|
|
53
|
+
|
|
54
|
+
// Safari's plain Tab skips buttons, so it can jump from the middle of the layer to the page behind,
|
|
55
|
+
// or off the page. A Tab that lands outside goes back to the end it wrapped past.
|
|
56
|
+
let check = 0
|
|
57
|
+
const onKey = (e: KeyboardEvent) => {
|
|
58
|
+
if (e.key !== 'Tab') return
|
|
59
|
+
const items = focusables(root)
|
|
60
|
+
if (items.length === 0) {
|
|
61
|
+
e.preventDefault()
|
|
62
|
+
root.focus()
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
const firstEl = items[0]
|
|
66
|
+
const lastEl = items[items.length - 1]
|
|
67
|
+
const current = document.activeElement
|
|
68
|
+
if (e.shiftKey && (current === firstEl || current === root)) {
|
|
69
|
+
e.preventDefault()
|
|
70
|
+
lastEl.focus()
|
|
71
|
+
} else if (!e.shiftKey && current === lastEl) {
|
|
72
|
+
e.preventDefault()
|
|
73
|
+
firstEl.focus()
|
|
74
|
+
} else {
|
|
75
|
+
const back = e.shiftKey
|
|
76
|
+
clearTimeout(check)
|
|
77
|
+
check = window.setTimeout(() => {
|
|
78
|
+
if (root.contains(document.activeElement)) return
|
|
79
|
+
const now = focusables(root)
|
|
80
|
+
now[back ? now.length - 1 : 0]?.focus({ preventScroll: true })
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
root.addEventListener('keydown', onKey)
|
|
85
|
+
return () => {
|
|
86
|
+
clearTimeout(check)
|
|
87
|
+
root.removeEventListener('keydown', onKey)
|
|
88
|
+
// Give focus back only if it is still in the layer, so a click elsewhere keeps its own focus.
|
|
89
|
+
const now = document.activeElement
|
|
90
|
+
const stillInside = !now || now === document.body || root.contains(now)
|
|
91
|
+
if (restore && stillInside && previous && document.contains(previous)) previous.focus({ preventScroll: true })
|
|
92
|
+
}
|
|
93
|
+
}, [active])
|
|
94
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/* Each icon's motion plays once when the control it sits in is pointed at or focused, or when the icon
|
|
2
|
+
itself is. Nothing plays with reduced motion. Moves stay within about a tenth of the icon, so it never
|
|
3
|
+
leaves its box. */
|
|
4
|
+
.icon { transform-origin: 50% 50%; }
|
|
5
|
+
.icon[data-motion="swing"] { transform-origin: 50% 12%; }
|
|
6
|
+
.icon[data-motion="grow"] { transform-origin: 50% 86%; }
|
|
7
|
+
|
|
8
|
+
.icon[data-motion="nudge-r"] { --gooee-icon-play: gooee-icon-nudge-r; }
|
|
9
|
+
.icon[data-motion="nudge-l"] { --gooee-icon-play: gooee-icon-nudge-l; }
|
|
10
|
+
.icon[data-motion="nudge-u"] { --gooee-icon-play: gooee-icon-nudge-u; }
|
|
11
|
+
.icon[data-motion="nudge-d"] { --gooee-icon-play: gooee-icon-nudge-d; }
|
|
12
|
+
.icon[data-motion="nudge-ur"] { --gooee-icon-play: gooee-icon-nudge-ur; }
|
|
13
|
+
.icon[data-motion="swing"] { --gooee-icon-play: gooee-icon-swing; }
|
|
14
|
+
.icon[data-motion="turn"] { --gooee-icon-play: gooee-icon-turn; }
|
|
15
|
+
.icon[data-motion="pop"] { --gooee-icon-play: gooee-icon-pop; }
|
|
16
|
+
.icon[data-motion="blink"] { --gooee-icon-play: gooee-icon-blink; }
|
|
17
|
+
.icon[data-motion="wiggle"] { --gooee-icon-play: gooee-icon-wiggle; }
|
|
18
|
+
.icon[data-motion="bounce"] { --gooee-icon-play: gooee-icon-bounce; }
|
|
19
|
+
.icon[data-motion="grow"] { --gooee-icon-play: gooee-icon-grow; }
|
|
20
|
+
|
|
21
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
22
|
+
:global(:is(a, button, label, summary, [role="button"], [role="menuitem"], [role="tab"], [role="option"], [role="link"])):is(:hover, :focus-visible) .icon,
|
|
23
|
+
.icon:hover {
|
|
24
|
+
animation: var(--gooee-icon-play, none) var(--gooee-motion-slow) var(--gooee-ease-out);
|
|
25
|
+
}
|
|
26
|
+
:global(:is(a, button, label, summary, [role="button"], [role="menuitem"], [role="tab"], [role="option"], [role="link"])):is(:hover, :focus-visible) .icon[data-motion="draw"] > *,
|
|
27
|
+
.icon[data-motion="draw"]:hover > * {
|
|
28
|
+
stroke-dasharray: 1;
|
|
29
|
+
animation: draw var(--gooee-motion-slower) var(--gooee-ease-out);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@keyframes :global(gooee-icon-nudge-r) { 40% { transform: translateX(0.12em); } }
|
|
34
|
+
@keyframes :global(gooee-icon-nudge-l) { 40% { transform: translateX(-0.12em); } }
|
|
35
|
+
@keyframes :global(gooee-icon-nudge-u) { 40% { transform: translateY(-0.12em); } }
|
|
36
|
+
@keyframes :global(gooee-icon-nudge-d) { 40% { transform: translateY(0.12em); } }
|
|
37
|
+
@keyframes :global(gooee-icon-nudge-ur) { 40% { transform: translate(0.1em, -0.1em); } }
|
|
38
|
+
@keyframes :global(gooee-icon-swing) {
|
|
39
|
+
25% { transform: rotate(14deg); }
|
|
40
|
+
50% { transform: rotate(-10deg); }
|
|
41
|
+
75% { transform: rotate(5deg); }
|
|
42
|
+
}
|
|
43
|
+
@keyframes :global(gooee-icon-turn) { to { transform: rotate(1turn); } }
|
|
44
|
+
@keyframes :global(gooee-icon-pop) { 40% { transform: scale(1.18); } }
|
|
45
|
+
@keyframes :global(gooee-icon-blink) { 45% { transform: scaleY(0.12); } }
|
|
46
|
+
@keyframes :global(gooee-icon-wiggle) {
|
|
47
|
+
20% { transform: rotate(-10deg); }
|
|
48
|
+
40% { transform: rotate(9deg); }
|
|
49
|
+
60% { transform: rotate(-6deg); }
|
|
50
|
+
80% { transform: rotate(3deg); }
|
|
51
|
+
}
|
|
52
|
+
@keyframes :global(gooee-icon-grow) {
|
|
53
|
+
40% { transform: scale(0.94, 1.14); }
|
|
54
|
+
70% { transform: scale(1.02, 0.97); }
|
|
55
|
+
}
|
|
56
|
+
@keyframes :global(gooee-icon-bounce) {
|
|
57
|
+
35% { transform: translateY(-0.14em); }
|
|
58
|
+
65% { transform: translateY(0.03em); }
|
|
59
|
+
}
|
|
60
|
+
/* Named in this file (not global): only the rule above plays it. The others are global because their
|
|
61
|
+
name travels in --gooee-icon-play, which CSS modules do not rename. */
|
|
62
|
+
@keyframes draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
|