gooee 0.41.1 → 0.45.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/README.md +1 -1
  2. package/package.json +1 -1
  3. package/src/components/AnimatedNumber/AnimatedNumber.module.css +3 -3
  4. package/src/components/Badge/Badge.module.css +1 -1
  5. package/src/components/Button/Button.module.css +4 -4
  6. package/src/components/Dial/Dial.module.css +2 -2
  7. package/src/components/Dialog/Dialog.module.css +10 -4
  8. package/src/components/HoldToConfirm/HoldToConfirm.module.css +37 -52
  9. package/src/components/HoldToConfirm/HoldToConfirm.tsx +146 -60
  10. package/src/components/Kbd/Kbd.module.css +1 -1
  11. package/src/components/LivePill/LivePill.module.css +211 -31
  12. package/src/components/LivePill/LivePill.tsx +45 -14
  13. package/src/components/MorphButton/MorphButton.module.css +8 -4
  14. package/src/components/PickerWheel/PickerWheel.module.css +1 -1
  15. package/src/components/Popover/Popover.module.css +11 -3
  16. package/src/components/Prose/Prose.module.css +4 -2
  17. package/src/components/RulerScrubber/RulerScrubber.module.css +1 -1
  18. package/src/components/SegmentedControl/SegmentedControl.module.css +3 -3
  19. package/src/components/Sheet/Sheet.module.css +10 -3
  20. package/src/components/Skeleton/Skeleton.module.css +1 -1
  21. package/src/components/SplitFlap/SplitFlap.module.css +1 -1
  22. package/src/components/Switch/Switch.module.css +1 -1
  23. package/src/components/Tabs/Tabs.module.css +34 -33
  24. package/src/components/Tabs/Tabs.tsx +64 -21
  25. package/src/components/ThemeToggle/ThemeToggle.module.css +6 -15
  26. package/src/components/ThemeToggle/ThemeToggle.tsx +108 -9
  27. package/src/components/Toast/Toast.module.css +6 -3
  28. package/src/components/Toast/Toast.tsx +2 -2
  29. package/src/components/Toggle/Toggle.module.css +1 -1
  30. package/src/internal/liquidMatter.ts +42 -11
  31. package/src/internal/motion.ts +1 -1
  32. package/src/internal/themeReveal.ts +63 -0
  33. package/src/tokens.css +53 -15
@@ -1,4 +1,7 @@
1
1
  .root {
2
+ /* The panel's surface; the chosen tab rises out of it in the same colour. */
3
+ --tabs-panel: var(--gooee-color-surface-sunken);
4
+ --tabs-r: var(--gooee-radius-md);
2
5
  display: flex;
3
6
  flex-direction: column;
4
7
  min-width: 0;
@@ -7,7 +10,9 @@
7
10
  .listScroll {
8
11
  overflow-x: auto;
9
12
  scrollbar-width: none;
10
- border-bottom: var(--gooee-line) solid var(--gooee-color-border);
13
+ /* Room under the row for the rise to reach into the panel's corner; the panel overlaps it. */
14
+ padding-bottom: var(--tabs-r);
15
+ margin-bottom: calc(var(--tabs-r) * -1);
11
16
  }
12
17
 
13
18
  .listScroll::-webkit-scrollbar { display: none; }
@@ -26,7 +31,8 @@
26
31
  min-height: var(--gooee-hit-min);
27
32
  padding: 0 var(--gooee-space-4);
28
33
  border: 0;
29
- border-radius: var(--gooee-radius-sm) var(--gooee-radius-sm) 0 0;
34
+ z-index: 1;
35
+ border-radius: var(--tabs-r) var(--tabs-r) 0 0;
30
36
  background: transparent;
31
37
  color: var(--gooee-color-fg-muted);
32
38
  font: inherit;
@@ -34,7 +40,7 @@
34
40
  font-weight: var(--gooee-weight-medium);
35
41
  white-space: nowrap;
36
42
  cursor: pointer;
37
- transition: color var(--gooee-motion-base) var(--gooee-ease-out), background-color var(--gooee-motion-fast) var(--gooee-ease-out);
43
+ transition: color var(--gooee-motion-base) var(--gooee-ease-morph);
38
44
  }
39
45
 
40
46
  /* Narrow screens: a little less room around each tab, so a short row fits instead of scrolling. */
@@ -43,7 +49,7 @@
43
49
  }
44
50
 
45
51
  @media (hover: hover) {
46
- .tab:hover:not(:disabled) { color: var(--gooee-color-fg); background: var(--gooee-color-surface-hover); }
52
+ .tab:hover:not(:disabled) { color: var(--gooee-color-fg); }
47
53
  }
