@justanarthur/modo-ui-notch 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/README.md +11 -11
  2. package/blocks/activities/agenda/examples.mdx +21 -5
  3. package/blocks/activities/agenda/index.tsx +291 -182
  4. package/blocks/activities/clock/examples.mdx +73 -0
  5. package/blocks/activities/clock/index.tsx +619 -0
  6. package/blocks/activities/now-playing/examples.mdx +32 -13
  7. package/blocks/activities/now-playing/index.tsx +319 -126
  8. package/blocks/activities/weather/examples.mdx +115 -0
  9. package/blocks/activities/weather/index.tsx +634 -0
  10. package/blocks/app/expanded-island/examples.mdx +8 -7
  11. package/blocks/app/expanded-island/index.tsx +19 -3
  12. package/blocks/app/settings-window/examples.mdx +6 -2
  13. package/blocks/app/settings-window/index.tsx +25 -7
  14. package/blocks/system/clipboard/examples.mdx +83 -0
  15. package/blocks/system/clipboard/index.tsx +563 -0
  16. package/blocks/system/recent-files/examples.mdx +66 -0
  17. package/blocks/system/recent-files/index.tsx +542 -0
  18. package/blocks/system/system-stats/examples.mdx +38 -9
  19. package/blocks/system/system-stats/index.tsx +241 -107
  20. package/components/indicators/media-scrubber/examples.mdx +8 -0
  21. package/components/indicators/media-scrubber/index.tsx +37 -13
  22. package/components/island/island/examples.mdx +4 -4
  23. package/components/island/island/index.tsx +2 -2
  24. package/components/island/island-flash/examples.mdx +15 -18
  25. package/components/island/island-flash/index.tsx +4 -4
  26. package/components/island/island-tabs/examples.mdx +5 -5
  27. package/components/island/widget/examples.mdx +76 -0
  28. package/components/island/widget/index.tsx +431 -0
  29. package/dist/blocks/activities/agenda/index.d.ts +1 -1
  30. package/dist/blocks/activities/agenda/index.js +3 -3
  31. package/dist/blocks/activities/clock/index.d.ts +2 -0
  32. package/dist/blocks/activities/clock/index.js +25 -0
  33. package/dist/blocks/activities/now-playing/index.d.ts +3 -2
  34. package/dist/blocks/activities/now-playing/index.js +5 -3
  35. package/dist/blocks/activities/weather/index.d.ts +2 -0
  36. package/dist/blocks/activities/weather/index.js +21 -0
  37. package/dist/blocks/app/expanded-island/index.d.ts +1 -1
  38. package/dist/blocks/app/expanded-island/index.js +4 -3
  39. package/dist/blocks/app/settings-window/index.d.ts +1 -1
  40. package/dist/blocks/app/settings-window/index.js +1 -1
  41. package/dist/blocks/system/clipboard/index.d.ts +2 -0
  42. package/dist/blocks/system/clipboard/index.js +17 -0
  43. package/dist/blocks/system/recent-files/index.d.ts +2 -0
  44. package/dist/blocks/system/recent-files/index.js +19 -0
  45. package/dist/blocks/system/system-stats/index.d.ts +2 -2
  46. package/dist/blocks/system/system-stats/index.js +4 -1
  47. package/dist/components/indicators/media-scrubber/index.d.ts +1 -1
  48. package/dist/components/indicators/media-scrubber/index.js +1 -1
  49. package/dist/components/island/island/index.d.ts +1 -1
  50. package/dist/components/island/island/index.js +2 -2
  51. package/dist/components/island/island-flash/index.d.ts +1 -1
  52. package/dist/components/island/island-flash/index.js +1 -1
  53. package/dist/components/island/island-tabs/index.js +2 -2
  54. package/dist/components/island/widget/index.d.ts +2 -0
  55. package/dist/components/island/widget/index.js +30 -0
  56. package/dist/index.d.ts +15 -15
  57. package/dist/index.js +102 -58
  58. package/dist/lib/artwork.d.ts +2 -0
  59. package/dist/lib/artwork.js +8 -0
  60. package/dist/lib/geometry.js +1 -1
  61. package/dist/shared/chunk-2818esrq.d.ts +140 -0
  62. package/dist/shared/{chunk-yngkkxz2.d.ts → chunk-2m5dz8nf.d.ts} +4 -4
  63. package/dist/shared/chunk-3thgcfcq.d.ts +151 -0
  64. package/dist/shared/chunk-416tsgbc.d.ts +175 -0
  65. package/dist/shared/{chunk-zvh0d3qb.js → chunk-61t2dfte.js} +1 -1
  66. package/dist/shared/chunk-7fvnrtz4.d.ts +105 -0
  67. package/dist/shared/{chunk-hpsabfsd.d.ts → chunk-81fpptwp.d.ts} +1 -1
  68. package/dist/shared/chunk-9c7ewvkk.js +381 -0
  69. package/dist/shared/{chunk-mp1nx0ez.js → chunk-9m0xbg5v.js} +14 -3
  70. package/dist/shared/{chunk-wwjxs75m.js → chunk-9xtcv3sy.js} +26 -12
  71. package/dist/shared/chunk-bvtyjcce.d.ts +123 -0
  72. package/dist/shared/{chunk-s33y1pcq.js → chunk-cc9nwbtf.js} +20 -10
  73. package/dist/shared/chunk-da177e8r.d.ts +114 -0
  74. package/dist/shared/{chunk-6c1jbefs.d.ts → chunk-fexwzycv.d.ts} +3 -3
  75. package/dist/shared/chunk-gejenfap.d.ts +25 -0
  76. package/dist/shared/{chunk-rr5e0g15.d.ts → chunk-j755a1a5.d.ts} +7 -1
  77. package/dist/shared/chunk-j77cx8dp.js +498 -0
  78. package/dist/shared/chunk-mt0k6v8x.js +474 -0
  79. package/dist/shared/{chunk-78w7qwp0.js → chunk-ndf79pv5.js} +1 -1
  80. package/dist/shared/{chunk-9nhpg9t8.d.ts → chunk-pfhy5e4q.d.ts} +7 -1
  81. package/dist/shared/chunk-qdzemt2v.js +477 -0
  82. package/dist/shared/{chunk-rpfwv3pz.js → chunk-r471sknr.js} +1 -1
  83. package/dist/shared/chunk-s2jeqqan.js +243 -0
  84. package/dist/shared/chunk-t0hcxh89.d.ts +124 -0
  85. package/dist/shared/chunk-w5h6ay93.js +72 -0
  86. package/dist/shared/chunk-wkg17nxs.d.ts +101 -0
  87. package/dist/shared/chunk-x7f3g82r.js +285 -0
  88. package/dist/shared/chunk-xq5hc5gv.js +333 -0
  89. package/dist/shared/{chunk-sbnrhy5m.js → chunk-y0188bbn.js} +2 -2
  90. package/dist/shared/chunk-ym0xbses.js +518 -0
  91. package/dist/styles.css +97 -55
  92. package/index.ts +7 -6
  93. package/lib/artwork.ts +112 -0
  94. package/lib/geometry.ts +1 -1
  95. package/mock/activities.tsx +9 -32
  96. package/mock/artwork.tsx +13 -1
  97. package/mock/clipboard.tsx +79 -0
  98. package/mock/clock.tsx +77 -0
  99. package/mock/data.ts +30 -44
  100. package/mock/files.tsx +70 -0
  101. package/mock/island-content.tsx +43 -118
  102. package/mock/screen.tsx +76 -0
  103. package/mock/settings.tsx +370 -91
  104. package/mock/system.ts +46 -0
  105. package/mock/weather.tsx +105 -0
  106. package/package.json +7 -2
  107. package/blocks/activities/shelf/examples.mdx +0 -33
  108. package/blocks/activities/shelf/index.tsx +0 -289
  109. package/blocks/activities/timer/examples.mdx +0 -52
  110. package/blocks/activities/timer/index.tsx +0 -292
  111. package/blocks/system/controls/examples.mdx +0 -34
  112. package/blocks/system/controls/index.tsx +0 -167
  113. package/blocks/system/devices/examples.mdx +0 -25
  114. package/blocks/system/devices/index.tsx +0 -172
  115. package/blocks/system/power-alert/examples.mdx +0 -32
  116. package/blocks/system/power-alert/index.tsx +0 -89
  117. package/components/indicators/battery-glyph/examples.mdx +0 -22
  118. package/components/indicators/battery-glyph/index.tsx +0 -91
  119. package/dist/blocks/activities/shelf/index.d.ts +0 -2
  120. package/dist/blocks/activities/shelf/index.js +0 -14
  121. package/dist/blocks/activities/timer/index.d.ts +0 -2
  122. package/dist/blocks/activities/timer/index.js +0 -19
  123. package/dist/blocks/system/controls/index.d.ts +0 -2
  124. package/dist/blocks/system/controls/index.js +0 -10
  125. package/dist/blocks/system/devices/index.d.ts +0 -2
  126. package/dist/blocks/system/devices/index.js +0 -12
  127. package/dist/blocks/system/power-alert/index.d.ts +0 -2
  128. package/dist/blocks/system/power-alert/index.js +0 -9
  129. package/dist/components/indicators/battery-glyph/index.d.ts +0 -2
  130. package/dist/components/indicators/battery-glyph/index.js +0 -9
  131. package/dist/shared/chunk-2qpcsv5h.d.ts +0 -45
  132. package/dist/shared/chunk-45gytfr1.d.ts +0 -84
  133. package/dist/shared/chunk-50ffk4r7.d.ts +0 -69
  134. package/dist/shared/chunk-5w0yck07.d.ts +0 -32
  135. package/dist/shared/chunk-7hr53mby.js +0 -116
  136. package/dist/shared/chunk-b8jb1w72.js +0 -145
  137. package/dist/shared/chunk-cpewy6yg.js +0 -178
  138. package/dist/shared/chunk-e3e4s4ds.d.ts +0 -77
  139. package/dist/shared/chunk-enm6td0p.js +0 -280
  140. package/dist/shared/chunk-fvedaas2.d.ts +0 -33
  141. package/dist/shared/chunk-gex38j8x.d.ts +0 -82
  142. package/dist/shared/chunk-hwtxpzg0.js +0 -69
  143. package/dist/shared/chunk-phb53x1f.js +0 -252
  144. package/dist/shared/chunk-r8esmjfs.d.ts +0 -42
  145. package/dist/shared/chunk-rcp1g9ca.js +0 -70
  146. package/dist/shared/chunk-rx9sphz2.js +0 -266
  147. package/dist/shared/chunk-xdeek16r.d.ts +0 -58
  148. package/dist/shared/chunk-xkzjk1tq.js +0 -206
