@justanarthur/modo-ui-notch 0.0.0-stage → 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.
- package/LICENSE +21 -0
- package/README.md +75 -2
- package/blocks/activities/agenda/examples.mdx +74 -0
- package/blocks/activities/agenda/index.tsx +441 -0
- package/blocks/activities/clock/examples.mdx +73 -0
- package/blocks/activities/clock/index.tsx +619 -0
- package/blocks/activities/now-playing/examples.mdx +68 -0
- package/blocks/activities/now-playing/index.tsx +411 -0
- package/blocks/activities/weather/examples.mdx +115 -0
- package/blocks/activities/weather/index.tsx +634 -0
- package/blocks/app/expanded-island/examples.mdx +46 -0
- package/blocks/app/expanded-island/index.tsx +143 -0
- package/blocks/app/settings-window/examples.mdx +34 -0
- package/blocks/app/settings-window/index.tsx +375 -0
- package/blocks/system/clipboard/examples.mdx +83 -0
- package/blocks/system/clipboard/index.tsx +563 -0
- package/blocks/system/recent-files/examples.mdx +66 -0
- package/blocks/system/recent-files/index.tsx +542 -0
- package/blocks/system/system-stats/examples.mdx +52 -0
- package/blocks/system/system-stats/index.tsx +312 -0
- package/components/indicators/countdown/examples.mdx +25 -0
- package/components/indicators/countdown/index.tsx +83 -0
- package/components/indicators/equalizer/examples.mdx +20 -0
- package/components/indicators/equalizer/index.tsx +116 -0
- package/components/indicators/media-scrubber/examples.mdx +29 -0
- package/components/indicators/media-scrubber/index.tsx +122 -0
- package/components/island/island/examples.mdx +57 -0
- package/components/island/island/index.tsx +415 -0
- package/components/island/island-flash/examples.mdx +52 -0
- package/components/island/island-flash/index.tsx +79 -0
- package/components/island/island-tabs/examples.mdx +53 -0
- package/components/island/island-tabs/index.tsx +285 -0
- package/components/island/widget/examples.mdx +76 -0
- package/components/island/widget/index.tsx +431 -0
- package/dist/blocks/activities/agenda/index.d.ts +2 -0
- package/dist/blocks/activities/agenda/index.js +21 -0
- package/dist/blocks/activities/clock/index.d.ts +2 -0
- package/dist/blocks/activities/clock/index.js +25 -0
- package/dist/blocks/activities/now-playing/index.d.ts +3 -0
- package/dist/blocks/activities/now-playing/index.js +24 -0
- package/dist/blocks/activities/weather/index.d.ts +2 -0
- package/dist/blocks/activities/weather/index.js +21 -0
- package/dist/blocks/app/expanded-island/index.d.ts +3 -0
- package/dist/blocks/app/expanded-island/index.js +11 -0
- package/dist/blocks/app/settings-window/index.d.ts +2 -0
- package/dist/blocks/app/settings-window/index.js +7 -0
- package/dist/blocks/system/clipboard/index.d.ts +2 -0
- package/dist/blocks/system/clipboard/index.js +17 -0
- package/dist/blocks/system/recent-files/index.d.ts +2 -0
- package/dist/blocks/system/recent-files/index.js +19 -0
- package/dist/blocks/system/system-stats/index.d.ts +2 -0
- package/dist/blocks/system/system-stats/index.js +15 -0
- package/dist/components/indicators/countdown/index.d.ts +2 -0
- package/dist/components/indicators/countdown/index.js +8 -0
- package/dist/components/indicators/equalizer/index.d.ts +2 -0
- package/dist/components/indicators/equalizer/index.js +7 -0
- package/dist/components/indicators/media-scrubber/index.d.ts +2 -0
- package/dist/components/indicators/media-scrubber/index.js +8 -0
- package/dist/components/island/island/index.d.ts +3 -0
- package/dist/components/island/island/index.js +10 -0
- package/dist/components/island/island-flash/index.d.ts +2 -0
- package/dist/components/island/island-flash/index.js +7 -0
- package/dist/components/island/island-tabs/index.d.ts +2 -0
- package/dist/components/island/island-tabs/index.js +9 -0
- package/dist/components/island/widget/index.d.ts +2 -0
- package/dist/components/island/widget/index.js +30 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +195 -0
- package/dist/lib/artwork.d.ts +2 -0
- package/dist/lib/artwork.js +8 -0
- package/dist/lib/clock.d.ts +2 -0
- package/dist/lib/clock.js +14 -0
- package/dist/lib/geometry.d.ts +2 -0
- package/dist/lib/geometry.js +24 -0
- package/dist/lib/island-context.d.ts +3 -0
- package/dist/lib/island-context.js +8 -0
- package/dist/lib/motion.d.ts +21 -0
- package/dist/lib/motion.js +16 -0
- package/dist/shared/chunk-152gpyq3.d.ts +13 -0
- package/dist/shared/chunk-2818esrq.d.ts +140 -0
- package/dist/shared/chunk-2f7zxrbk.js +65 -0
- package/dist/shared/chunk-2m5dz8nf.d.ts +88 -0
- package/dist/shared/chunk-2s4q6mt0.js +27 -0
- package/dist/shared/chunk-3thgcfcq.d.ts +151 -0
- package/dist/shared/chunk-416tsgbc.d.ts +175 -0
- package/dist/shared/chunk-502rmtap.js +54 -0
- package/dist/shared/chunk-52gb3g6r.d.ts +12 -0
- package/dist/shared/chunk-5en5aaj1.d.ts +33 -0
- package/dist/shared/chunk-61t2dfte.js +63 -0
- package/dist/shared/chunk-7fvnrtz4.d.ts +105 -0
- package/dist/shared/chunk-81fpptwp.d.ts +75 -0
- package/dist/shared/chunk-9c7ewvkk.js +381 -0
- package/dist/shared/chunk-9m0xbg5v.js +112 -0
- package/dist/shared/chunk-9xtcv3sy.js +88 -0
- package/dist/shared/chunk-bvtyjcce.d.ts +123 -0
- package/dist/shared/chunk-cc9nwbtf.js +315 -0
- package/dist/shared/chunk-cfzmfnyh.d.ts +63 -0
- package/dist/shared/chunk-d5qm9cps.js +10 -0
- package/dist/shared/chunk-da177e8r.d.ts +114 -0
- package/dist/shared/chunk-fexwzycv.d.ts +36 -0
- package/dist/shared/chunk-gb56m10p.js +39 -0
- package/dist/shared/chunk-gejenfap.d.ts +25 -0
- package/dist/shared/chunk-hrpxbqmx.d.ts +28 -0
- package/dist/shared/chunk-j755a1a5.d.ts +41 -0
- package/dist/shared/chunk-j77cx8dp.js +498 -0
- package/dist/shared/chunk-mt0k6v8x.js +474 -0
- package/dist/shared/chunk-ndf79pv5.js +58 -0
- package/dist/shared/chunk-pfhy5e4q.d.ts +53 -0
- package/dist/shared/chunk-qdzemt2v.js +477 -0
- package/dist/shared/chunk-r471sknr.js +209 -0
- package/dist/shared/chunk-s2jeqqan.js +243 -0
- package/dist/shared/chunk-t0hcxh89.d.ts +124 -0
- package/dist/shared/chunk-w48eyvfr.d.ts +56 -0
- package/dist/shared/chunk-w5h6ay93.js +72 -0
- package/dist/shared/chunk-wkg17nxs.d.ts +101 -0
- package/dist/shared/chunk-x7f3g82r.js +285 -0
- package/dist/shared/chunk-xq5hc5gv.js +333 -0
- package/dist/shared/chunk-y0188bbn.js +331 -0
- package/dist/shared/chunk-ym0xbses.js +518 -0
- package/dist/styles.css +264 -0
- package/index.ts +22 -0
- package/lib/artwork.ts +112 -0
- package/lib/clock.ts +53 -0
- package/lib/geometry.ts +130 -0
- package/lib/island-context.tsx +24 -0
- package/lib/motion.ts +42 -0
- package/mock/activities.tsx +77 -0
- package/mock/artwork.tsx +37 -0
- package/mock/clipboard.tsx +79 -0
- package/mock/clock.tsx +77 -0
- package/mock/data.ts +139 -0
- package/mock/desktop.tsx +83 -0
- package/mock/files.tsx +70 -0
- package/mock/fit.ts +26 -0
- package/mock/island-content.tsx +142 -0
- package/mock/scene.tsx +52 -0
- package/mock/screen.tsx +76 -0
- package/mock/settings.tsx +489 -0
- package/mock/system.ts +46 -0
- package/mock/weather.tsx +105 -0
- package/package.json +122 -4
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Local addition: a notch app's system load, the busiest figure as the hero
|
|
3
|
+
* with its trend, the rest as facts and the busiest processes beside it.
|
|
4
|
+
* Rebuilt from Just Notch's stats plugin (`System`, `Tile`, `Measuring`,
|
|
5
|
+
* `CpuLoad`) on the kit's Widget frame and modo-ui's Sparkline and Meter:
|
|
6
|
+
* the readings come in as props.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
'use client'
|
|
10
|
+
|
|
11
|
+
import Sparkline, { type SparklineTone } from '@justanarthur/modo-ui/components/data-display/sparkline'
|
|
12
|
+
import Meter from '@justanarthur/modo-ui/components/feedback/meter'
|
|
13
|
+
import type { SizeVariant } from '@justanarthur/modo-ui/lib/size-context'
|
|
14
|
+
import { cn } from '@justanarthur/modo-ui/lib/utils'
|
|
15
|
+
import {
|
|
16
|
+
Activity,
|
|
17
|
+
ArrowDown,
|
|
18
|
+
ArrowUp,
|
|
19
|
+
BatteryCharging,
|
|
20
|
+
BatteryFull,
|
|
21
|
+
BatteryLow,
|
|
22
|
+
BatteryMedium,
|
|
23
|
+
Cpu,
|
|
24
|
+
HardDrive,
|
|
25
|
+
MemoryStick,
|
|
26
|
+
} from 'lucide-react'
|
|
27
|
+
import Widget from '../../../components/island/widget'
|
|
28
|
+
|
|
29
|
+
/** One reading of the system. */
|
|
30
|
+
interface StatsSample {
|
|
31
|
+
/** CPU load, from 0 to 1. */
|
|
32
|
+
cpu: number
|
|
33
|
+
/** Memory in use, in bytes. */
|
|
34
|
+
memoryUsed: number
|
|
35
|
+
/** All the memory, in bytes. */
|
|
36
|
+
memoryTotal: number
|
|
37
|
+
/** Memory pressure, from 0 to 1, as the system judges it; without it the share in use stands in. */
|
|
38
|
+
memoryPressure?: number
|
|
39
|
+
/** Network in, in bytes per second. */
|
|
40
|
+
netIn: number
|
|
41
|
+
/** Network out, in bytes per second. */
|
|
42
|
+
netOut: number
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface StatsBattery {
|
|
46
|
+
/** The charge, in percent (0 to 100). */
|
|
47
|
+
level: number
|
|
48
|
+
/** A charger is connected. */
|
|
49
|
+
charging?: boolean
|
|
50
|
+
/** Minutes until full while charging, else until empty. */
|
|
51
|
+
minutesLeft?: number
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface StatsDisk {
|
|
55
|
+
/** Free space on the startup disk, in bytes. */
|
|
56
|
+
free: number
|
|
57
|
+
/** The disk's size, in bytes. */
|
|
58
|
+
total: number
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface StatsProcess {
|
|
62
|
+
/** What tells it apart: its pid. */
|
|
63
|
+
id: string
|
|
64
|
+
/** The app or process name. */
|
|
65
|
+
name: string
|
|
66
|
+
/** Its share of the CPU, from 0 to 1. */
|
|
67
|
+
cpu: number
|
|
68
|
+
/** The memory it holds, in bytes. */
|
|
69
|
+
memory?: number
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
type StatsHero = 'cpu' | 'memory'
|
|
73
|
+
|
|
74
|
+
interface SystemStatsProps {
|
|
75
|
+
/** The readings so far, oldest first; the latest is the figure, all of them the trend. Without any, it is still measuring. */
|
|
76
|
+
samples: StatsSample[]
|
|
77
|
+
/** Which figure is the hero: the CPU load, or memory pressure when memory is what's tight. Defaults to `'cpu'`. */
|
|
78
|
+
hero?: StatsHero
|
|
79
|
+
/** The battery, on a laptop. */
|
|
80
|
+
battery?: StatsBattery
|
|
81
|
+
/** The startup disk's free space. */
|
|
82
|
+
disk?: StatsDisk
|
|
83
|
+
/** Seconds since the last boot. */
|
|
84
|
+
uptime?: number
|
|
85
|
+
/** The busiest processes, in any order: the top three list beside the hero, by CPU. */
|
|
86
|
+
processes?: StatsProcess[]
|
|
87
|
+
/** Step on the size ladder. Omitted, it follows the surrounding SizeProvider. */
|
|
88
|
+
size?: SizeVariant
|
|
89
|
+
/** Classes for the root, which fills its container. */
|
|
90
|
+
className?: string
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Processes listed before the count of the rest. */
|
|
94
|
+
const ROWS = 3
|
|
95
|
+
|
|
96
|
+
const percent = (v: number) => `${Math.round(v * 100)}%`
|
|
97
|
+
const share = (v: number) => (v < 0.1 ? `${(v * 100).toFixed(1)}%` : percent(v))
|
|
98
|
+
|
|
99
|
+
/** Bytes as `11.4 GB`, `640 MB` or `212 GB`. */
|
|
100
|
+
function bytes(n: number) {
|
|
101
|
+
if (n >= 100e9) return `${Math.round(n / 1e9)} GB`
|
|
102
|
+
if (n >= 1e9) return `${(n / 1e9).toFixed(1)} GB`
|
|
103
|
+
return `${Math.round(n / 1e6)} MB`
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Bytes per second as `2.4 MB/s`, `512 KB/s` or `80 B/s`. */
|
|
107
|
+
function rate(bps: number) {
|
|
108
|
+
if (bps >= 1e6) return `${(bps / 1e6).toFixed(1)} MB/s`
|
|
109
|
+
if (bps >= 1e3) return `${Math.round(bps / 1e3)} KB/s`
|
|
110
|
+
return `${Math.round(bps)} B/s`
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Seconds as `3 d 4 h`, `5 h 12 min` or `12 min`. */
|
|
114
|
+
function span(seconds: number) {
|
|
115
|
+
const minutes = Math.floor(seconds / 60)
|
|
116
|
+
const hours = Math.floor(minutes / 60)
|
|
117
|
+
const days = Math.floor(hours / 24)
|
|
118
|
+
if (days) return `${days} d ${hours % 24} h`
|
|
119
|
+
if (hours) return `${hours} h ${minutes % 60} min`
|
|
120
|
+
return `${minutes} min`
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Minutes as `3:40`. */
|
|
124
|
+
const clock = (minutes: number) => `${Math.floor(minutes / 60)}:${String(Math.round(minutes % 60)).padStart(2, '0')}`
|
|
125
|
+
|
|
126
|
+
/** The status a load reads as: calm, then the warning hue, then the error hue. */
|
|
127
|
+
function toneOf(load: number): SparklineTone {
|
|
128
|
+
if (load >= 0.9) return 'error'
|
|
129
|
+
if (load >= 0.75) return 'warning'
|
|
130
|
+
return 'current'
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function verdict(load: number) {
|
|
134
|
+
if (load >= 0.9) return 'Under strain'
|
|
135
|
+
if (load >= 0.6) return 'Busy'
|
|
136
|
+
if (load >= 0.2) return 'Steady'
|
|
137
|
+
return 'Idle'
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const pressureOf = (sample: StatsSample) => sample.memoryPressure ?? sample.memoryUsed / sample.memoryTotal
|
|
141
|
+
|
|
142
|
+
function batteryIcon({ level, charging }: StatsBattery) {
|
|
143
|
+
if (charging) return BatteryCharging
|
|
144
|
+
if (level <= 20) return BatteryLow
|
|
145
|
+
if (level <= 70) return BatteryMedium
|
|
146
|
+
return BatteryFull
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function BatteryItem({ battery }: { battery: StatsBattery }) {
|
|
150
|
+
const left = battery.minutesLeft === undefined ? undefined : clock(battery.minutesLeft)
|
|
151
|
+
return (
|
|
152
|
+
<Widget.MetaItem icon={batteryIcon(battery)}>
|
|
153
|
+
{battery.level}%{left && ` · ${left} ${battery.charging ? 'to full' : 'left'}`}
|
|
154
|
+
</Widget.MetaItem>
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
interface FactsProps {
|
|
159
|
+
last?: StatsSample
|
|
160
|
+
hero: StatsHero
|
|
161
|
+
battery?: StatsBattery
|
|
162
|
+
disk?: StatsDisk
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Everything but the hero, as two rows of glyph and words. */
|
|
166
|
+
function Facts({ last, hero, battery, disk }: FactsProps) {
|
|
167
|
+
const dash = '–'
|
|
168
|
+
return (
|
|
169
|
+
<div className="flex min-w-0 flex-col gap-1">
|
|
170
|
+
<Widget.Meta>
|
|
171
|
+
{hero === 'cpu' ? (
|
|
172
|
+
<Widget.MetaItem icon={MemoryStick}>
|
|
173
|
+
{last ? `${bytes(last.memoryUsed)} of ${bytes(last.memoryTotal)}` : dash}
|
|
174
|
+
</Widget.MetaItem>
|
|
175
|
+
) : (
|
|
176
|
+
<Widget.MetaItem icon={Cpu}>{last ? `${percent(last.cpu)} CPU` : dash}</Widget.MetaItem>
|
|
177
|
+
)}
|
|
178
|
+
<Widget.MetaItem icon={ArrowDown}>{last ? rate(last.netIn) : dash}</Widget.MetaItem>
|
|
179
|
+
<Widget.MetaItem icon={ArrowUp}>{last ? rate(last.netOut) : dash}</Widget.MetaItem>
|
|
180
|
+
</Widget.Meta>
|
|
181
|
+
{(battery || disk) && (
|
|
182
|
+
<Widget.Meta>
|
|
183
|
+
{battery && <BatteryItem battery={battery} />}
|
|
184
|
+
{disk && <Widget.MetaItem icon={HardDrive}>{bytes(disk.free)} free</Widget.MetaItem>}
|
|
185
|
+
</Widget.Meta>
|
|
186
|
+
)}
|
|
187
|
+
</div>
|
|
188
|
+
)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function Processes({ processes }: { processes: StatsProcess[] }) {
|
|
192
|
+
const top = [...processes].sort((a, b) => b.cpu - a.cpu)
|
|
193
|
+
const more = top.length - ROWS
|
|
194
|
+
return (
|
|
195
|
+
<Widget.Section label="Top processes" trailing={<span>CPU · memory</span>}>
|
|
196
|
+
{top.slice(0, ROWS).map(process => (
|
|
197
|
+
<Widget.Row
|
|
198
|
+
key={process.id}
|
|
199
|
+
leading={share(process.cpu)}
|
|
200
|
+
trailing={process.memory !== undefined && bytes(process.memory)}
|
|
201
|
+
>
|
|
202
|
+
{process.name}
|
|
203
|
+
</Widget.Row>
|
|
204
|
+
))}
|
|
205
|
+
{more > 0 && (
|
|
206
|
+
<span className="flex h-6 items-center pl-17.5 text-caption text-muted-foreground">{more} more</span>
|
|
207
|
+
)}
|
|
208
|
+
</Widget.Section>
|
|
209
|
+
)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** The compact island's left wing: the CPU glyph. */
|
|
213
|
+
function SystemStatsLeading() {
|
|
214
|
+
return <Cpu size={16} strokeWidth={1.5} className="text-muted-foreground" />
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** The compact island's right wing: the CPU load, a dash until the first reading. */
|
|
218
|
+
function SystemStatsTrailing({ sample }: { sample?: StatsSample }) {
|
|
219
|
+
if (!sample) return <span className="text-caption weight-semibold text-muted-foreground">–</span>
|
|
220
|
+
return <span className="text-caption weight-semibold tabular-nums text-foreground">{percent(sample.cpu)}</span>
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** The split island's bubble: the CPU load as a ring, in the warning hue from 75% and the error hue from 90%. */
|
|
224
|
+
function SystemStatsMinimal({ sample }: { sample?: StatsSample }) {
|
|
225
|
+
const load = sample?.cpu ?? 0
|
|
226
|
+
return (
|
|
227
|
+
<Meter
|
|
228
|
+
variant="ring"
|
|
229
|
+
className="size-5.5"
|
|
230
|
+
size="compact"
|
|
231
|
+
value={load}
|
|
232
|
+
label={sample ? `CPU, ${percent(load)}` : 'CPU, measuring'}
|
|
233
|
+
/>
|
|
234
|
+
)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* A notch app's system load: the busiest figure as the hero with its trend,
|
|
239
|
+
* the rest as facts, and the processes behind it.
|
|
240
|
+
*
|
|
241
|
+
* The hero is the CPU load, set large, with every reading so far as a
|
|
242
|
+
* modo-ui Sparkline beside it (it spans the width however many readings
|
|
243
|
+
* there are: the island stays open for seconds, too short to fill a fixed
|
|
244
|
+
* window). The line turns to the warning hue from 75% and the error hue
|
|
245
|
+
* from 90%, so the color comes from the load. When memory is what's tight,
|
|
246
|
+
* `hero="memory"` makes memory pressure the figure and its trend instead.
|
|
247
|
+
* Under it one word for how the machine is doing and who's busiest, then
|
|
248
|
+
* the facts: memory in use of all of it (or the CPU), the network's in and
|
|
249
|
+
* out rates, and, when given, the battery with its time left and the
|
|
250
|
+
* startup disk's free space. The uptime sits on the context line.
|
|
251
|
+
*
|
|
252
|
+
* Beside it, past a hairline, the busiest processes by CPU with the memory
|
|
253
|
+
* they hold, three at most and a count of the rest.
|
|
254
|
+
*
|
|
255
|
+
* CPU and network are rates between two readings, so before the first one
|
|
256
|
+
* lands (about a second after opening) the figures are dashes over the
|
|
257
|
+
* Sparkline's baseline.
|
|
258
|
+
*
|
|
259
|
+
* `SystemStats.Leading` and `SystemStats.Trailing` show the CPU load in the
|
|
260
|
+
* compact island's wings, `SystemStats.Minimal` as a ring in the split
|
|
261
|
+
* island's bubble.
|
|
262
|
+
*
|
|
263
|
+
* @example {@include ./examples.mdx}
|
|
264
|
+
*/
|
|
265
|
+
const SystemStats = Object.assign(
|
|
266
|
+
function SystemStats({ samples, hero = 'cpu', battery, disk, uptime, processes, size, className }: SystemStatsProps) {
|
|
267
|
+
const last = samples.at(-1)
|
|
268
|
+
const series = hero === 'cpu' ? samples.map(s => s.cpu) : samples.map(pressureOf)
|
|
269
|
+
const load = last ? (hero === 'cpu' ? last.cpu : pressureOf(last)) : 0
|
|
270
|
+
const name = hero === 'cpu' ? 'CPU' : 'Memory pressure'
|
|
271
|
+
const busiest = processes?.length ? processes.reduce((a, b) => (b.cpu > a.cpu ? b : a)).name : undefined
|
|
272
|
+
|
|
273
|
+
return (
|
|
274
|
+
<Widget
|
|
275
|
+
size={size}
|
|
276
|
+
className={cn('h-full', className)}
|
|
277
|
+
aside={processes?.length ? <Processes processes={processes} /> : undefined}
|
|
278
|
+
>
|
|
279
|
+
<Widget.Header icon={Activity}>{uptime === undefined ? 'System' : `System · up ${span(uptime)}`}</Widget.Header>
|
|
280
|
+
<div className="flex min-w-0 items-end gap-4" aria-busy={!last}>
|
|
281
|
+
<Widget.Figure
|
|
282
|
+
value={last ? percent(load) : '–'}
|
|
283
|
+
unit={hero === 'cpu' ? 'CPU' : 'pressure'}
|
|
284
|
+
className="shrink-0"
|
|
285
|
+
/>
|
|
286
|
+
<Sparkline
|
|
287
|
+
values={series}
|
|
288
|
+
max={1}
|
|
289
|
+
area
|
|
290
|
+
tone={toneOf(load)}
|
|
291
|
+
label={last ? `${name}, ${percent(load)}` : `${name}, measuring`}
|
|
292
|
+
className={cn('mb-1.5 h-9 min-w-0 flex-1', !last && 'text-muted-foreground')}
|
|
293
|
+
/>
|
|
294
|
+
</div>
|
|
295
|
+
<Widget.Subtitle className="mb-1">
|
|
296
|
+
{last ? [verdict(load), busiest && `${busiest} is busiest`].filter(Boolean).join(' · ') : 'Measuring…'}
|
|
297
|
+
</Widget.Subtitle>
|
|
298
|
+
<Facts last={last} hero={hero} battery={battery} disk={disk} />
|
|
299
|
+
</Widget>
|
|
300
|
+
)
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
Leading: SystemStatsLeading,
|
|
304
|
+
Trailing: SystemStatsTrailing,
|
|
305
|
+
Minimal: SystemStatsMinimal,
|
|
306
|
+
},
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
export default SystemStats
|
|
310
|
+
|
|
311
|
+
export type { StatsBattery, StatsDisk, StatsHero, StatsProcess, StatsSample, SystemStatsProps }
|
|
312
|
+
export { SystemStats, SystemStatsLeading, SystemStatsMinimal, SystemStatsTrailing }
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import Countdown from './index'
|
|
2
|
+
|
|
3
|
+
# Clock
|
|
4
|
+
|
|
5
|
+
`4:05`, a digit at a time on the second's edge.
|
|
6
|
+
|
|
7
|
+
<div className="flex items-center gap-6 text-subtitle weight-semibold">
|
|
8
|
+
<Countdown duration={245000} />
|
|
9
|
+
<Countdown duration={3725000} />
|
|
10
|
+
</div>
|
|
11
|
+
|
|
12
|
+
# Short
|
|
13
|
+
|
|
14
|
+
The largest unit, for a compact wing: minutes, then seconds in the last minute.
|
|
15
|
+
|
|
16
|
+
<div className="dark flex items-center gap-6 rounded-box bg-ink px-5 py-3 text-caption weight-medium text-status-warning">
|
|
17
|
+
<Countdown duration={240000} format="short" />
|
|
18
|
+
<Countdown duration={45000} format="short" />
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
# Paused
|
|
22
|
+
|
|
23
|
+
It holds the time left.
|
|
24
|
+
|
|
25
|
+
<Countdown paused remaining={754000} className="text-subtitle weight-semibold text-muted-foreground" />
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Local addition: the time left on a notch app's timer, as text that ticks
|
|
3
|
+
* only on second edges. Rebuilt from Just Notch's timer plugin (`Countdown`,
|
|
4
|
+
* `useRemaining`).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use client'
|
|
8
|
+
|
|
9
|
+
import { cn } from '@justanarthur/modo-ui/lib/utils'
|
|
10
|
+
import { useEffect, useMemo, useRef, useState } from 'react'
|
|
11
|
+
import { formatClock, formatShort, MINUTE, SECOND, useEdgeClock } from '../../../lib/clock'
|
|
12
|
+
|
|
13
|
+
type CountdownFormat = 'clock' | 'short'
|
|
14
|
+
|
|
15
|
+
interface CountdownProps {
|
|
16
|
+
/** When it ends, in epoch ms. */
|
|
17
|
+
endsAt?: number
|
|
18
|
+
/** How long it runs from when it mounts, in ms, when there is no `endsAt`. Defaults to `0`. */
|
|
19
|
+
duration?: number
|
|
20
|
+
/** Stop the clock: it holds the time left when it paused, or `remaining`. Defaults to `false`. */
|
|
21
|
+
paused?: boolean
|
|
22
|
+
/** The time left to show while paused, in ms. */
|
|
23
|
+
remaining?: number
|
|
24
|
+
/** `clock` is `4:05`; `short` is the largest unit, rounded up: `4m`, then `45s` in the last minute. Defaults to `'clock'`. */
|
|
25
|
+
format?: CountdownFormat
|
|
26
|
+
/** Called once when it reaches zero. */
|
|
27
|
+
onEnd?: () => void
|
|
28
|
+
/** Classes for the text, such as its role and weight. */
|
|
29
|
+
className?: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The time left, as text: `4:05`, or `4m` where room is short (a compact
|
|
34
|
+
* wing).
|
|
35
|
+
*
|
|
36
|
+
* It re-renders once per shown unit, on the unit's edge counted from the end,
|
|
37
|
+
* never in between: a second for the clock, a minute for the short form until
|
|
38
|
+
* its last minute. So a running timer costs one render a second at most, and
|
|
39
|
+
* the digits change exactly when a second has passed. Digits are tabular, so
|
|
40
|
+
* the text holds its width as it ticks. Paused, it holds the time left.
|
|
41
|
+
*
|
|
42
|
+
* @example {@include ./examples.mdx}
|
|
43
|
+
*/
|
|
44
|
+
export default function Countdown({
|
|
45
|
+
endsAt,
|
|
46
|
+
duration = 0,
|
|
47
|
+
paused = false,
|
|
48
|
+
remaining,
|
|
49
|
+
format = 'clock',
|
|
50
|
+
onEnd,
|
|
51
|
+
className,
|
|
52
|
+
}: CountdownProps) {
|
|
53
|
+
const [mounted] = useState(Date.now)
|
|
54
|
+
const end = endsAt ?? mounted + duration
|
|
55
|
+
const [coarse, setCoarse] = useState(format === 'short' && end - Date.now() > MINUTE)
|
|
56
|
+
// Past the end there is nothing left to tick.
|
|
57
|
+
const now = useEdgeClock(end, !paused && Date.now() < end + SECOND, coarse ? MINUTE : SECOND)
|
|
58
|
+
const pausedLeft = useMemo(() => end - Date.now(), [paused, end])
|
|
59
|
+
const left = Math.max(0, paused ? (remaining ?? pausedLeft) : end - now)
|
|
60
|
+
|
|
61
|
+
useEffect(() => setCoarse(format === 'short' && left > MINUTE), [format, left])
|
|
62
|
+
|
|
63
|
+
const ended = useRef(false)
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
if (left > 0 || paused) {
|
|
66
|
+
ended.current = false
|
|
67
|
+
return
|
|
68
|
+
}
|
|
69
|
+
if (ended.current) return
|
|
70
|
+
ended.current = true
|
|
71
|
+
onEnd?.()
|
|
72
|
+
}, [left, paused, onEnd])
|
|
73
|
+
|
|
74
|
+
const seconds = left / SECOND
|
|
75
|
+
return (
|
|
76
|
+
<span role="timer" className={cn('tabular-nums', className)}>
|
|
77
|
+
{format === 'short' ? formatShort(seconds) : formatClock(Math.ceil(seconds))}
|
|
78
|
+
</span>
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export type { CountdownFormat, CountdownProps }
|
|
83
|
+
export { Countdown }
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import Equalizer from './index'
|
|
2
|
+
|
|
3
|
+
# Playing and paused
|
|
4
|
+
|
|
5
|
+
Playing, each bar loops at its own pace; paused, they settle low.
|
|
6
|
+
|
|
7
|
+
<div className="dark flex items-center gap-6 rounded-box bg-ink px-5 py-3 text-foreground">
|
|
8
|
+
<Equalizer label="Playing" />
|
|
9
|
+
<Equalizer playing={false} label="Paused" />
|
|
10
|
+
</div>
|
|
11
|
+
|
|
12
|
+
# Tinted
|
|
13
|
+
|
|
14
|
+
Any fill through `barClassName`, such as the artwork's tint, and fewer or more bars.
|
|
15
|
+
|
|
16
|
+
<div className="flex items-center gap-6">
|
|
17
|
+
<Equalizer barClassName="bg-status-success" bars={3} />
|
|
18
|
+
<Equalizer barClassName="bg-brand" bars={5} className="h-5" />
|
|
19
|
+
<Equalizer barClassName="bg-muted-foreground" />
|
|
20
|
+
</div>
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Local addition: the now-playing level bars of a notch app's compact wing.
|
|
3
|
+
* Rebuilt from Just Notch's now-playing plugin (`Bars`).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use client'
|
|
7
|
+
|
|
8
|
+
import { useReduceMotion } from '@justanarthur/modo-ui/lib/reduced-motion'
|
|
9
|
+
import { spring } from '@justanarthur/modo-ui/lib/springs'
|
|
10
|
+
import { cn } from '@justanarthur/modo-ui/lib/utils'
|
|
11
|
+
import { motion } from 'motion/react'
|
|
12
|
+
import { useEffect, useRef } from 'react'
|
|
13
|
+
|
|
14
|
+
// Each bar loops its own levels at its own pace, so together they read as random.
|
|
15
|
+
const LOOPS = [
|
|
16
|
+
{ levels: [0.35, 1, 0.5, 0.8, 0.35], beats: 5 },
|
|
17
|
+
{ levels: [0.7, 0.4, 0.95, 0.55, 0.7], beats: 4 },
|
|
18
|
+
{ levels: [0.5, 0.9, 0.3, 1, 0.5], beats: 6 },
|
|
19
|
+
{ levels: [0.4, 0.75, 0.6, 0.3, 0.4], beats: 4.5 },
|
|
20
|
+
{ levels: [0.6, 0.3, 0.85, 0.45, 0.6], beats: 5.5 },
|
|
21
|
+
]
|
|
22
|
+
const REST = 0.2
|
|
23
|
+
const STILL = [0.5, 0.85, 0.65, 0.4, 0.7]
|
|
24
|
+
|
|
25
|
+
interface EqualizerProps {
|
|
26
|
+
/** Music is playing: the bars move. Paused, they settle low. Defaults to `true`. */
|
|
27
|
+
playing?: boolean
|
|
28
|
+
/** How many bars, from 1 to 5. Defaults to `4`. */
|
|
29
|
+
bars?: number
|
|
30
|
+
/** What screen readers hear. Without one the bars are hidden from them. */
|
|
31
|
+
label?: string
|
|
32
|
+
/** Classes for the bars' fill. Defaults to `'bg-foreground'`. */
|
|
33
|
+
barClassName?: string
|
|
34
|
+
/** Classes for the row, such as its height. Defaults to `'h-3.5'`. */
|
|
35
|
+
className?: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface BarProps {
|
|
39
|
+
loop: (typeof LOOPS)[number]
|
|
40
|
+
live: boolean
|
|
41
|
+
level: number
|
|
42
|
+
className: string
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Playing, the bar loops on the Web Animations API: a `transform` keyframe loop the compositor runs, no JS per frame. */
|
|
46
|
+
function Bar({ loop, live, level, className }: BarProps) {
|
|
47
|
+
const ref = useRef<HTMLSpanElement>(null)
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
const bar = ref.current
|
|
51
|
+
if (!live || !bar) return
|
|
52
|
+
const animation = bar.animate(
|
|
53
|
+
loop.levels.map(l => ({ transform: `scaleY(${l})` })),
|
|
54
|
+
{
|
|
55
|
+
duration: spring.slow.duration * loop.beats * 1000,
|
|
56
|
+
easing: 'ease-in-out',
|
|
57
|
+
iterations: Number.POSITIVE_INFINITY,
|
|
58
|
+
},
|
|
59
|
+
)
|
|
60
|
+
return () => animation.cancel()
|
|
61
|
+
}, [live, loop])
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<motion.span
|
|
65
|
+
ref={ref}
|
|
66
|
+
className={cn('h-full w-0.75 rounded-full', className)}
|
|
67
|
+
initial={false}
|
|
68
|
+
animate={{ scaleY: level }}
|
|
69
|
+
transition={spring.moderate}
|
|
70
|
+
/>
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Level bars for what's playing: they dance while music plays and settle low
|
|
76
|
+
* when it pauses.
|
|
77
|
+
*
|
|
78
|
+
* Each bar loops its own levels at its own pace on the Web Animations API, a
|
|
79
|
+
* `transform` loop the compositor runs, so playing music costs no JavaScript
|
|
80
|
+
* per frame. Pausing springs the bars down to rest; under reduced motion they
|
|
81
|
+
* hold still at a level instead of dancing. They take the text color, or any
|
|
82
|
+
* fill through `barClassName` (an artwork's tint).
|
|
83
|
+
*
|
|
84
|
+
* @example {@include ./examples.mdx}
|
|
85
|
+
*/
|
|
86
|
+
export default function Equalizer({
|
|
87
|
+
playing = true,
|
|
88
|
+
bars = 4,
|
|
89
|
+
label,
|
|
90
|
+
barClassName = 'bg-foreground',
|
|
91
|
+
className,
|
|
92
|
+
}: EqualizerProps) {
|
|
93
|
+
const reduced = useReduceMotion()
|
|
94
|
+
const live = playing && !reduced
|
|
95
|
+
const count = Math.min(Math.max(1, Math.round(bars)), LOOPS.length)
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<span
|
|
99
|
+
{...(label ? { role: 'img', 'aria-label': label } : { 'aria-hidden': true })}
|
|
100
|
+
className={cn('inline-flex h-3.5 shrink-0 items-center gap-0.5', className)}
|
|
101
|
+
>
|
|
102
|
+
{LOOPS.slice(0, count).map((loop, i) => (
|
|
103
|
+
<Bar
|
|
104
|
+
key={loop.beats}
|
|
105
|
+
loop={loop}
|
|
106
|
+
live={live}
|
|
107
|
+
level={playing ? (STILL[i] ?? REST) : REST}
|
|
108
|
+
className={barClassName}
|
|
109
|
+
/>
|
|
110
|
+
))}
|
|
111
|
+
</span>
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export type { EqualizerProps }
|
|
116
|
+
export { Equalizer }
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import MediaScrubber from './index'
|
|
2
|
+
|
|
3
|
+
# Playing
|
|
4
|
+
|
|
5
|
+
Elapsed, the scrubber and the time remaining, running on a second at a time. Drag to seek.
|
|
6
|
+
|
|
7
|
+
<div className="dark w-full max-w-md rounded-box bg-ink px-5 py-4 text-foreground">
|
|
8
|
+
<MediaScrubber position={71} duration={243} playing />
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
# Paused
|
|
12
|
+
|
|
13
|
+
<div className="w-full max-w-md">
|
|
14
|
+
<MediaScrubber position={190} duration={258} />
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
# Default size
|
|
18
|
+
|
|
19
|
+
<div className="w-full max-w-md">
|
|
20
|
+
<MediaScrubber position={12} duration={330} size="default" />
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
# Quiet
|
|
24
|
+
|
|
25
|
+
`quiet` shows a thin line of progress at rest; hover or focus it and the scrubber fades in to seek. Touch always gets the scrubber.
|
|
26
|
+
|
|
27
|
+
<div className="dark w-full max-w-md rounded-box bg-ink px-5 py-4 text-foreground">
|
|
28
|
+
<MediaScrubber position={71} duration={243} playing quiet />
|
|
29
|
+
</div>
|