Skip to content

Commit 267cf0e

Browse files
committed
fix color
1 parent e75b61f commit 267cf0e

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@node-projects/svghmi.webcomponent",
3-
"version": "0.0.8",
3+
"version": "0.0.9",
44
"description": "a svghmi webcomponent.",
55
"type": "module",
66
"main": "./dist/index.js",

src/Converter.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
function hexToHSL(hex) {
2+
if (hex.startsWith('#'))
3+
hex = hex.substring(1);
24
let r = parseInt(hex.substr(1, 2), 16) / 255;
35
let g = parseInt(hex.substr(3, 2), 16) / 255;
46
let b = parseInt(hex.substr(5, 2), 16) / 255;
@@ -58,10 +60,14 @@ export class Converter {
5860
}
5961

6062
static RGB(col: string) {
63+
if (col.startsWith('#'))
64+
return col;
6165
return '#' + col.substring(4);
6266
}
6367

6468
static RGBA(col: string) {
69+
if (col.startsWith('#'))
70+
return col;
6571
return '#' + col.substring(4) + col.substring(2, 4);
6672
}
6773

0 commit comments

Comments
 (0)