Skip to content

Commit bccaf40

Browse files
committed
fix: improve layer colours
1 parent 5e41e45 commit bccaf40

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

app/pages/[[owner]]/[[repo]]/index.vue

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script setup lang="ts">
22
import hexRgb from 'hex-rgb'
3+
import rgbToHSL from 'rgb-to-hsl'
34
45
import { allowedRepos } from '#shared/repos'
56
@@ -23,11 +24,15 @@ onMounted(async () => {
2324
2425
function labelColors(color: string) {
2526
const value = hexRgb(color)
27+
const [hue, saturation, lightness] = rgbToHSL(value.red, value.green, value.blue)
2628
2729
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)),
3136
}
3237
}
3338
@@ -169,7 +174,7 @@ const openState = reactive<Record<string, boolean>>({})
169174
<span
170175
v-for="(label, j) of issue.labels"
171176
: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"
173178
:style="labelColors(typeof label === 'string' ? '000000' : label.color || '000000')"
174179
>
175180
{{ typeof label === 'string' ? label : label.name }}
@@ -192,8 +197,12 @@ const openState = reactive<Record<string, boolean>>({})
192197

193198
<style scoped>
194199
.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%));
197206
border-color: rgba(var(--label-r), var(--label-g), var(--label-b), 0.7);
198207
}
199208
section:first-of-type {

augments/declarations.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module 'rgb-to-hsl' {
2+
const _default: (r: number, g: number, b: number) => [number, string, string]
3+
export default _default
4+
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"nuxt-time": "1.0.3",
2727
"ohash": "^1.1.4",
2828
"openai": "^4.76.0",
29+
"rgb-to-hsl": "^0.0.3",
2930
"unocss": "^0.65.1",
3031
"unplugin-vue-router": "^0.10.9"
3132
},

pnpm-lock.yaml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)