@@ -1,49 +1,68 @@
1
1
  import NowPlaying from './index'
2
- import { MockArtwork } from '../../../mock/artwork'
3
- import { FlashIsland, PLAYING, ScreenEdge, TimerBubble, WidgetIsland, WingsIsland } from '../../../mock/island-content'
2
+ import Button from '@justanarthur/modo-ui/components/actions/button'
3
+ import { ARTWORK_TINT, MockArtwork } from '../../../mock/artwork'
4
+ import { FlashIsland, PLAYING, WidgetIsland, WingsIsland } from '../../../mock/island-content'
4
5
  import { TRACK } from '../../../mock/data'
5
6
 
6
7
  # Player
7
8
 
8
- The open island's view: artwork, title and artist, the scrubber running on by itself, the transport and the app it plays in.
9
+ The artwork as the hero's picture with a glow of its tint, the title, artist and album, the scrubber ticking on by itself, the transport, the app and the device it plays on, and shuffle, repeat and the heart.
9
10
 
10
11
  <WidgetIsland tab="now-playing">
11
- <NowPlaying track={PLAYING} />
12
+ <NowPlaying track={PLAYING} defaultShuffle={false} defaultRepeat="all" defaultLiked />
13
+ </WidgetIsland>
14
+
15
+ # Paused, no extras
16
+
17
+ Without shuffle, repeat or like values or handlers, their buttons stay out; paused, the bars settle.
18
+
19
+ <WidgetIsland tab="now-playing">
20
+ <NowPlaying track={{ ...PLAYING, output: undefined }} defaultPlaying={false} />
12
21
  </WidgetIsland>
