@@ -14,6 +14,8 @@ const NPMS_API = 'https://api.npms.io/v2/package'
1414const QUERY_SCHEMA = v . object ( {
1515 color : v . optional ( v . string ( ) ) ,
1616 name : v . optional ( v . string ( ) ) ,
17+ labelColor : v . optional ( v . string ( ) ) ,
18+ label : v . optional ( v . string ( ) ) ,
1719} )
1820
1921const COLORS = {
@@ -263,7 +265,9 @@ export default defineCachedEventHandler(
263265
264266 const queryParams = v . safeParse ( QUERY_SCHEMA , query )
265267 const userColor = queryParams . success ? queryParams . output . color : undefined
268+ const labelColor = queryParams . success ? queryParams . output . labelColor : undefined
266269 const showName = queryParams . success && queryParams . output . name === 'true'
270+ const userLabel = queryParams . success ? queryParams . output . label : undefined
267271
268272 const badgeTypeResult = v . safeParse ( BadgeTypeSchema , typeParam )
269273 const strategyKey = badgeTypeResult . success ? badgeTypeResult . output : 'version'
@@ -274,12 +278,15 @@ export default defineCachedEventHandler(
274278 const pkgData = await fetchNpmPackage ( packageName )
275279 const strategyResult = await strategy ( pkgData , requestedVersion )
276280
277- const finalLabel = showName ? packageName : strategyResult . label
281+ const finalLabel = userLabel ? userLabel : showName ? packageName : strategyResult . label
278282 const finalValue = strategyResult . value
279283
280284 const rawColor = userColor ?? strategyResult . color
281285 const finalColor = rawColor ?. startsWith ( '#' ) ? rawColor : `#${ rawColor } `
282286
287+ const rawLabelColor = labelColor ?? '#0a0a0a'
288+ const finalLabelColor = rawLabelColor ?. startsWith ( '#' ) ? rawLabelColor : `#${ rawLabelColor } `
289+
283290 const leftWidth = measureTextWidth ( finalLabel )
284291 const rightWidth = measureTextWidth ( finalValue )
285292 const totalWidth = leftWidth + rightWidth
@@ -291,7 +298,7 @@ export default defineCachedEventHandler(
291298 <rect width="${ totalWidth } " height="${ height } " rx="3" fill="#fff"/>
292299 </clipPath>
293300 <g clip-path="url(#r)">
294- <rect width="${ leftWidth } " height="${ height } " fill="#0a0a0a "/>
301+ <rect width="${ leftWidth } " height="${ height } " fill="${ finalLabelColor } "/>
295302 <rect x="${ leftWidth } " width="${ rightWidth } " height="${ height } " fill="${ finalColor } "/>
296303 </g>
297304 <g text-anchor="middle" font-family="'Geist', system-ui, -apple-system, sans-serif" font-size="11">
0 commit comments