@@ -2,12 +2,14 @@ import {
22 collectLimitAccounts ,
33 collectLimitNotices ,
44 collectLimitPools ,
5+ evenPacePercent ,
56 formatDuration ,
67 formatResetsIn ,
78 type LimitAccount ,
89 type LimitPool ,
910 type LimitPoolMember ,
1011 type LimitPoolWindow ,
12+ paceGapLabel ,
1113 remainingPercent ,
1214} from "@t3tools/shared/usageLimits" ;
1315import { TicketIcon } from "lucide-react" ;
@@ -147,6 +149,7 @@ function SegmentPopover({
147149} ) {
148150 const timestampFormat = usePrimarySettings ( ( settings ) => settings . timestampFormat ) ;
149151 const remaining = remainingPercent ( window ) ;
152+ const evenPace = evenPacePercent ( window , now ) ;
150153 const resetsIn = formatResetsIn ( window , now ) ;
151154 const where =
152155 account . environments . length > 0
@@ -181,6 +184,11 @@ function SegmentPopover({
181184 </ div >
182185 < div className = "flex flex-col gap-1 border-t border-border/60 pt-2.5" >
183186 < Row label = "Left" > { remaining } %</ Row >
187+ { evenPace !== null ? (
188+ < Row label = "Even pace" >
189+ { evenPace } % < span className = "text-muted-foreground" > · { paceGapLabel ( window , now ) } </ span >
190+ </ Row >
191+ ) : null }
184192 { window . resetsAt ? (
185193 < Row label = "Resets" >
186194 { formatUpcomingTimestamp ( window . resetsAt , timestampFormat , now ) }
@@ -211,6 +219,26 @@ function SegmentPopover({
211219 ) ;
212220}
213221
222+ /**
223+ * Where even spending would have left the fill, as a tick above and below the
224+ * segment rather than a line across it: the segment's own label runs the full
225+ * width, and a mark outside the bar reads at a glance without competing with it.
226+ * The provider colour ties it to the fill it is measured against.
227+ *
228+ * The tick is shorter than the room its wrapper reserves, and the difference is
229+ * the gap that keeps it reading as a tick. Flush against the bar, the two run
230+ * together into one line.
231+ */
232+ function EvenPaceTicks ( { at, color } : { readonly at : number ; readonly color : string } ) {
233+ const tick = "absolute w-px -translate-x-1/2 h-1.5 @2xl/pool:h-2" ;
234+ return (
235+ < span aria-hidden className = "pointer-events-none" >
236+ < span className = { cn ( tick , "top-0" ) } style = { { left : `${ at } %` , backgroundColor : color } } />
237+ < span className = { cn ( tick , "bottom-0" ) } style = { { left : `${ at } %` , backgroundColor : color } } />
238+ </ span >
239+ ) ;
240+ }
241+
214242/**
215243 * One account's share of one pooled window: the segment, its popover, and the
216244 * reset confirm. The confirm is a sibling of the popover, not a child: dialogs
@@ -234,66 +262,81 @@ function PoolSegment({
234262} ) {
235263 const [ open , setOpen ] = useState ( false ) ;
236264 const remaining = remainingPercent ( window ) ;
265+ const evenPace = evenPacePercent ( window , now ) ;
237266 const resetsIn = formatResetsIn ( window , now ) ;
238267 const credits = account . limits . resetCredits ?. availableCount ?? 0 ;
239268 return (
240269 < Popover open = { open } onOpenChange = { setOpen } >
241- < PopoverTrigger
242- openOnHover
243- render = {
244- < button
245- type = "button"
246- style = { { gridColumn : index , gridRow : 1 } }
247- aria-label = { `${ account . displayName ?? ( account . email ? accountInitials ( account . email ) : account . driver ) } : ${ remaining } % left${ resetsIn ? `, ${ resetsIn } ` : "" } ${ credits ? `, ${ credits } reset ${ credits === 1 ? "credit" : "credits" } banked` : "" } ` }
248- className = "relative h-5 min-w-0 cursor-pointer overflow-hidden rounded-md bg-muted text-start outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background data-[popup-open]:ring-1 data-[popup-open]:ring-border @2xl/pool:h-8"
249- />
250- }
270+ { /* The wrapper reserves the ticks' room and their gap; the segment clips its fill, so they
271+ cannot live inside it. Centring the segment keeps both gaps equal whatever height the
272+ grid row takes, and makes the button a flex item, which drops the baseline space an
273+ inline-level button would otherwise add under it. */ }
274+ < div
275+ className = "relative flex min-w-0 flex-col justify-center py-2.5 @2xl/pool:py-3"
276+ style = { { gridColumn : index , gridRow : 1 } }
251277 >
252- { /* Translucent so the label reads over the fill for any provider colour and theme. */ }
253- < div
254- aria-hidden
255- className = "absolute inset-y-0 left-0 rounded-md opacity-35"
256- style = { { width : `${ remaining } %` , backgroundColor : color } }
257- />
258- { /* The spent share is hatched, not blank: it is what the countdown restores. */ }
259- { remaining < 100 && reset ? (
278+ < PopoverTrigger
279+ openOnHover
280+ render = {
281+ < button
282+ type = "button"
283+ aria-label = { `${ account . displayName ?? ( account . email ? accountInitials ( account . email ) : account . driver ) } : ${ remaining } % left${ evenPace === null ? "" : `, ${ evenPace } % at even pace` } ${ resetsIn ? `, ${ resetsIn } ` : "" } ${ credits ? `, ${ credits } reset ${ credits === 1 ? "credit" : "credits" } banked` : "" } ` }
284+ className = "relative h-5 w-full min-w-0 shrink-0 cursor-pointer overflow-hidden rounded-md bg-muted text-start outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background data-[popup-open]:ring-1 data-[popup-open]:ring-border @2xl/pool:h-8"
285+ />
286+ }
287+ >
288+ { /* Translucent so the label reads over the fill for any provider colour and theme. */ }
260289 < div
261290 aria-hidden
262- className = "absolute inset-y-0 right-0 opacity-20"
263- style = { {
264- width : `${ 100 - remaining } %` ,
265- backgroundImage : `repeating-linear-gradient(135deg, ${ color } 0 1px, transparent 1px 5px)` ,
266- } }
291+ className = "absolute inset-y-0 left-0 rounded-md opacity-35"
292+ style = { { width : `${ remaining } %` , backgroundColor : color } }
267293 />
268- ) : null }
269- < span
270- aria-hidden
271- className = "absolute inset-0 flex items-center justify-center text-[10px] leading-none font-semibold text-foreground/80 tabular-nums @2xl/pool:hidden"
272- >
273- { index }
274- </ span >
275- < div className = "relative hidden h-full min-w-0 items-center gap-1.5 px-2 text-xs @2xl/pool:flex" >
276- < AccountName account = { account } className = "min-w-0 truncate font-medium text-foreground" />
277- < span className = "shrink-0 font-semibold text-foreground tabular-nums" > { remaining } %</ span >
278- { /* Countdown and badge get their own plate: fill and hatching run under them otherwise. */ }
279- < span className = "ms-auto flex shrink-0 items-center gap-1.5 rounded-sm bg-background/85 px-1.5 py-0.5 text-[11px] text-foreground tabular-nums" >
280- { resetsIn ?. replace ( "resets in " , "↻ " ) ?? "" }
281- { credits ? (
282- < >
283- { resetsIn ? (
284- < span aria-hidden className = "text-muted-foreground" >
285- ·
286- </ span >
287- ) : null }
288- < span aria-hidden className = "inline-flex items-center gap-0.5 font-semibold" >
289- < TicketIcon className = "size-3" aria-hidden />
290- { credits }
291- </ span >
292- </ >
293- ) : null }
294+ { /* The spent share is hatched, not blank: it is what the countdown restores. */ }
295+ { remaining < 100 && reset ? (
296+ < div
297+ aria-hidden
298+ className = "absolute inset-y-0 right-0 opacity-20"
299+ style = { {
300+ width : `${ 100 - remaining } %` ,
301+ backgroundImage : `repeating-linear-gradient(135deg, ${ color } 0 1px, transparent 1px 5px)` ,
302+ } }
303+ />
304+ ) : null }
305+ < span
306+ aria-hidden
307+ className = "absolute inset-0 flex items-center justify-center text-[10px] leading-none font-semibold text-foreground/80 tabular-nums @2xl/pool:hidden"
308+ >
309+ { index }
294310 </ span >
295- </ div >
296- </ PopoverTrigger >
311+ < div className = "relative hidden h-full min-w-0 items-center gap-1.5 px-2 text-xs @2xl/pool:flex" >
312+ < AccountName
313+ account = { account }
314+ className = "min-w-0 truncate font-medium text-foreground"
315+ />
316+ < span className = "shrink-0 font-semibold text-foreground tabular-nums" >
317+ { remaining } %
318+ </ span >
319+ { /* Countdown and badge get their own plate: fill and hatching run under them otherwise. */ }
320+ < span className = "ms-auto flex shrink-0 items-center gap-1.5 rounded-sm bg-background/85 px-1.5 py-0.5 text-[11px] text-foreground tabular-nums" >
321+ { resetsIn ?. replace ( "resets in " , "↻ " ) ?? "" }
322+ { credits ? (
323+ < >
324+ { resetsIn ? (
325+ < span aria-hidden className = "text-muted-foreground" >
326+ ·
327+ </ span >
328+ ) : null }
329+ < span aria-hidden className = "inline-flex items-center gap-0.5 font-semibold" >
330+ < TicketIcon className = "size-3" aria-hidden />
331+ { credits }
332+ </ span >
333+ </ >
334+ ) : null }
335+ </ span >
336+ </ div >
337+ </ PopoverTrigger >
338+ { evenPace !== null ? < EvenPaceTicks at = { evenPace } color = { color } /> : null }
339+ </ div >
297340 < LegendRow account = { account } window = { window } color = { color } now = { now } index = { index } />
298341 { account . redeem ? (
299342 < RedeemableSegmentPopup
0 commit comments