13
22
 
14
23
  # Without artwork
15
24
 
16
- A small note tile leads the title row instead of an empty square.
25
+ `artwork: null` says the track has none: the note placeholder takes the artwork's place. Left out, the artwork is still loading, and the last picture stays up.
26
+
27
+ <WidgetIsland tab="now-playing">
28
+ <NowPlaying track={{ ...TRACK, artwork: null }} defaultPlaying={false} />
29
+ </WidgetIsland>
30
+
31
+ # A stream
32
+
33
+ A `duration` of `0` hides the scrubber.
17
34
 
18
35
  <WidgetIsland tab="now-playing">
19
- <NowPlaying track={TRACK} defaultPlaying={false} />
36
+ <NowPlaying
37
+ track={{ title: 'Lofi beats to code to', artist: 'Radio', source: 'Safari', output: 'Living room', outputKind: 'airplay', duration: 0, position: 0, artwork: <MockArtwork variant="night" />, tint: ARTWORK_TINT.night }}
38
+ />
20
39
  </WidgetIsland>
21
40
 
22
41
  # Nothing playing
23
42
 
24
43
  <WidgetIsland tab="now-playing">
25
- <NowPlaying track={null} />
44
+ <NowPlaying track={null} emptyActions={<Button variant="secondary" size="compact">Open Music</Button>} />
26
45
  </WidgetIsland>
27
46
 
28
47
  # Compact
29
48
 
30
- `NowPlaying.Leading` and `NowPlaying.Trailing` in the wings; the bars settle low while paused.
49
+ `NowPlaying.Leading` and `NowPlaying.Trailing` in the wings: the artwork, and the bars in its tint, settling low while paused.
31
50
 
32
51
  <div className="flex w-full flex-col gap-3">
33
- <WingsIsland leading={<NowPlaying.Leading track={PLAYING} />} trailing={<NowPlaying.Trailing />} />
34
- <WingsIsland leading={<NowPlaying.Leading track={PLAYING} />} trailing={<NowPlaying.Trailing playing={false} />} />
52
+ <WingsIsland leading={<NowPlaying.Leading track={PLAYING} />} trailing={<NowPlaying.Trailing track={PLAYING} />} />
53
+ <WingsIsland leading={<NowPlaying.Leading track={PLAYING} />} trailing={<NowPlaying.Trailing track={PLAYING} playing={false} />} />
35
54
  </div>
36
55
 
37
56
  # Minimal
38
57
 
39
- `NowPlaying.Minimal`, the artwork as a disc, in the split island's bubble beside a timer.
58
+ `NowPlaying.Minimal`, the artwork as a disc, in the split island's bubble.
40
59
 
41
- <WingsIsland leading={<NowPlaying.Leading track={PLAYING} />} trailing={<NowPlaying.Trailing />} minimal={<NowPlaying.Minimal track={PLAYING} />} />
60
+ <WingsIsland leading={<NowPlaying.Leading track={PLAYING} />} trailing={<NowPlaying.Trailing track={PLAYING} />} minimal={<NowPlaying.Minimal track={PLAYING} />} />
42
61
 
43
62
  # Track change
44
63
 
45
64
  `NowPlaying.Flash` announces the next track for a moment.
