Skip to content

Commit c5398ec

Browse files
committed
chore: replace css-color-converter with color
1 parent 4d09376 commit c5398ec

File tree

13 files changed

+93
-51
lines changed

13 files changed

+93
-51
lines changed

badge-maker/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ There are three ways to specify `color` and `labelColor`:
105105

106106
- `rgb(...)`, `rgba(...)`
107107
- `hsl(...)`, `hsla(...)`
108+
- `hwb(...)`
108109
- ![][aqua] ![][fuchsia] ![][lightslategray] etc.
109110

110111
[brightgreen]: https://img.shields.io/badge/brightgreen-brightgreen.svg

badge-maker/lib/color.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fromString } from 'css-color-converter'
1+
import colour from 'color'
22

33
// When updating these, be sure also to update the list in `badge-maker/README.md`.
44
export const namedColors = {
@@ -36,7 +36,13 @@ export function isHexColor(s = '') {
3636
}
3737

3838
function isCSSColor(color) {
39-
return typeof color === 'string' && fromString(color.trim())
39+
if (typeof color !== 'string') return false
40+
try {
41+
const cssColor = colour(color.trim())
42+
return Boolean(cssColor)
43+
} catch {
44+
return false
45+
}
4046
}
4147

4248
export function normalizeColor(color) {
@@ -67,12 +73,15 @@ export function toSvgColor(color) {
6773
}
6874

6975
export function brightness(color) {
70-
if (color) {
71-
const cssColor = fromString(color)
76+
if (!color) return 0
77+
try {
78+
const cssColor = colour(color)
79+
7280
if (cssColor) {
73-
const rgb = cssColor.toRgbaArray()
81+
const rgb = cssColor.rgb().array()
7482
return +((rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 255000).toFixed(2)
7583
}
84+
} catch {
85+
return 0
7686
}
77-
return 0
7887
}

badge-maker/lib/color.spec.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,23 @@ test(normalizeColor, () => {
3333
given('rgb(100%, 200%, 222%)').expect('rgb(100%, 200%, 222%)')
3434
given('rgb(122, 200, 222)').expect('rgb(122, 200, 222)')
3535
given('rgb(122, 200, 222, 1)').expect('rgb(122, 200, 222, 1)')
36+
given('rgb(-100, 20, 111)').expect('rgb(-100, 20, 111)')
37+
given('rgba(-100, 20, 111, 1.1)').expect('rgba(-100, 20, 111, 1.1)')
3638
given('rgba(100, 20, 111, 1)').expect('rgba(100, 20, 111, 1)')
3739
given('hsl(122, 200%, 222%)').expect('hsl(122, 200%, 222%)')
3840
given('hsla(122, 200%, 222%, 1)').expect('hsla(122, 200%, 222%, 1)')
41+
given('hwb(122, 200%, 222%)').expect('hwb(122, 200%, 222%)')
42+
given('hwb(122, 200%, 222%, 1)').expect('hwb(122, 200%, 222%, 1)')
3943
forCases([
4044
given(),
4145
given(''),
4246
given('not-a-color'),
4347
given('#ABCFGH'),
44-
given('rgb(-100, 20, 111)'),
4548
given('rgb(100%, 200, 222)'),
46-
given('rgba(-100, 20, 111, 1.1)'),
4749
given('hsl(122, 200, 222, 1)'),
4850
given('hsl(122, 200, 222)'),
4951
given('hsl(122, 200, 222%)'),
52+
given('hwba(122, 200%, 222, 1)'),
5053
given(undefined),
5154
given(null),
5255
given(true),

badge-maker/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
},
4343
"dependencies": {
4444
"anafanafo": "2.0.0",
45-
"css-color-converter": "^2.0.0"
45+
"color": "^5.0.0"
4646
},
4747
"scripts": {
4848
"test": "echo 'Run tests from parent dir'; false"

core/base-service/openapi.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function category2openapi({ category, services, sort = false }) {
135135
in: 'query',
136136
required: false,
137137
description:
138-
'The color of the logo (hex, rgb, rgba, hsl, hsla and css named colors supported). Supported for simple-icons logos but not for custom logos.',
138+
'The color of the logo (hex, rgb, rgba, hsl, hsla, hwb and css named colors supported). Supported for simple-icons logos but not for custom logos.',
139139
schema: {
140140
type: 'string',
141141
},
@@ -168,7 +168,7 @@ function category2openapi({ category, services, sort = false }) {
168168
in: 'query',
169169
required: false,
170170
description:
171-
'Background color of the left part (hex, rgb, rgba, hsl, hsla and css named colors supported).',
171+
'Background color of the left part (hex, rgb, rgba, hsl, hsla, hwb and css named colors supported).',
172172
schema: {
173173
type: 'string',
174174
},
@@ -179,7 +179,7 @@ function category2openapi({ category, services, sort = false }) {
179179
in: 'query',
180180
required: false,
181181
description:
182-
'Background color of the right part (hex, rgb, rgba, hsl, hsla and css named colors supported).',
182+
'Background color of the right part (hex, rgb, rgba, hsl, hsla, hwb and css named colors supported).',
183183
schema: {
184184
type: 'string',
185185
},

core/base-service/openapi.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const expected = {
8888
in: 'query',
8989
required: false,
9090
description:
91-
'The color of the logo (hex, rgb, rgba, hsl, hsla and css named colors supported). Supported for simple-icons logos but not for custom logos.',
91+
'The color of the logo (hex, rgb, rgba, hsl, hsla, hwb and css named colors supported). Supported for simple-icons logos but not for custom logos.',
9292
schema: { type: 'string' },
9393
example: 'violet',
9494
},
@@ -117,7 +117,7 @@ const expected = {
117117
in: 'query',
118118
required: false,
119119
description:
120-
'Background color of the left part (hex, rgb, rgba, hsl, hsla and css named colors supported).',
120+
'Background color of the left part (hex, rgb, rgba, hsl, hsla, hwb and css named colors supported).',
121121
schema: { type: 'string' },
122122
example: 'abcdef',
123123
},
@@ -126,7 +126,7 @@ const expected = {
126126
in: 'query',
127127
required: false,
128128
description:
129-
'Background color of the right part (hex, rgb, rgba, hsl, hsla and css named colors supported).',
129+
'Background color of the right part (hex, rgb, rgba, hsl, hsla, hwb and css named colors supported).',
130130
schema: { type: 'string' },
131131
example: 'fedcba',
132132
},

core/server/error-pages/500.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
<!doctype html><meta charset=utf-8><title>A server error occurred</title>
1+
<!doctype html><meta charset="utf-8" /><title>A server error occurred</title>
22

3-
<h1> I have nothing to offer for this request </h1>
4-
<p> … but blood, toil, tears and sweat.
5-
</p>
3+
<h1>I have nothing to offer for this request</h1>
4+
<p>… but blood, toil, tears and sweat.</p>
65
<p>And trying again later.</p>

core/server/test-public/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
33
<head>
4-
<meta charset="utf-8">
4+
<meta charset="utf-8" />
55
<title>shields.io</title>
66
</head>
77
<body>

frontend/docs/logos.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Any custom logo can be passed in a URL parameter by base64 encoding it. e.g:
2020

2121
## logoColor parameter
2222

23-
The `logoColor` param can be used to set the color of the SimpleIcons named logo. Hex, rgb, rgba, hsl, hsla and css named colors can all be used.
23+
The `logoColor` param can be used to set the color of the SimpleIcons named logo. Hex, rgb, rgba, hsl, hsla, hwb and css named colors can all be used.
2424

2525
- ![](https://img.shields.io/badge/logo-javascript-blue?logo=javascript) - https://img.shields.io/badge/logo-javascript-blue?logo=javascript
2626
- ![](https://img.shields.io/badge/logo-javascript-blue?logo=javascript&logoColor=f5f5f5) - https://img.shields.io/badge/logo-javascript-blue?logo=javascript&logoColor=f5f5f5

frontend/src/css/custom.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
padding: 0 var(--ifm-pre-padding);
2424
}
2525

26-
html[data-theme="dark"] .docusaurus-highlight-code-line {
26+
html[data-theme='dark'] .docusaurus-highlight-code-line {
2727
background-color: rgba(0, 0, 0, 0.3);
2828
}
2929

0 commit comments

Comments
 (0)