@@ -18,9 +18,10 @@ import {
1818 remainingPercent ,
1919} from "@t3tools/shared/usageLimits" ;
2020import { GaugeIcon , TrendingDownIcon , TrendingUpIcon } from "lucide-react" ;
21- import { Fragment , type ReactNode , useState } from "react" ;
21+ import { Fragment , type ReactNode , useLayoutEffect , useState } from "react" ;
2222
2323import { usePrimarySettings } from "../../hooks/useSettings" ;
24+ import { observeResize } from "../../lib/observeResize" ;
2425import { environmentPresentations } from "../../state/presentation" ;
2526import { useEnvironmentScope , readEnvironmentScope } from "../../state/session" ;
2627import { serverEnvironment } from "../../state/server" ;
@@ -73,6 +74,43 @@ export function PaceIcon({ pace }: { readonly pace: LimitPace }) {
7374 ) ;
7475}
7576
77+ // The tick sits in a transparent gap cut from the bar, clamped so it stays inside at 0% and 100%.
78+ // The gap is a clip-path slot rather than a mask: a mask composites its layer and re-antialiases
79+ // the bar's rounded ends, and the polygon reaches 1px past the box so only the slot edges clip.
80+ function paceMarkStyles ( timeLeft : number | null ) {
81+ if ( timeLeft === null ) return null ;
82+ const at = `clamp(3px, ${ timeLeft } %, calc(100% - 3px))` ;
83+ const [ left , right ] = [ `calc(${ at } - 3px)` , `calc(${ at } + 3px)` ] ;
84+ const [ near , far ] = [ "-1px" , "calc(100% + 1px)" ] ;
85+ return {
86+ tick : { left : at } ,
87+ gap : {
88+ clipPath : `polygon(${ near } ${ near } , ${ left } ${ near } , ${ left } ${ far } , ${ right } ${ far } , ${ right } ${ near } , ${ far } ${ near } , ${ far } ${ far } , ${ near } ${ far } )` ,
89+ } ,
90+ // For a track painted on an element that also draws focus rings, which a clip would cut.
91+ gappedTrack : {
92+ backgroundColor : "transparent" ,
93+ backgroundImage : `linear-gradient(to right, var(--color-muted) ${ left } , transparent ${ left } , transparent ${ right } , var(--color-muted) ${ right } )` ,
94+ } ,
95+ } ;
96+ }
97+
98+ /**
99+ * Pace mark styles for the bar given the returned ref. Below 6px there is no room for the gap
100+ * and tick, so the bar draws neither, as the mobile bars do.
101+ */
102+ export function usePaceMark ( timeLeft : number | null ) {
103+ const [ bar , setBar ] = useState < HTMLElement | null > ( null ) ;
104+ const [ roomy , setRoomy ] = useState ( false ) ;
105+ useLayoutEffect ( ( ) => {
106+ if ( ! bar ) return ;
107+ const measure = ( ) => setRoomy ( bar . getBoundingClientRect ( ) . width >= 6 ) ;
108+ measure ( ) ;
109+ return observeResize ( bar , measure ) ;
110+ } , [ bar ] ) ;
111+ return [ setBar , roomy ? paceMarkStyles ( timeLeft ) : null ] as const ;
112+ }
113+
76114function WindowBar ( {
77115 color,
78116 window,
@@ -85,6 +123,7 @@ function WindowBar({
85123 const timestampFormat = usePrimarySettings ( ( settings ) => settings . timestampFormat ) ;
86124 const remaining = remainingPercent ( window ) ;
87125 const timeLeft = paceRemainingPercent ( window , now ) ;
126+ const [ barRef , paceMark ] = usePaceMark ( timeLeft ) ;
88127 const resetsIn = formatResetsIn ( window , now ) ;
89128 const resetsAt = window . resetsAt
90129 ? formatUpcomingTimestamp ( window . resetsAt , timestampFormat , now )
@@ -98,25 +137,29 @@ function WindowBar({
98137 < TooltipTrigger
99138 render = {
100139 < div
140+ ref = { barRef }
101141 role = "img"
102142 aria-label = { summary }
103143 tabIndex = { 0 }
104144 className = "relative h-6 cursor-default rounded-full outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
105145 />
106146 }
107147 >
108- < div className = "absolute inset-x-0 inset-y-1.5 rounded-full bg-muted" />
109- { remaining > 0 ? (
110- < div
111- className = "absolute inset-y-1.5 left-0 rounded-full"
112- style = { { width : `${ remaining } %` , backgroundColor : color } }
113- />
114- ) : null }
115- { timeLeft !== null ? (
148+ { /* Clip both layers so the gap exposes even a translucent composer surface. */ }
149+ < div className = "absolute inset-0" style = { paceMark ?. gap } >
150+ < div className = "absolute inset-x-0 inset-y-1.5 rounded-full bg-muted" />
151+ { remaining > 0 ? (
152+ < div
153+ className = "absolute inset-y-1.5 left-0 rounded-full"
154+ style = { { width : `${ remaining } %` , backgroundColor : color } }
155+ />
156+ ) : null }
157+ </ div >
158+ { paceMark ? (
116159 < span
117160 aria-hidden
118- className = "absolute inset-y-0.5 w-px - translate-x-1/2 bg-foreground/60 "
119- style = { { left : ` ${ timeLeft } %` } }
161+ className = "absolute inset-y-1 w- 0.5 - translate-x-1/2 rounded-full bg-foreground"
162+ style = { paceMark . tick }
120163 />
121164 ) : null }
122165 </ TooltipTrigger >
0 commit comments