46
65
 
47
66
  <FlashIsland>
48
- <NowPlaying.Flash track={{ ...PLAYING, title: 'Teardrop', artist: 'Massive Attack', artwork: <MockArtwork variant="night" /> }} />
67
+ <NowPlaying.Flash track={{ ...PLAYING, title: 'Teardrop', artist: 'Massive Attack', album: 'Mezzanine', artwork: <MockArtwork variant="night" />, tint: ARTWORK_TINT.night }} />
49
68
  </FlashIsland>
@@ -7,24 +7,60 @@
7
7
 
8
8
  'use client'
9
9
 
10
- import Button from '@justanarthur/modo-ui/components/actions/button'
11
- import EmptyState from '@justanarthur/modo-ui/components/feedback/empty-state'
10
+ import { useReduceMotion } from '@justanarthur/modo-ui/lib/reduced-motion'
11
+ import { useSize } from '@justanarthur/modo-ui/lib/size-context'
12
+ import { spring } from '@justanarthur/modo-ui/lib/springs'
13
+ import { SURFACE_BG } from '@justanarthur/modo-ui/lib/surface-classes'
14
+ import { useLift } from '@justanarthur/modo-ui/lib/surface-context'
12
15
  import { useControllableState } from '@justanarthur/modo-ui/lib/use-controllable-state'
13
16
  import { cn } from '@justanarthur/modo-ui/lib/utils'
14
- import { Music, Pause, Play, SkipBack, SkipForward } from 'lucide-react'
15
- import type { ReactNode } from 'react'
17
+ import {
18
+ Airplay,
19
+ Disc3,
20
+ Headphones,
21
+ Heart,
22
+ Laptop,
23
+ Music,
24
+ Pause,
25
+ Play,
26
+ Repeat,
27
+ Repeat1,
28
+ Shuffle,
29
+ SkipBack,
30
+ SkipForward,
31
+ Speaker,
32
+ } from 'lucide-react'
33
+ import { motion } from 'motion/react'
34
+ import { type ReactNode, useState } from 'react'
16
35
  import Equalizer from '../../../components/indicators/equalizer'
17
36
  import MediaScrubber from '../../../components/indicators/media-scrubber'
18
37
  import IslandFlash from '../../../components/island/island-flash'
38
+ import Widget from '../../../components/island/widget'
39
+ import { type Artwork, type ShownArtwork, useArtworkTint, useStableArtwork } from '../../../lib/artwork'
40
+
41
+ type NowPlayingOutput = 'built-in' | 'headphones' | 'speaker' | 'airplay'
42
+ type NowPlayingRepeat = 'off' | 'all' | 'one'
19
43
 
