@@ -43,6 +43,7 @@ const COLORS = {
4343
4444const BADGE_PADDING_X = 8
4545const MIN_BADGE_TEXT_WIDTH = 40
46+ const FALLBACK_VALUE_EXTRA_PADDING_X = 4
4647const SHIELDS_LABEL_PADDING_X = 5
4748
4849const BADGE_FONT_SHORTHAND = 'normal normal 400 11px Geist, system-ui, -apple-system, sans-serif'
@@ -132,14 +133,17 @@ function measureTextWidth(text: string, font: string): number | null {
132133 return null
133134}
134135
135- function measureDefaultTextWidth ( text : string ) : number {
136+ function measureDefaultTextWidth ( text : string , fallbackExtraPadding = 0 ) : number {
136137 const measuredWidth = measureTextWidth ( text , BADGE_FONT_SHORTHAND )
137138
138139 if ( measuredWidth !== null ) {
139140 return Math . max ( MIN_BADGE_TEXT_WIDTH , measuredWidth + BADGE_PADDING_X * 2 )
140141 }
141142
142- return Math . max ( MIN_BADGE_TEXT_WIDTH , estimateTextWidth ( text , 'default' ) + BADGE_PADDING_X * 2 )
143+ return Math . max (
144+ MIN_BADGE_TEXT_WIDTH ,
145+ estimateTextWidth ( text , 'default' ) + BADGE_PADDING_X * 2 + fallbackExtraPadding ,
146+ )
143147}
144148
145149function escapeXML ( str : string ) : string {
@@ -188,7 +192,7 @@ function renderDefaultBadgeSvg(params: {
188192 const { finalColor, finalLabel, finalLabelColor, finalValue, labelTextColor, valueTextColor } =
189193 params
190194 const leftWidth = finalLabel . trim ( ) . length === 0 ? 0 : measureDefaultTextWidth ( finalLabel )
191- const rightWidth = measureDefaultTextWidth ( finalValue )
195+ const rightWidth = measureDefaultTextWidth ( finalValue , FALLBACK_VALUE_EXTRA_PADDING_X )
192196 const totalWidth = leftWidth + rightWidth
193197 const height = 20
194198 const escapedLabel = escapeXML ( finalLabel )
0 commit comments