48
54
  .tab[aria-selected="true"] { color: var(--gooee-color-fg); }
49
55
  .tab:disabled { opacity: var(--gooee-disabled-opacity); cursor: not-allowed; }
@@ -53,49 +59,44 @@
53
59
  box-shadow: inset 0 0 0 var(--gooee-line-focus) var(--gooee-color-fg);
54
60
  }
55
61
 
56
- .indicator {
62
+ /* The rise: the panel's surface grown up behind the chosen tab, with rounded top corners and soft inside
63
+ corners where it meets the panel. */
64
+ .rise {
57
65
  position: absolute;
58
- left: 0;
59
- bottom: 0;
60
- height: var(--gooee-indicator);
61
- border-radius: var(--gooee-radius-full);
62
- background: var(--gooee-color-accent);
66
+ top: 0;
67
+ /* Down past the row by one corner: wherever the rise is, it fills the panel's round corner under it,
68
+ so the corner squares and rounds with the rise itself, never on its own. */
69
+ bottom: calc(var(--tabs-r) * -1);
70
+ border-radius: var(--tabs-r) var(--tabs-r) 0 0;
71
+ background: var(--tabs-panel);
63
72
  pointer-events: none;
64
73
  }
65
74
 
66
- .indicator[data-ready] {
67
- transition:
68
- transform var(--gooee-motion-slow) var(--gooee-ease-out),
69
- width var(--gooee-motion-slow) var(--gooee-ease-out);
70
- }
71
-
72
- /* A new tab flows the underline instead (internal/liquidMatter.ts useFlow): .liquid draws it meanwhile. */
73
- .indicator[data-flowing] {
74
- opacity: 0;
75
- transition: none;
76
- }
77
-
78
- .liquid {
75
+ .rise::before,
76
+ .rise::after {
77
+ content: "";
79
78
  position: absolute;
80
- left: 0;
81
- top: 0;
82
- width: 100%;
83
- height: 100%;
84
- overflow: visible;
85
- pointer-events: none;
79
+ bottom: var(--tabs-r);
86
80
  }
81
+ /* The inside corners: their size is set each frame (Tabs.tsx) from how far the rise is from each end. */
82
+ .rise::before { --s: var(--tabs-in-start, var(--tabs-r)); right: 100%; width: var(--s); height: var(--s); background: radial-gradient(circle at 0 0, transparent var(--s), var(--tabs-panel) calc(var(--s) + 0.5px)); }
83
+ .rise::after { --s: var(--tabs-in-end, var(--tabs-r)); left: 100%; width: var(--s); height: var(--s); background: radial-gradient(circle at 100% 0, transparent var(--s), var(--tabs-panel) calc(var(--s) + 0.5px)); }
84
+ /* Past either end of the row an inside corner is clipped by the row itself, so it never shows outside the panel. */
87
85
 
88
86
  .panel {
89
- padding-top: var(--gooee-space-6);
90
- border-radius: var(--gooee-radius-sm);
91
- animation: panelIn var(--gooee-motion-slow) var(--gooee-ease-out);
87
+ padding: var(--gooee-space-6);
88
+ border-radius: var(--tabs-corner-start, var(--tabs-r)) var(--tabs-corner-end, var(--tabs-r)) var(--tabs-r) var(--tabs-r);
89
+ background: var(--tabs-panel);
92
90
  }
93
91
 
92
+ /* Only the words fade in, in place. The panel never moves or fades, so it stays one shape with the rise. */
93
+ .panel > * { animation: panelIn var(--gooee-motion-slow) var(--gooee-ease-morph); }
94
+
94
95
  .panel:focus-visible {
95
96
  outline: none;
96
97
  box-shadow: var(--gooee-focus-ring);
97
98
  }
98
99
 
99
100
  @keyframes panelIn {
100
- from { opacity: 0; transform: translateY(var(--gooee-shift-md)); }
101
+ from { opacity: 0; }
101
102
  }
@@ -10,9 +10,9 @@ import {
10
10
  type KeyboardEvent,
11
11
  type ReactNode,
12
12
  } from 'react'
13
- import { prefersReducedMotion } from '../../internal/motion'
13
+ import { morphCurve, motionMs, prefersReducedMotion } from '../../internal/motion'
14
+ import { bezier } from '../../internal/feel'
14
15
  import { cx } from '../../internal/cx'
15
- import { useFlow } from '../../internal/liquidMatter'
16
16
  import { useControllable } from '../../internal/useControllable'
17
17
  import styles from './Tabs.module.css'
18
18
 
@@ -44,7 +44,9 @@ export function Tabs({ value: valueProp, defaultValue, onValueChange, className,
44
44
  const [value, set] = useControllable(valueProp, defaultValue, onValueChange)
45
45
  return (
46
46
  <TabsCtx.Provider value={{ value, set, baseId }}>
47
- <div className={cx(styles.root, className)}>{children}</div>
47
+ <div className={cx(styles.root, className)} data-gooee-tabs="">
48
+ {children}
49
+ </div>
48
50
  </TabsCtx.Provider>
49
51
  )
50
52
  }
@@ -61,15 +63,14 @@ export type TabListProps = {
61
63
  export function TabList({ label, className, children }: TabListProps) {
62
64
  const { value } = useTabs()
63
65
  const listRef = useRef<HTMLDivElement>(null)
64
- const [bar, setBar] = useState<{ x: number; w: number } | null>(null)
65
- const [ready, setReady] = useState(false)
66
+ const [bar, setBar] = useState<{ x: number; w: number; room: number; value: string } | null>(null)
66
67
 
67
68
  useLayoutEffect(() => {
68
69
  const list = listRef.current
69
70
  if (!list) return
70
71
  const measure = () => {
71
72
  const el = list.querySelector<HTMLElement>('[role="tab"][aria-selected="true"]')
72
- if (el) setBar({ x: el.offsetLeft, w: el.offsetWidth })
73
+ if (el) setBar({ x: el.offsetLeft, w: el.offsetWidth, room: list.offsetWidth, value })
73
74
  }
74
75
  measure()
75
76
  const ro = new ResizeObserver(measure)
@@ -85,16 +86,64 @@ export function TabList({ label, className, children }: TabListProps) {
85
86
  for (const t of tabs) t.tabIndex = t === stop ? 0 : -1
86
87
  })
87
88
 
89
+ // The rise moves by script, so each frame knows how far each edge is from the row's ends. Near an end
90
+ // the panel's corner and the rise's inside corner shrink together; at the end the rise and the panel
91
+ // share one straight edge.
92
+ const riseRef = useRef<HTMLSpanElement>(null)
93
+ const drawn = useRef<{ l: number; r: number; value: string } | null>(null)
94
+ const raf = useRef(0)
95
+ // Where a running move is heading. A re-measure of the same tab (the size watcher reports once more
96
+ // after every change) only updates this; it never restarts or cuts the move short.
97
+ const aim = useRef<{ l: number; r: number; value: string } | null>(null)
88
98
  useLayoutEffect(() => {
89
- if (bar && !ready) {
90
- const r = requestAnimationFrame(() => setReady(true))
91
- return () => cancelAnimationFrame(r)
99
+ const rise = riseRef.current
100
+ const root = listRef.current?.closest<HTMLElement>('[data-gooee-tabs]')
101
+ if (!bar || !rise || !root) return
102
+ const R = parseFloat(getComputedStyle(root).getPropertyValue('--tabs-r')) || 0
103
+ // Within two corners of an end, the panel's corner and the inside corner each take half the room, so
104
+ // they meet as one even S; at the end both are gone.
105
+ const curve = (gap: number) => `${Math.max(0, Math.min(R, gap / 2))}px`
106
+ const draw = (l: number, r: number) => {
107
+ rise.style.left = `${l}px`
108
+ rise.style.right = `${r}px`
109
+ rise.style.setProperty('--tabs-in-start', curve(l))
110
+ rise.style.setProperty('--tabs-in-end', curve(r))
111
+ root.style.setProperty('--tabs-corner-start', curve(l))
112
+ root.style.setProperty('--tabs-corner-end', curve(r))
113
+ drawn.current = { l, r, value: aim.current?.value ?? bar.value }
92
114
  }
93
- }, [bar, ready])
94
-
95
- // The underline flows to the new tab: it runs ahead, splits, and what is left drains after it.
96
- const barRef = useRef<HTMLSpanElement>(null)
97
- useFlow(listRef, barRef, bar, value, ready, styles.liquid, true)
115
+ const to = { l: bar.x, r: bar.room - bar.x - bar.w }
116
+ if (aim.current?.value === bar.value) {
117
+ aim.current = { ...to, value: bar.value }
118
+ return
119
+ }
120
+ const from = drawn.current
121
+ cancelAnimationFrame(raf.current)
122
+ aim.current = null
123
+ const length = motionMs('morph-out')
124
+ // Only a new choice moves; a resize or the first paint just puts it in place.
125
+ if (!from || from.value === bar.value || !length || prefersReducedMotion()) return draw(to.l, to.r)
126
+ // The edge on the way leads; the other follows a beat later, so the rise stretches, then settles.
127
+ const lag = motionMs('instant')
128
+ const ease = bezier(morphCurve())
129
+ const toEnd = to.l > from.l
130
+ const t0 = performance.now()
131
+ aim.current = { ...to, value: bar.value }
132
+ const step = (now: number) => {
133
+ const at = aim.current
134
+ if (!at) return
135
+ const t = now - t0
136
+ const lead = ease(Math.min(1, t / length))
137
+ const trail = ease(Math.min(1, Math.max(0, (t - lag) / length)))
138
+ const ul = toEnd ? trail : lead
139
+ const ur = toEnd ? lead : trail
140
+ draw(from.l + (at.l - from.l) * ul, from.r + (at.r - from.r) * ur)
141
+ if (t < length + lag) raf.current = requestAnimationFrame(step)
142
+ else aim.current = null
143
+ }
144
+ raf.current = requestAnimationFrame(step)
145
+ }, [bar])
146
+ useLayoutEffect(() => () => cancelAnimationFrame(raf.current), [])
98
147
 
99
148
  // Automatic activation, per the WAI-ARIA tabs pattern
100
149
  const onKeyDown = (e: KeyboardEvent) => {
@@ -117,13 +166,7 @@ export function TabList({ label, className, children }: TabListProps) {
117
166
  <div ref={listRef} role="tablist" aria-label={label} className={styles.list} onKeyDown={onKeyDown}>
118
167
  {children}
119
168
  {bar && (
120
- <span
121
- ref={barRef}
122
- className={styles.indicator}
123
- data-ready={ready || undefined}
124
- style={{ transform: `translateX(${bar.x}px)`, width: bar.w }}
125
- aria-hidden="true"
126
- />
169
+ <span ref={riseRef} className={styles.rise} aria-hidden="true" />
127
170
  )}
128
171
  </div>
129
172
  </div>
@@ -1,21 +1,12 @@
1
- /* The sun and the moon share one spot: the one for the other theme turns away and shrinks as the
2
- current one turns in. */
1
+ /* One shape: the sun's disc grows and a bite slides over it into the moon's crescent, with the rays
2
+ drawing back in first (ThemeToggle.tsx draws every frame). */
3
3
  .icon {
4
- display: grid;
5
4
  width: 1em;
6
5
  height: 1em;
6
+ overflow: visible;
7
7
  }
8
8
 
9
- .sun,
10
- .moon {
11
- grid-area: 1 / 1;
12
- width: 100%;
13
- height: 100%;
14
- transition:
15
- transform var(--gooee-motion-slower) var(--gooee-ease-spring),
16
- opacity var(--gooee-motion-base) var(--gooee-ease-out);
9
+ .rays {
10
+ transform-box: view-box;
11
+ transform-origin: 50% 50%;
17
12
  }
18
-
19
- /* Shows the theme the button switches to: the moon in light, the sun in dark. */
20
- .icon:not([data-theme-shown="dark"]) .sun { opacity: 0; transform: rotate(90deg) scale(0.4); }
21
- .icon[data-theme-shown="dark"] .moon { opacity: 0; transform: rotate(-90deg) scale(0.4); }
@@ -1,7 +1,9 @@
1
1
  'use client'
2
2
 
3
- import { useEffect, useState } from 'react'
4
- import { MoonIcon, SunIcon } from '../../internal/icons'
3
+ import { useEffect, useLayoutEffect, useRef, useState, type MouseEvent } from 'react'
4
+ import { bezier } from '../../internal/feel'
5
+ import { morphCurve, motionMs, prefersReducedMotion } from '../../internal/motion'
6
+ import { themeReveal } from '../../internal/themeReveal'
5
7
  import { IconButton } from '../IconButton'
6
8
  import styles from './ThemeToggle.module.css'
7
9
 
@@ -14,6 +16,8 @@ export type ThemeToggleProps = {
14
16
  onThemeChange?: (theme: Theme) => void
15
17
  /** Where the choice is remembered when the toggle runs the page. Match it in themeScript. */
16
18
  storageKey?: string
19
+ /** The new theme grows from the button in a circle over the screen. Turn it off for an instant change. */
20
+ reveal?: boolean
17
21
  /** The button's size, the same as IconButton. */
18
22
  size?: 'sm' | 'md' | 'lg'
19
23
  /** Extra class for the button. */
@@ -24,10 +28,57 @@ export type ThemeToggleProps = {
24
28
  export const themeScript = (storageKey = 'gooee-theme') =>
25
29
  `try{var t=localStorage.getItem(${JSON.stringify(storageKey)});if(t!=='light'&&t!=='dark')t=matchMedia('(prefers-color-scheme: dark)').matches?'dark':'light';document.documentElement.dataset.theme=t}catch(e){}`
26
30
 
31
+ // Sun to moon the way the real moon works: a round disc with a shadow passing over it. The disc stays
32
+ // round and grows from the sun's size to the moon's; a second circle, the bite, slides in from the top
33
+ // right and carves the crescent. The outline is drawn exactly each frame as "disc minus bite", so every
34
+ // frame is a true shape. The rays draw back into the disc and fade first, before it grows into them.
35
+ const C = 12
36
+ const lerp = (a: number, b: number, t: number) => a + (b - a) * t
37
+ const part = (t: number, a: number, b: number) => Math.min(1, Math.max(0, (t - a) / (b - a)))
38
+ const f = (n: number) => Math.round(n * 100) / 100
39
+ const BITE = 7
40
+ const TOWARD = -Math.PI / 4
41
+ function bodyAt(t: number) {
42
+ const r = lerp(4, 8, part(t, 0.2, 1))
43
+ // The bite starts clear of the disc and ends 5.6 from its centre.
44
+ const d = lerp(r + BITE + 1, 5.6, part(t, 0.15, 1))
45
+ if (d >= r + BITE) return `M${C - r} ${C}A${f(r)} ${f(r)} 0 1 1 ${C + r} ${C}A${f(r)} ${f(r)} 0 1 1 ${C - r} ${C}Z`
46
+ const half = Math.acos((r * r + d * d - BITE * BITE) / (2 * r * d))
47
+ const at = (o: [number, number], rad: number, ang: number): [number, number] => [o[0] + rad * Math.cos(ang), o[1] + rad * Math.sin(ang)]
48
+ const centre: [number, number] = [C, C]
49
+ const bite = at(centre, d, TOWARD)
50
+ const A = at(centre, r, TOWARD + half)
51
+ const B = at(centre, r, TOWARD - half)
52
+ // The disc's edge from A the long way round to B, then the bite's edge back to A through the disc.
53
+ const outer = 2 * Math.PI - 2 * half
54
+ // Of the two ways round the bite from B to A, the one whose middle lies inside the disc.
55
+ const angA = Math.atan2(A[1] - bite[1], A[0] - bite[0])
56
+ const angB = Math.atan2(B[1] - bite[1], B[0] - bite[0])
57
+ const up = (((angA - angB) % (2 * Math.PI)) + 2 * Math.PI) % (2 * Math.PI)
58
+ const mid = at(bite, BITE, angB + up / 2)
59
+ const sweep = Math.hypot(mid[0] - C, mid[1] - C) < r ? 1 : 0
60
+ const inner = sweep ? up : 2 * Math.PI - up
61
+ return `M${f(A[0])} ${f(A[1])}A${f(r)} ${f(r)} 0 ${outer > Math.PI ? 1 : 0} 1 ${f(B[0])} ${f(B[1])}A${BITE} ${BITE} 0 ${inner > Math.PI ? 1 : 0} ${sweep} ${f(A[0])} ${f(A[1])}Z`
62
+ }
63
+ const RAYS = Array.from({ length: 8 }, (_, i) => {
64
+ const a = (i * Math.PI) / 4
65
+ return `M${f(C + 7 * Math.cos(a))} ${f(C + 7 * Math.sin(a))}L${f(C + 9.5 * Math.cos(a))} ${f(C + 9.5 * Math.sin(a))}`
66
+ }).join('')
67
+ // The rays draw in toward the disc, turn a little and fade, all within the first 40%.
68
+ const raysAt = (t: number) => {
69
+ const k = part(t, 0, 0.4)
70
+ return { transform: `rotate(${f(-30 * k)}deg) scale(${f(1 - 0.45 * k)})`, opacity: String(f(1 - k)) }
71
+ }
72
+ function draw(body: SVGPathElement, t: number) {
73
+ body.setAttribute('d', bodyAt(t))
74
+ const rays = body.nextElementSibling as SVGPathElement | null
75
+ if (rays) Object.assign(rays.style, raysAt(t))
76
+ }
77
+
27
78
  const pageTheme = (): Theme => (document.documentElement.dataset.theme === 'dark' ? 'dark' : 'light')
28
79
 
29
- // One button that flips between the light and dark theme. The sun turns into the moon and back.
30
- export function ThemeToggle({ theme: themeProp, onThemeChange, storageKey = 'gooee-theme', size = 'sm', className }: ThemeToggleProps) {
80
+ // One button that flips between the light and dark theme. The sun morphs into the moon and back.
81
+ export function ThemeToggle({ theme: themeProp, onThemeChange, storageKey = 'gooee-theme', reveal = true, size = 'sm', className }: ThemeToggleProps) {
31
82
  const controlled = themeProp !== undefined
32
83
  const [own, setOwn] = useState<Theme>('light')
33
84
  const theme = controlled ? themeProp : own
@@ -38,7 +89,55 @@ export function ThemeToggle({ theme: themeProp, onThemeChange, storageKey = 'goo
38
89
  }, [controlled])
39
90
 
40
91
  const next: Theme = theme === 'dark' ? 'light' : 'dark'
41
- const flip = () => {
92
+ // Shows the theme the button switches to: the moon in light, the sun in dark. The body morphs on the
93
+ // morph curve, in the reveal's time, so the icon and the circle end together; the rays are drawn on
94
+ // the same frames.
95
+ const body = useRef<SVGPathElement>(null)
96
+ const shown = useRef(theme === 'dark' ? 0 : 1)
97
+ const aim = useRef(shown.current)
98
+ const raf = useRef(0)
99
+ const morphTo = (to: number) => {
100
+ const el = body.current
101
+ aim.current = to
102
+ cancelAnimationFrame(raf.current)
103
+ if (!el) return
104
+ const from = shown.current
105
+ const length = motionMs('reveal')
106
+ if (from === to || !length || prefersReducedMotion()) {
107
+ shown.current = to
108
+ draw(el, to)
109
+ return
110
+ }
111
+ const ease = bezier(morphCurve())
112
+ const t0 = performance.now()
113
+ const step = (now: number) => {
114
+ const u = Math.min(1, (now - t0) / length)
115
+ shown.current = from + (to - from) * ease(u)
116
+ draw(el, shown.current)
117
+ if (u < 1) raf.current = requestAnimationFrame(step)
118
+ }
119
+ raf.current = requestAnimationFrame(step)
120
+ }
121
+ // A theme set from outside (or the first paint): morph to it, unless a press already started that morph.
122
+ useLayoutEffect(() => {
123
+ const to = theme === 'dark' ? 0 : 1
124
+ if (aim.current !== to) morphTo(to)
125
+ // eslint-disable-next-line react-hooks/exhaustive-deps
126
+ }, [theme])
127
+ useLayoutEffect(() => () => cancelAnimationFrame(raf.current), [])
128
+ // The icon answers the press at once; the theme change, and its circle, start two frames later, so
129
+ // the first motion is on screen before the page is held still to be photographed.
130
+ const flip = (e: MouseEvent<HTMLButtonElement>) => {
131
+ const origin = e.currentTarget
132
+ morphTo(next === 'dark' ? 0 : 1)
133
+ requestAnimationFrame(() =>
134
+ requestAnimationFrame(() => {
135
+ if (reveal) themeReveal(origin, apply)
136
+ else apply()
137
+ }),
138
+ )
139
+ }
140
+ const apply = () => {
42
141
  if (!controlled) {
43
142
  document.documentElement.dataset.theme = next
44
143
  try {
@@ -59,10 +158,10 @@ export function ThemeToggle({ theme: themeProp, onThemeChange, storageKey = 'goo
59
158
  className={className}
60
159
  onClick={flip}
61
160
  icon={
62
- <span className={styles.icon} data-theme-shown={theme}>
63
- <SunIcon className={styles.sun} />
64
- <MoonIcon className={styles.moon} />
65
- </span>
161
+ <svg className={styles.icon} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={1.75} strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
162
+ <path ref={body} d={bodyAt(shown.current)} />
163
+ <path className={styles.rays} d={RAYS} style={raysAt(shown.current)} />
164
+ </svg>
66
165
  }
67
166
  />
68
167
  )
@@ -148,12 +148,12 @@
148
148
  .action:focus-visible { outline: none; box-shadow: var(--gooee-focus-ring); }
149
149
 
150
150
  .close {
151
+ position: relative;
151
152
  display: grid;
152
153
  place-items: center;
153
154
  flex: none;
154
- width: var(--gooee-hit-min);
155
- height: var(--gooee-hit-min);
156
- margin-block: calc(var(--gooee-space-4) * -1);
155
+ width: var(--gooee-control-h-sm);
156
+ height: var(--gooee-control-h-sm);
157
157
  padding: 0;
158
158
  border: 0;
159
159
  border-radius: var(--gooee-radius-full);
@@ -164,6 +164,9 @@
164
164
  transition: background-color var(--gooee-motion-fast) var(--gooee-ease-out);
165
165
  }
166
166
 
167
+ /* Looks 32px, keeps a 44px touch area. */
168
+ .close::after { content: ""; position: absolute; inset: calc((var(--gooee-control-h-sm) - var(--gooee-hit-min)) / 2); border-radius: inherit; }
169
+
167
170
  @media (hover: hover) {
168
171
  .close:hover { background: var(--gooee-color-surface-hover); color: var(--gooee-color-fg); }
169
172
  }
@@ -13,7 +13,7 @@ import {
13
13
  type ReactNode,
14
14
  } from 'react'
15
15
  import { CheckCircleIcon, ErrorIcon, InfoIcon, XIcon } from '../../internal/icons'
16
- import { frames, layer, morphEase, motionFor, shadowOf } from '../../internal/liquidMatter'
16
+ import { castShadow, frames, layer, morphEase, motionFor, shadowOf } from '../../internal/liquidMatter'
17
17
  import { BEND, body, budScene, exitToward, loopsPath, pincher, sdBox, trace, type Box, type Pt } from '../../internal/liquidPath'
18
18
  import { motionMs } from '../../internal/motion'
19
19
  import { release, speedTracker } from '../../internal/fling'
@@ -234,7 +234,7 @@ function bud(toast: HTMLElement, origin: ToastOptions['origin'], way: 'in' | 'ou
234
234
  path.style.fill = look.backgroundColor
235
235
  path.style.stroke = look.borderTopColor
236
236
  path.style.strokeWidth = `${line}px`
237
- svg.style.filter = shadowOf(toast).filter
237
+ castShadow(svg, shadowOf(toast).shadows)
238
238
  const inset = line / 2
239
239
  const T2: Box = { cx: T.cx, cy: T.cy, hw: T.hw - inset, hh: T.hh - inset, r: Math.max(0, T.r - inset) }
240
240
  // The origin keeps its own look: the drawing is cut out where it is.
@@ -14,7 +14,7 @@
14
14
  color: var(--gooee-color-fg);
15
15
  font-size: var(--gooee-text-md);
16
16
  font-weight: var(--gooee-weight-medium);
17
- line-height: 1;
17
+ line-height: var(--gooee-leading-none);
18
18
  white-space: nowrap;
19
19
  cursor: pointer;
20
20
  user-select: none;
@@ -13,21 +13,52 @@ export const morphEase = () => bezier(morphCurve())
13
13
  /** A duration token in ms, or 0 when motion is reduced. */
14
14
  export const motionFor = (token: MotionToken) => (prefersReducedMotion() ? 0 : motionMs(token))
15
15
 
16
- /**
17
- * An element's outer box shadows as drop-shadow filters, so a drawn shape casts the same shadow. A
18
- * shadow that is only a spread (a 1px ring) comes back as `ring`, to draw as a stroke.
19
- */
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. */
20
19
  export function shadowOf(el: Element) {
21
- const filters: string[] = []
20
+ const shadows: Shadow[] = []
22
21
  let ring: { colour: string; width: number } | null = null
23
22
  for (const part of getComputedStyle(el).boxShadow.split(/,(?![^(]*\))/)) {
24
23
  if (part.trim() === 'none' || part.includes('inset')) continue
25
24
  const colour = part.match(/rgba?\([^)]*\)|#[\da-f]+/i)?.[0] ?? 'currentColor'
26
25
  const [x = 0, y = 0, blur = 0, spread = 0] = (part.replace(colour, '').match(/-?[\d.]+px/g) ?? []).map(parseFloat)
27
26
  if (spread > 0 && !x && !y && !blur) ring = { colour, width: spread }
28
- else filters.push(`drop-shadow(${x}px ${y}px ${blur}px ${colour})`)
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
29
45
  }
30
- return { filter: filters.join(' ') || 'none', ring }
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)
31
62
  }
32
63
 
33
64
  /** An SVG in `host`, before `before`, with `count` paths. It is marked data-gooee-liquid. */
@@ -105,7 +136,7 @@ export function useFlow(
105
136
  end()
106
137
  return
107
138
  }
108
- const ms = motionFor('slow')
139
+ const ms = motionFor('morph-out')
109
140
  if (!ms) {
110
141
  end()
111
142
  return
@@ -122,21 +153,21 @@ export function useFlow(
122
153
  else {
123
154
  const { svg, paths } = layer(root, cls, m.nextSibling)
124
155
  const look = getComputedStyle(m)
125
- const { filter, ring } = shadowOf(m)
156
+ const { shadows, ring } = shadowOf(m)
126
157
  paths[0].style.fill = look.backgroundColor
127
158
  if (ring && !line) {
128
159
  paths[0].style.stroke = ring.colour
129
160
  paths[0].style.strokeWidth = `${ring.width * 2}px`
130
161
  paths[0].style.paintOrder = 'stroke'
131
162
  }
132
- svg.style.filter = filter
163
+ castShadow(svg, shadows)
133
164
  f = { front: from.front, rest: from.rest, stop: () => {}, svg, pin: pincher(e, motionFor('fast')) }
134
165
  run.current = f
135
166
  m.dataset.flowing = ''
136
167
  root.dataset.flowing = ''
137
168
  }
138
169
  const flow = f
139
- const path = flow.svg.firstElementChild as SVGPathElement
170
+ const path = flow.svg.querySelector('path') as SVGPathElement
140
171
  const lift = Math.max(BEND + 0.5, hh / 2)
141
172
  const settle = Math.max(BEND + 0.5, hh / 3)
142
173
  const start = { front: from.front, rest: from.rest }
@@ -1,6 +1,6 @@
1
1
  import { MORPH, type Curve } from './feel'
2
2
 
3
- export type MotionToken = 'instant' | 'fast' | 'base' | 'slow' | 'slower' | 'liquid' | 'morph' | 'morph-out' | 'fling' | 'delay-tooltip'
3
+ export type MotionToken = 'instant' | 'fast' | 'base' | 'slow' | 'slower' | 'liquid' | 'morph' | 'morph-out' | 'reveal' | 'fling' | 'delay-tooltip'
4
4
 
5
5
  // Reads a duration token at run time, so reduced motion (0ms) and Retime's speed are honoured by JS
6
6
  // timers too.
@@ -0,0 +1,63 @@
1
+ import { flushSync } from 'react-dom'
2
+ import { easing, motionMs, prefersReducedMotion } from './motion'
3
+
4
+ // The new theme grows from the spot you pressed: the page is snapshot as it is, and the new page opens
5
+ // over it in a circle from the button's centre to the farthest corner, at an even pace. The old snapshot
6
+ // stays still under it, and no element plays its own colour change meanwhile, so nothing flips piece by
7
+ // piece. A second press finishes the running one first. Without View Transitions the page fades in once;
8
+ // with reduced motion it changes at once.
9
+
10
+ let running: ViewTransition | null = null
11
+
12
+ // The radius whose circle covers `share` of the screen, by halving, counted on a coarse grid.
13
+ function radiusFor(share: number, x: number, y: number, reach: number) {
14
+ if (share >= 1) return reach
15
+ const cols = 48, rows = 32
16
+ const covered = (r: number) => {
17
+ let n = 0
18
+ for (let j = 0; j < rows; j++) for (let i = 0; i < cols; i++) if (Math.hypot(((i + 0.5) * innerWidth) / cols - x, ((j + 0.5) * innerHeight) / rows - y) <= r) n++
19
+ return n / (cols * rows)
20
+ }
21
+ let lo = 0, hi = reach
22
+ for (let k = 0; k < 18; k++) {
23
+ const m = (lo + hi) / 2
24
+ if (covered(m) < share) lo = m
25
+ else hi = m
26
+ }
27
+ return hi
28
+ }
29
+
30
+ export function themeReveal(origin: Element | null, apply: () => void) {
31
+ const root = document.documentElement
32
+ const ms = motionMs('reveal')
33
+ if (prefersReducedMotion() || !ms) return flushSync(apply)
34
+ running?.skipTransition()
35
+ root.dataset.gooeeThemeSwitch = ''
36
+ const done = () => delete root.dataset.gooeeThemeSwitch
37
+ if (typeof document.startViewTransition !== 'function') {
38
+ flushSync(apply)
39
+ document.body.animate([{ opacity: 0.4 }, { opacity: 1 }], { duration: ms * 0.6, easing: easing('morph') }).finished.then(done, done)
40
+ return
41
+ }
42
+ const r = origin?.getBoundingClientRect()
43
+ const x = r ? r.left + r.width / 2 : innerWidth / 2
44
+ const y = r ? r.top + r.height / 2 : 0
45
+ const reach = Math.hypot(Math.max(x, innerWidth - x), Math.max(y, innerHeight - y))
46
+ const vt = document.startViewTransition(() => flushSync(apply))
47
+ running = vt
48
+ vt.ready.then(
49
+ // The share of the screen covered grows at an even, calm pace (ease out): a circle's area grows with
50
+ // the radius squared, so each step's radius is solved for its share; linear in between.
51
+ () =>
52
+ root.animate(
53
+ { clipPath: Array.from({ length: 21 }, (_, i) => `circle(${radiusFor(1 - (1 - i / 20) ** 2, x, y, reach)}px at ${x}px ${y}px)`) },
54
+ { duration: ms, easing: 'linear', pseudoElement: '::view-transition-new(root)' },
55
+ ),
56
+ () => {},
57
+ )
58
+ vt.finished.finally(() => {
59
+ if (running !== vt) return
60
+ running = null
61
+ done()
62
+ })
63
+ }