gooee 0.42.0 → 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 (28) hide show
  1. package/package.json +1 -1
  2. package/src/components/AnimatedNumber/AnimatedNumber.module.css +3 -3
  3. package/src/components/Badge/Badge.module.css +1 -1
  4. package/src/components/Button/Button.module.css +4 -4
  5. package/src/components/Dial/Dial.module.css +2 -2
  6. package/src/components/Dialog/Dialog.module.css +10 -4
  7. package/src/components/HoldToConfirm/HoldToConfirm.module.css +37 -52
  8. package/src/components/HoldToConfirm/HoldToConfirm.tsx +146 -60
  9. package/src/components/Kbd/Kbd.module.css +1 -1
  10. package/src/components/LivePill/LivePill.module.css +211 -31
  11. package/src/components/LivePill/LivePill.tsx +45 -14
  12. package/src/components/MorphButton/MorphButton.module.css +8 -4
  13. package/src/components/PickerWheel/PickerWheel.module.css +1 -1
  14. package/src/components/Popover/Popover.module.css +11 -3
  15. package/src/components/Prose/Prose.module.css +4 -2
  16. package/src/components/RulerScrubber/RulerScrubber.module.css +1 -1
  17. package/src/components/Sheet/Sheet.module.css +10 -3
  18. package/src/components/Skeleton/Skeleton.module.css +1 -1
  19. package/src/components/SplitFlap/SplitFlap.module.css +1 -1
  20. package/src/components/Tabs/Tabs.module.css +34 -33
  21. package/src/components/Tabs/Tabs.tsx +64 -21
  22. package/src/components/ThemeToggle/ThemeToggle.module.css +6 -15
  23. package/src/components/ThemeToggle/ThemeToggle.tsx +108 -9
  24. package/src/components/Toast/Toast.module.css +6 -3
  25. package/src/components/Toggle/Toggle.module.css +1 -1
  26. package/src/internal/motion.ts +1 -1
  27. package/src/internal/themeReveal.ts +63 -0
  28. package/src/tokens.css +47 -13
@@ -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-morph-out) var(--gooee-ease-out),
69
- width var(--gooee-motion-morph-out) 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
  }
@@ -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;
@@ -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
+ }
package/src/tokens.css CHANGED
@@ -62,20 +62,30 @@
62
62
  /* Type */
63
63
  --gooee-font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
64
64
  --gooee-font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
65
- --gooee-text-xs: 12px;
65
+ /* The golden scale: every second step is x1.618 (13, 21, 34, 55 run on Fibonacci). xs and lg are kept
66
+ as names: xs is the caption size, and a large control keeps body-size words and gains room instead. */
67
+ --gooee-text-xs: 13px;
66
68
  --gooee-text-sm: 13px;
67
- --gooee-text-md: 15px;
69
+ --gooee-text-md: 16px;
68
70
  /* Text typed into a field. On a touch screen it is at least 16px, or iPhone Safari zooms
69
71
  the page in when the field is tapped. */
70
72
  --gooee-text-input: var(--gooee-text-md);
71
- --gooee-text-lg: 17px;
72
- --gooee-text-xl: 20px;
73
+ --gooee-text-lg: 16px;
74
+ --gooee-text-xl: 21px;
73
75
  --gooee-text-2xl: 26px;
74
76
  --gooee-text-3xl: 34px;
75
- --gooee-text-4xl: 44px;
76
- --gooee-leading-tight: 1.2;
77
- --gooee-leading-snug: 1.4;
78
- --gooee-leading-normal: 1.6;
77
+ --gooee-text-4xl: 42px;
78
+ --gooee-text-5xl: 55px;
79
+ /* Line height as a ratio of the text size. The leading tokens below round it to a whole 4px line box
80
+ on each element that uses them, so text never sits between pixels. */
81
+ --gooee-leading-none-ratio: 1;
82
+ --gooee-leading-tight-ratio: 1.2;
83
+ --gooee-leading-snug-ratio: 1.4;
84
+ --gooee-leading-normal-ratio: 1.618;
85
+ --gooee-leading-none: var(--gooee-leading-none-ratio);
86
+ --gooee-leading-tight: var(--gooee-leading-tight-ratio);
87
+ --gooee-leading-snug: var(--gooee-leading-snug-ratio);
88
+ --gooee-leading-normal: var(--gooee-leading-normal-ratio);
79
89
  /* Prose: the longest line of reading text, about the most an eye follows back to the next line */
80
90
  --gooee-prose-w: 68ch;