20
44
  interface NowPlayingTrack {
45
+ /** What tells two tracks apart; defaults to the title, artist and album. */
46
+ id?: string
21
47
  title: string
22
48
  artist?: string
23
49
  album?: string
24
- /** The artwork: an image URL, or any element (an `<img>`, a generated tile). */
25
- artwork?: string | ReactNode
26
- /** The app it plays in, shown under the controls. */
50
+ /**
51
+ * The artwork: an image URL, or any element. `null` when the track has
52
+ * none (the placeholder shows); left out while it isn't known yet, which
53
+ * keeps the last picture up.
54
+ */
55
+ artwork?: Artwork | null
56
+ /** The color the artwork leans to, any CSS color: it tints the glow, the bars and the toggles. Read from an image URL when left out. */
57
+ tint?: string
58
+ /** The app it plays in. */
27
59
  source?: string
60
+ /** Where it plays: a device's name. */
61
+ output?: string
62
+ /** What kind of device `output` is, for its glyph. Defaults to `'built-in'`. */
63
+ outputKind?: NowPlayingOutput
28
64
  /** The track's length, in seconds; `0` for a stream, which hides the scrubber. */
29
65
  duration: number
30
66
  /** Where playback is, in seconds. */
@@ -46,173 +82,330 @@ interface NowPlayingProps {
46
82
  onNext?: () => void
47
83
  /** Called with the position to seek to, once, when a drag on the scrubber ends. */
48
84
  onSeek?: (seconds: number) => void
49
- /** The empty state's line. Defaults to `'Play something in Music, Spotify or a browser.'`. */
85
+ /** Shuffle is on (controlled). The toggle shows when this, `defaultShuffle` or `onShuffleChange` is given. */
86
+ shuffle?: boolean
87
+ /** Shuffle is on at first (uncontrolled). */
88
+ defaultShuffle?: boolean
89
+ /** Called with the new state when shuffle is pressed. */
90
+ onShuffleChange?: (shuffle: boolean) => void
91
+ /** The repeat mode (controlled): a press steps off → all → one. Shows like `shuffle`. */
92
+ repeat?: NowPlayingRepeat
93
+ /** The repeat mode at first (uncontrolled). */
94
+ defaultRepeat?: NowPlayingRepeat
95
+ /** Called with the next mode when repeat is pressed. */
96
+ onRepeatChange?: (repeat: NowPlayingRepeat) => void
97
+ /** The track is in the library (controlled). Shows like `shuffle`. */
98
+ liked?: boolean
99
+ /** The track is in the library at first (uncontrolled). */
100
+ defaultLiked?: boolean
101
+ /** Called with the new state when the heart is pressed. */
102
+ onLikedChange?: (liked: boolean) => void
103
+ /** The empty state's line. Defaults to `'Play something in Music, Spotify or a browser and it shows up here.'`. */
50
104
  emptyDescription?: ReactNode
105
+ /** The empty state's way forward, such as a Button that opens a player. */
106
+ emptyActions?: ReactNode
51
107
  /** Classes for the root, which fills its container. */
52
108
  className?: string
53
109
  }
54
110
 
55
- const GLYPH = { strokeWidth: 1.5, fill: 'currentColor', strokeLinejoin: 'round' } as const
111
+ const OUTPUT_ICON = { 'built-in': Laptop, headphones: Headphones, speaker: Speaker, airplay: Airplay }
112
+ const NEXT_REPEAT: Record<NowPlayingRepeat, NowPlayingRepeat> = { off: 'all', all: 'one', one: 'off' }
113
+ const REPEAT_LABEL: Record<NowPlayingRepeat, string> = {
114
+ off: 'Repeat',
115
+ all: 'Repeat all',
116
+ one: 'Repeat one',
117
+ }
118
+
119
+ type TrackIdentity = Pick<NowPlayingTrack, 'id' | 'title' | 'artist' | 'album' | 'artwork' | 'tint'>
120
+
121
+ const keyOf = (track?: TrackIdentity | null) =>
122
+ track ? (track.id ?? [track.title, track.artist, track.album].join('\u0000')) : ''
123
+
124
+ /** The track's tint: its own, else read from its image. */
125
+ function useTint(track?: TrackIdentity | null) {
126
+ const read = useArtworkTint(track?.tint || typeof track?.artwork !== 'string' ? undefined : track.artwork)
127
+ return track?.tint ?? read
128
+ }
129
+
130
+ function Picture({ art, glyph }: { art: ShownArtwork['art']; glyph: number }) {
131
+ const level = useLift(1)
132
+ if (typeof art === 'string') return <img alt="" src={art} draggable={false} className="size-full object-cover" />
133
+ if (art != null) return art
134
+ return (
135
+ <span className={cn('flex size-full items-center justify-center text-muted-foreground', SURFACE_BG[level])}>
136
+ <Music size={glyph} strokeWidth={1.5} />
137
+ </span>
138
+ )
139
+ }
56
140
 
57
141
  interface ArtworkProps {
58
- /** The track's artwork; without one, a note on a tile one surface up. */
59
- artwork?: string | ReactNode
60
- /** The note's size in px when there is no artwork. Defaults to `14`. */
142
+ /** The track whose artwork it shows; without one, the placeholder. */
143
+ track?: TrackIdentity | null
144
+ /** The placeholder note's size in px. Defaults to `14`. */
61
145
  glyph?: number
62
146
  /** Classes for the tile: its size and radius. */
63
147
  className?: string
64
148
  }
65
149
 
66
- /** A track's artwork in a tile, or a note on a raised tile when it has none. */
67
- function NowPlayingArtwork({ artwork, glyph = 14, className }: ArtworkProps) {
150
+ /**
151
+ * A track's artwork in a tile that never blinks: the last good picture stays
152
+ * while the next one loads or an update comes without one, the next
153
+ * crossfades in over it, and only a track without artwork shows the note.
154
+ */
155
+ function NowPlayingArtwork({ track, glyph = 14, className }: ArtworkProps) {
156
+ const shown = useStableArtwork(track?.artwork, keyOf(track))
157
+ const reduced = useReduceMotion()
158
+ const [top, setTop] = useState(shown)
159
+ const [under, setUnder] = useState<ShownArtwork | null>(null)
160
+ if (top.id !== shown.id) {
161
+ setUnder(top)
162
+ setTop(shown)
163
+ }
164
+
68
165
  return (
69
- <span
70
- className={cn(
71
- 'flex shrink-0 items-center justify-center overflow-hidden bg-surface-3 text-muted-foreground',
72
- className,
73
- )}
74
- >
75
- {typeof artwork === 'string' ? (
76
- <img alt="" src={artwork} draggable={false} className="size-full object-cover" />
77
- ) : (
78
- (artwork ?? <Music size={glyph} strokeWidth={1.5} />)
166
+ <span className={cn('relative isolate block shrink-0 overflow-hidden', className)}>
167
+ {under && (
168
+ <span key={under.id} className="absolute inset-0">
169
+ <Picture art={under.art} glyph={glyph} />
170
+ </span>
79
171
  )}
172
+ <motion.span
173
+ key={shown.id}
174
+ className="absolute inset-0"
175
+ initial={under ? { opacity: 0 } : false}
176
+ animate={{ opacity: 1 }}
177
+ transition={reduced ? spring.fast : spring.slow}
178
+ onAnimationComplete={() => setUnder(null)}
179
+ >
180
+ <Picture art={shown.art} glyph={glyph} />
181
+ </motion.span>
182
+ <span
183
+ aria-hidden
184
+ className="pointer-events-none absolute inset-0 rounded-[inherit] ring-1 ring-border ring-inset"
185
+ />
186
+ </span>
187
+ )
188
+ }
189
+
190
+ interface PartProps {
191
+ /** What plays. */
192
+ track?: TrackIdentity | null
193
+ /** It plays: the bars dance. Defaults to `true`. */
194
+ playing?: boolean
195
+ }
196
+
197
+ /** Level bars in the artwork's tint. */
198
+ function TintedBars({ track, playing = true, className }: PartProps & { className?: string }) {
199
+ const tint = useTint(track)
200
+ return (
201
+ <span className={cn('inline-flex text-foreground', className)} style={tint ? { color: tint } : undefined}>
202
+ <Equalizer playing={playing} label={playing ? 'Playing' : 'Paused'} barClassName="bg-current" />
80
203
  </span>
81
204
  )
82
205
  }
83
206
 
84
207
  /** The compact island's left wing: the artwork, small. */
85
- function NowPlayingLeading({ track }: { track?: Pick<NowPlayingTrack, 'artwork'> | null }) {
86
- return <NowPlayingArtwork artwork={track?.artwork} glyph={12} className="size-5.5 rounded-md" />
208
+ function NowPlayingLeading({ track }: Pick<PartProps, 'track'>) {
209
+ return <NowPlayingArtwork track={track} glyph={12} className="size-5.5 rounded-md" />
87
210
  }
88
211
 
89
- /** The compact island's right wing: the level bars, low while paused. */
90
- function NowPlayingTrailing({ playing = true }: { playing?: boolean }) {
91
- return <Equalizer playing={playing} label={playing ? 'Playing' : 'Paused'} />
212
+ /** The compact island's right wing: the level bars in the artwork's tint, low while paused. */
213
+ function NowPlayingTrailing(props: PartProps) {
214
+ return <TintedBars {...props} />
92
215
  }
93
216
 
94
217
  /** The split island's bubble: the artwork as a disc. */
95
- function NowPlayingMinimal({ track }: { track?: Pick<NowPlayingTrack, 'artwork'> | null }) {
96
- return <NowPlayingArtwork artwork={track?.artwork} glyph={12} className="size-6 rounded-full" />
218
+ function NowPlayingMinimal({ track }: Pick<PartProps, 'track'>) {
219
+ return <NowPlayingArtwork track={track} glyph={12} className="size-6 rounded-full" />
97
220
  }
98
221
 
99
- /** The island's flash when the track changes: its artwork, title and artist, and the bars. */
222
+ /** The island's flash when the track changes: its artwork, title and artist, and the tinted bars. */
100
223
  function NowPlayingFlash({ track, playing = true }: { track: NowPlayingTrack; playing?: boolean }) {
101
224
  return (
102
225
  <IslandFlash
103
- icon={<NowPlayingArtwork artwork={track.artwork} className="size-8 rounded-lg" />}
226
+ icon={<NowPlayingArtwork track={track} className="size-9 rounded-lg" />}
104
227
  title={track.title || 'Unknown title'}
105
- caption={track.artist || track.album || track.source}
106
- trailing={<Equalizer playing={playing} />}
228
+ caption={[track.artist, track.album].filter(Boolean).join(' — ') || track.source}
229
+ trailing={<TintedBars track={track} playing={playing} />}
107
230
  />
108
231
  )
109
232
  }
110
233
 
111
- interface ControlsProps {
112
- playing: boolean
113
- onToggle: () => void
114
- onPrevious?: () => void
115
- onNext?: () => void
116
- }
117
-
118
- function Controls({ playing, onToggle, onPrevious, onNext }: ControlsProps) {
119
- return (
120
- <div className="flex items-center gap-2">
121
- <Button variant="ghost" size="icon" aria-label="Previous" onClick={onPrevious}>
122
- <SkipBack {...GLYPH} size={16} />
123
- </Button>
124
- <Button
125
- variant="ghost"
126
- size="icon"
127
- className="text-foreground"
128
- aria-label={playing ? 'Pause' : 'Play'}
129
- onClick={onToggle}
130
- >
131
- {playing ? <Pause {...GLYPH} size={18} /> : <Play {...GLYPH} size={18} />}
132
- </Button>
133
- <Button variant="ghost" size="icon" aria-label="Next" onClick={onNext}>
134
- <SkipForward {...GLYPH} size={16} />
135
- </Button>
136
- </div>
137
- )
138
- }
234
+ // Literal tables: UnoCSS only generates the classes it can read whole.
235
+ const ART = { default: 'size-36 rounded-2xl', compact: 'size-28 rounded-xl' }
139
236
 
140
237
  /**
141
238
  * What's playing, as a notch app's open island shows it: the artwork, the
142
- * title and artist, where the track is, and the transport.
239
+ * title and artist, where the track is, the transport, and where it plays.
240
+ *
241
+ * The artwork is the hero's picture, as tall as the widget, with a soft glow
242
+ * of its tint behind it (`track.tint`, else read from an image URL); the
243
+ * equalizer and any toggle that is on take the same tint, so the color
244
+ * comes from the music. The artwork never blinks: the last good picture
245
+ * stays up while a new one loads or an update arrives without one, the next
246
+ * crossfades in over it, and only a track whose `artwork` is `null` shows
247
+ * the placeholder note.
143
248
  *
144
- * The scrubber is the kit's MediaScrubber: it runs on by itself while
145
- * playing and seeks once when a drag ends (`onSeek`). Play / pause is
146
- * controlled through `playing` / `onPlayingChange`, or kept here from
147
- * `defaultPlaying`; previous and next report their press. Without artwork a
148
- * big square would be an empty box, so a small note tile leads the title row
149
- * instead. Without a track it says nothing is playing.
249
+ * Under the title and artist (with the album) runs the kit's MediaScrubber,
250
+ * which ticks on by itself while playing and seeks once when a drag ends
251
+ * (`onSeek`). The transport sits in the middle of the last row, the source
252
+ * app and the output device on its left, and shuffle, repeat and the heart
253
+ * on its right, each shown when its value or handler is given. Play / pause
254
+ * runs through `playing` / `onPlayingChange`, or is kept here from
255
+ * `defaultPlaying`; the toggles are the same. Without a track it says
256
+ * nothing is playing and how to change that.
150
257
  *
151
258
  * The other forms are parts: `NowPlaying.Leading` and `NowPlaying.Trailing`
152
- * for the compact island's wings (the artwork, and an Equalizer that settles
153
- * when paused), `NowPlaying.Minimal` for the split island's bubble (the
154
- * artwork as a disc), `NowPlaying.Flash` for the flash on a track change and
155
- * `NowPlaying.Artwork` for the tile on its own.
259
+ * for the compact island's wings (the artwork, and the tinted Equalizer that
260
+ * settles when paused), `NowPlaying.Minimal` for the split island's bubble
261
+ * (the artwork as a disc), `NowPlaying.Flash` for the flash on a track
262
+ * change and `NowPlaying.Artwork` for the tile on its own.
156
263
  *
157
264
  * @example {@include ./examples.mdx}
158
265
  */
159
- function NowPlaying({
160
- track,
161
- playing: playingProp,
162
- defaultPlaying = true,
163
- onPlayingChange,
164
- onPrevious,
165
- onNext,
166
- onSeek,
167
- emptyDescription = 'Play something in Music, Spotify or a browser.',
168
- className,
169
- }: NowPlayingProps) {
170
- const [playing, setPlaying] = useControllableState(playingProp, defaultPlaying, onPlayingChange)
171
-
172
- if (!track)
173
- return (
174
- <div className={cn('flex size-full items-center justify-center', className)}>
175
- <EmptyState size="compact" icon={Music} title="Nothing playing" description={emptyDescription} />
176
- </div>
177
- )
266
+ const NowPlaying = Object.assign(
267
+ function NowPlaying({
268
+ track,
269
+ playing: playingProp,
270
+ defaultPlaying = true,
271
+ onPlayingChange,
272
+ onPrevious,
273
+ onNext,
274
+ onSeek,
275
+ shuffle: shuffleProp,
276
+ defaultShuffle,
277
+ onShuffleChange,
278
+ repeat: repeatProp,
279
+ defaultRepeat,
280
+ onRepeatChange,
281
+ liked: likedProp,
282
+ defaultLiked,
283
+ onLikedChange,
284
+ emptyDescription = 'Play something in Music, Spotify or a browser and it shows up here.',
285
+ emptyActions,
286
+ className,
287
+ }: NowPlayingProps) {
288
+ const size = useSize()
289
+ const [playing, setPlaying] = useControllableState(playingProp, defaultPlaying, onPlayingChange)
290
+ const [shuffle, setShuffle] = useControllableState(shuffleProp, defaultShuffle ?? false, onShuffleChange)
291
+ const [repeat, setRepeat] = useControllableState(repeatProp, defaultRepeat ?? 'off', onRepeatChange)
292
+ const [liked, setLiked] = useControllableState(likedProp, defaultLiked ?? false, onLikedChange)
293
+ const tint = useTint(track)
178
294
 
179
- const art = track.artwork !== undefined
180
- return (
181
- <div className={cn('flex size-full items-center gap-5', className)}>
182
- {art && <NowPlayingArtwork artwork={track.artwork} className="size-30 rounded-2xl" />}
183
- <div className="flex min-w-0 flex-1 flex-col gap-2">
184
- <div className="flex items-center gap-3">
185
- {!art && <NowPlayingArtwork glyph={18} className="size-10 rounded-xl" />}
186
- <div className="flex min-w-0 flex-1 flex-col">
187
- <span className="truncate text-subtitle weight-semibold text-foreground">
188
- {track.title || 'Unknown title'}
295
+ if (!track)
296
+ return (
297
+ <Widget.Message
298
+ icon={Music}
299
+ title="Nothing playing"
300
+ description={emptyDescription}
301
+ actions={emptyActions}
302
+ className={className}
303
+ />
304
+ )
305
+
306
+ const showShuffle = shuffleProp !== undefined || defaultShuffle !== undefined || onShuffleChange !== undefined
307
+ const showRepeat = repeatProp !== undefined || defaultRepeat !== undefined || onRepeatChange !== undefined
308
+ const showLiked = likedProp !== undefined || defaultLiked !== undefined || onLikedChange !== undefined
309
+ const byline = [track.artist, track.album].filter(Boolean).join(' — ')
310
+
311
+ return (
312
+ <div className={cn('relative isolate flex w-full flex-col justify-center', className)}>
313
+ <Widget
314
+ media={
315
+ <span className="relative flex">
316
+ {tint && (
317
+ <span
318
+ aria-hidden
319
+ className="absolute -inset-x-8 -inset-y-4 -z-1 opacity-70"
320
+ style={{ backgroundImage: `radial-gradient(closest-side, ${tint}, transparent)` }}
321
+ />
322
+ )}
323
+ <NowPlayingArtwork track={track} glyph={28} className={ART[size.variant]} />
189
324
  </span>
190
- {(track.artist || track.album) && (
191
- <span className="truncate text-caption text-muted-foreground">{track.artist || track.album}</span>
192
- )}
325
+ }
326
+ >
327
+ <div className="flex min-w-0 items-start gap-3">
328
+ <div className="flex min-w-0 flex-1 flex-col">
329
+ <Widget.Title>{track.title || 'Unknown title'}</Widget.Title>
330
+ {byline && <Widget.Subtitle>{byline}</Widget.Subtitle>}
331
+ </div>
332
+ <TintedBars track={track} playing={playing} className="mt-1.5" />
193
333
  </div>
194
- <Equalizer playing={playing} />
195
- </div>
196
- {track.duration > 0 && (
197
- <MediaScrubber position={track.position} duration={track.duration} playing={playing} onSeek={onSeek} />
198
- )}
199
- <div className="grid grid-cols-[1fr_auto_1fr] items-center gap-3">
200
- <span className="truncate text-caption text-muted-foreground">{track.source}</span>
201
- <Controls playing={playing} onToggle={() => setPlaying(!playing)} onPrevious={onPrevious} onNext={onNext} />
202
- <span />
203
- </div>
204
- </div>
205
- </div>
206
- )
207
- }
208
334
 
209
- NowPlaying.Artwork = NowPlayingArtwork
210
- NowPlaying.Leading = NowPlayingLeading
211
- NowPlaying.Trailing = NowPlayingTrailing
212
- NowPlaying.Minimal = NowPlayingMinimal
213
- NowPlaying.Flash = NowPlayingFlash
335
+ {track.duration > 0 && (
336
+ <MediaScrubber
337
+ className="mt-2"
338
+ quiet
339
+ position={track.position}
340
+ duration={track.duration}
341
+ playing={playing}
342
+ onSeek={onSeek}
343
+ />
344
+ )}
345
+
346
+ <div className="grid grid-cols-[1fr_auto_1fr] items-center gap-2">
347
+ <Widget.Meta>
348
+ {track.source && <Widget.MetaItem icon={Disc3}>{track.source}</Widget.MetaItem>}
349
+ {track.output && (
350
+ <Widget.MetaItem icon={OUTPUT_ICON[track.outputKind ?? 'built-in']}>{track.output}</Widget.MetaItem>
351
+ )}
352
+ </Widget.Meta>
353
+ <div className="flex items-center gap-1">
354
+ <Widget.Action icon={SkipBack} label="Previous" filled onClick={onPrevious} />
355
+ <Widget.Action
356
+ icon={playing ? Pause : Play}
357
+ label={playing ? 'Pause' : 'Play'}
358
+ emphasis="primary"
359
+ filled
360
+ onClick={() => setPlaying(!playing)}
361
+ />
362
+ <Widget.Action icon={SkipForward} label="Next" filled onClick={onNext} />
363
+ </div>
364
+ <div className="flex items-center justify-end">
365
+ {showShuffle && (
366
+ <Widget.Action
367
+ icon={Shuffle}
368
+ label="Shuffle"
369
+ pressed={shuffle}
370
+ color={tint}
371
+ onClick={() => setShuffle(!shuffle)}
372
+ />
373
+ )}
374
+ {showRepeat && (
375
+ <Widget.Action
376
+ icon={repeat === 'one' ? Repeat1 : Repeat}
377
+ label={REPEAT_LABEL[repeat]}
378
+ pressed={repeat !== 'off'}
379
+ color={tint}
380
+ onClick={() => setRepeat(NEXT_REPEAT[repeat])}
381
+ />
382
+ )}
383
+ {showLiked && (
384
+ <Widget.Action
385
+ icon={Heart}
386
+ label={liked ? 'Remove from library' : 'Add to library'}
387
+ pressed={liked}
388
+ filled={liked}
389
+ color={tint}
390
+ onClick={() => setLiked(!liked)}
391
+ />
392
+ )}
393
+ </div>
394
+ </div>
395
+ </Widget>
396
+ </div>
397
+ )
398
+ },
399
+ {
400
+ Artwork: NowPlayingArtwork,
401
+ Leading: NowPlayingLeading,
402
+ Trailing: NowPlayingTrailing,
403
+ Minimal: NowPlayingMinimal,
404
+ Flash: NowPlayingFlash,
405
+ },
406
+ )
214
407
 
215
408
  export default NowPlaying
216
409
 
217
- export type { NowPlayingProps, NowPlayingTrack }
410
+ export type { NowPlayingOutput, NowPlayingProps, NowPlayingRepeat, NowPlayingTrack }
218
411
  export { NowPlaying, NowPlayingArtwork, NowPlayingFlash, NowPlayingLeading, NowPlayingMinimal, NowPlayingTrailing }