1
1
<script setup lang="ts">
2
2
import hexRgb from ' hex-rgb'
3
+ import rgbToHSL from ' rgb-to-hsl'
3
4
4
5
import { allowedRepos } from ' #shared/repos'
5
6
@@ -23,11 +24,15 @@ onMounted(async () => {
23
24
24
25
function labelColors(color : string ) {
25
26
const value = hexRgb (color )
27
+ const [hue, saturation, lightness] = rgbToHSL (value .red , value .green , value .blue )
26
28
27
29
return {
28
- ' --label-r' : value .red ,
29
- ' --label-g' : value .green ,
30
- ' --label-b' : value .blue ,
30
+ ' --label-r' : Math .round (value .red ),
31
+ ' --label-g' : Math .round (value .green ),
32
+ ' --label-b' : Math .round (value .blue ),
33
+ ' --label-h' : Math .round (hue ),
34
+ ' --label-s' : Math .round (Number .parseInt (saturation )),
35
+ ' --label-l' : Math .round (Number .parseInt (lightness )),
31
36
}
32
37
}
33
38
@@ -169,7 +174,7 @@ const openState = reactive<Record<string, boolean>>({})
169
174
<span
170
175
v-for =" (label, j) of issue.labels"
171
176
:key =" j"
172
- class =" label bg-gray-200 text-gray-800 rounded-full px-2 py-0.5 whitespace-pre border-solid border-1 text-xs inline-block leading-tight"
177
+ class =" label rounded-full px-2 py-0.5 whitespace-pre border-solid border-1 text-xs inline-block leading-tight"
173
178
:style =" labelColors(typeof label === 'string' ? '000000' : label.color || '000000')"
174
179
>
175
180
{{ typeof label === 'string' ? label : label.name }}
@@ -192,8 +197,12 @@ const openState = reactive<Record<string, boolean>>({})
192
197
193
198
<style scoped>
194
199
.label {
195
- background : rgba (var (--label-r ), var (--label-g ), var (--label-b ), 0.30 );
196
- color : white ;
200
+ --lightness-threshold : 0.6 ;
201
+ --perceived-lightness : calc (((var (--label-r ) * 0.2126 ) + (var (--label-g ) * 0.7152 ) + (var (--label-b ) * 0.0722)) / 255);
202
+ --lightness-switch : max (0 , min (calc ((var (--perceived-lightness ) - var (--lightness-threshold )) * -1000 ), 1 ));
203
+ --lighten-by : calc (((var (--lightness-threshold ) - var (--perceived-lightness )) * 100 ) * var (--lightness-switch ));
204
+ background : rgba (var (--label-r ), var (--label-g ), var (--label-b ), 0.18 );
205
+ color : hsl (var (--label-h ),calc (var (--label-s ) * 1% ),calc ((var (--label-l ) + var (--lighten-by )) * 1% ));
197
206
border-color : rgba (var (--label-r ), var (--label-g ), var (--label-b ), 0.7 );
198
207
}
199
208
section :first-of-type {
0 commit comments