81
91
  --gooee-weight-regular: 400;
@@ -102,18 +112,24 @@
102
112
 
103
113
  /* Sizes */
104
114
  --gooee-line: 1px;
105
- --gooee-line-thick: 1.5px;
115
+ /* Lines are 1px or 2px: whole pixels, never a half that blurs. */
116
+ --gooee-line-thick: 2px;
106
117
  --gooee-hit-min: 44px;
107
118
  --gooee-control-h-sm: 32px;
108
119
  --gooee-control-h-md: 40px;
109
120
  --gooee-control-h-lg: 48px;
121
+ /* A control's side padding is its height divided by the golden ratio, on the 4px grid: 20, 24, 28. */
122
+ --gooee-control-pad-sm: 20px;
123
+ --gooee-control-pad-md: 24px;
124
+ --gooee-control-pad-lg: 28px;
110
125
  --gooee-icon-sm: 14px;
111
126
  --gooee-icon-md: 16px;
112
127
  --gooee-icon-lg: 20px;
113
128
  --gooee-icon-xl: 28px;
114
- --gooee-panel-w-sm: 380px;
115
- --gooee-panel-w-md: 480px;
116
- --gooee-panel-w-lg: 640px;
129
+ /* Each panel width is the one before times the golden ratio, on the 4px grid. */
130
+ --gooee-panel-w-sm: 320px;
131
+ --gooee-panel-w-md: 520px;
132
+ --gooee-panel-w-lg: 840px;
117
133
  --gooee-menu-w: 220px;
118
134
  --gooee-tooltip-w: 260px;
119
135
  --gooee-toast-w: 360px;
@@ -156,7 +172,7 @@
156
172
  --gooee-radius-sm: 8px;
157
173
  --gooee-radius-md: 12px;
158
174
  --gooee-radius-panel: 20px;
159
- --gooee-radius-sheet: 28px;
175
+ --gooee-radius-sheet: 32px;
160
176
  --gooee-radius-control: 999px;
161
177
  --gooee-radius-full: 999px;
162
178
 
@@ -180,6 +196,9 @@
180
196
  back in 400ms, both on --gooee-ease-morph played forward, so a close starts moving at once */
181
197
  --gooee-motion-morph: calc(600ms * var(--gooee-motion-scale));
182
198
  --gooee-motion-morph-out: calc(400ms * var(--gooee-motion-scale));
199
+ /* A theme change: the new theme grows from the toggle in a circle over the whole screen. The morph's
200
+ close time: a whole-screen change reads best in about 200 to 400ms, and its icon ends with it. */
201
+ --gooee-motion-reveal: var(--gooee-motion-morph-out);
183
202
  /* Older names, kept so apps that use them still work. They are the morph now */
184
203
  --gooee-motion-pour: var(--gooee-motion-morph);
185
204
  --gooee-motion-liquid: var(--gooee-motion-morph);
@@ -336,6 +355,7 @@
336
355
  --gooee-motion-slower: 0ms;
337
356
  --gooee-motion-morph: 0ms;
338
357
  --gooee-motion-morph-out: 0ms;
358
+ --gooee-motion-reveal: 0ms;
339
359
  --gooee-motion-stagger: 0ms;
340
360
  --gooee-motion-shimmer: 0ms;
341
361
  --gooee-motion-spin: 1600ms;
@@ -729,3 +749,17 @@
729
749
  --gooee-code-comment: var(--gooee-color-fg-subtle);
730
750
  --gooee-code-gutter: var(--gooee-color-fg-subtle);
731
751
  }
752
+
753
+ /* Where round() works (every current browser), each leading is a whole line box on the 4px grid. */
754
+ @supports (line-height: round(nearest, 1em, 4px)) {
755
+ :root,
756
+ [data-theme] {
757
+ --gooee-leading-none: round(nearest, 1em, 4px);
758
+ --gooee-rise-room: round(up, 0.14em, 4px);
759
+ --gooee-flap-w: round(nearest, 0.92em, 4px);
760
+ --gooee-flap-h: round(nearest, 1.36em, 4px);
761
+ --gooee-leading-tight: round(nearest, calc(var(--gooee-leading-tight-ratio) * 1em), 4px);
762
+ --gooee-leading-snug: round(nearest, calc(var(--gooee-leading-snug-ratio) * 1em), 4px);
763
+ --gooee-leading-normal: round(nearest, calc(var(--gooee-leading-normal-ratio) * 1em), 4px);
764
+ }
765
+ }