@ooneex/color 0.0.17 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -0
- package/dist/index.d.ts +5 -22
- package/dist/index.js +86 -1
- package/dist/index.js.map +5 -3
- package/package.json +8 -10
package/README.md
CHANGED
|
@@ -1 +1,37 @@
|
|
|
1
1
|
# @ooneex/color
|
|
2
|
+
|
|
3
|
+
Curated color palette with hex values and human-friendly names plus TypeScript types for UI theming.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Simple Palette** - `SIMPLE_COLORS` — a curated set of 26 hex colors suitable for charts, avatars, and tags
|
|
12
|
+
- **Human-Friendly Names** - `SIMPLE_COLOR_NAMES` maps each hex to a readable label (Blue, Emerald, Coral, …)
|
|
13
|
+
- **Type-Safe** - `SimpleColorType` narrows to the exact hex values in the palette
|
|
14
|
+
- **Zero Dependencies** - Pure constants, no runtime dependencies
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
bun add @ooneex/color
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { SIMPLE_COLOR_NAMES, SIMPLE_COLORS, type SimpleColorType } from "@ooneex/color";
|
|
26
|
+
|
|
27
|
+
const color: SimpleColorType = "#3B82F6";
|
|
28
|
+
SIMPLE_COLOR_NAMES[color]; // "Blue"
|
|
29
|
+
|
|
30
|
+
for (const hex of SIMPLE_COLORS) {
|
|
31
|
+
console.log(hex, SIMPLE_COLOR_NAMES[hex]);
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## License
|
|
36
|
+
|
|
37
|
+
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,22 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
type HSLAType = `hsla(${number}, ${number}%, ${number}%, ${number})`;
|
|
7
|
-
type ColorType = HexaType | RGBType | RGBAType | HSLType | HSLAType;
|
|
8
|
-
interface IColor extends IBase {
|
|
9
|
-
hex?: HexaType;
|
|
10
|
-
rgb?: RGBType;
|
|
11
|
-
rgba?: RGBAType;
|
|
12
|
-
hsl?: HSLType;
|
|
13
|
-
hsla?: HSLAType;
|
|
14
|
-
alpha?: number;
|
|
15
|
-
red?: number;
|
|
16
|
-
green?: number;
|
|
17
|
-
blue?: number;
|
|
18
|
-
hue?: number;
|
|
19
|
-
saturation?: number;
|
|
20
|
-
lightness?: number;
|
|
21
|
-
}
|
|
22
|
-
export { RGBType, RGBAType, IColor, HexaType, HSLType, HSLAType, ColorType };
|
|
1
|
+
type SimpleColorType = (typeof SIMPLE_COLORS)[number];
|
|
2
|
+
declare const SIMPLE_COLORS: readonly ["#3B82F6", "#10B981", "#8B5CF6", "#F59E0B", "#EC4899", "#F97316", "#6B7280", "#EF4444", "#14B8A6", "#6366F1", "#84CC16", "#06B6D4", "#A855F7", "#F43F5E", "#78716C", "#0EA5E9", "#22C55E", "#FACC15", "#E879F9", "#2DD4BF", "#FB923C", "#818CF8", "#F472B6", "#4ADE80", "#000000", "#FFFFFF"];
|
|
3
|
+
declare const SIMPLE_COLOR_NAMES: Record<SimpleColorType, string>;
|
|
4
|
+
declare const hexToRgba: (hex: string, alpha?: number) => string | null;
|
|
5
|
+
export { hexToRgba, SimpleColorType, SIMPLE_COLOR_NAMES, SIMPLE_COLORS };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,87 @@
|
|
|
1
|
+
// src/constants.ts
|
|
2
|
+
var SIMPLE_COLORS = [
|
|
3
|
+
"#3B82F6",
|
|
4
|
+
"#10B981",
|
|
5
|
+
"#8B5CF6",
|
|
6
|
+
"#F59E0B",
|
|
7
|
+
"#EC4899",
|
|
8
|
+
"#F97316",
|
|
9
|
+
"#6B7280",
|
|
10
|
+
"#EF4444",
|
|
11
|
+
"#14B8A6",
|
|
12
|
+
"#6366F1",
|
|
13
|
+
"#84CC16",
|
|
14
|
+
"#06B6D4",
|
|
15
|
+
"#A855F7",
|
|
16
|
+
"#F43F5E",
|
|
17
|
+
"#78716C",
|
|
18
|
+
"#0EA5E9",
|
|
19
|
+
"#22C55E",
|
|
20
|
+
"#FACC15",
|
|
21
|
+
"#E879F9",
|
|
22
|
+
"#2DD4BF",
|
|
23
|
+
"#FB923C",
|
|
24
|
+
"#818CF8",
|
|
25
|
+
"#F472B6",
|
|
26
|
+
"#4ADE80",
|
|
27
|
+
"#000000",
|
|
28
|
+
"#FFFFFF"
|
|
29
|
+
];
|
|
30
|
+
var SIMPLE_COLOR_NAMES = {
|
|
31
|
+
"#3B82F6": "Blue",
|
|
32
|
+
"#10B981": "Green",
|
|
33
|
+
"#8B5CF6": "Purple",
|
|
34
|
+
"#F59E0B": "Yellow",
|
|
35
|
+
"#EC4899": "Pink",
|
|
36
|
+
"#F97316": "Orange",
|
|
37
|
+
"#6B7280": "Gray",
|
|
38
|
+
"#EF4444": "Red",
|
|
39
|
+
"#14B8A6": "Teal",
|
|
40
|
+
"#6366F1": "Indigo",
|
|
41
|
+
"#84CC16": "Lime",
|
|
42
|
+
"#06B6D4": "Cyan",
|
|
43
|
+
"#A855F7": "Violet",
|
|
44
|
+
"#F43F5E": "Rose",
|
|
45
|
+
"#78716C": "Stone",
|
|
46
|
+
"#0EA5E9": "Sky",
|
|
47
|
+
"#22C55E": "Emerald",
|
|
48
|
+
"#FACC15": "Amber",
|
|
49
|
+
"#E879F9": "Fuchsia",
|
|
50
|
+
"#2DD4BF": "Mint",
|
|
51
|
+
"#FB923C": "Tangerine",
|
|
52
|
+
"#818CF8": "Periwinkle",
|
|
53
|
+
"#F472B6": "Coral",
|
|
54
|
+
"#4ADE80": "Spring",
|
|
55
|
+
"#000000": "Black",
|
|
56
|
+
"#FFFFFF": "White"
|
|
57
|
+
};
|
|
58
|
+
// src/hexToRgba.ts
|
|
59
|
+
var hexToRgba = (hex, alpha) => {
|
|
60
|
+
const match = hex.trim().replace(/^#/, "");
|
|
61
|
+
if (!/^([0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(match)) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
const expand = (value) => value.length <= 4 ? value.split("").map((c) => c + c).join("") : value;
|
|
65
|
+
const full = expand(match);
|
|
66
|
+
const r = Number.parseInt(full.slice(0, 2), 16);
|
|
67
|
+
const g = Number.parseInt(full.slice(2, 4), 16);
|
|
68
|
+
const b = Number.parseInt(full.slice(4, 6), 16);
|
|
69
|
+
let a = 1;
|
|
70
|
+
if (alpha !== undefined) {
|
|
71
|
+
if (alpha < 0 || alpha > 1 || Number.isNaN(alpha)) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
a = alpha;
|
|
75
|
+
} else if (full.length === 8) {
|
|
76
|
+
a = Number.parseInt(full.slice(6, 8), 16) / 255;
|
|
77
|
+
}
|
|
78
|
+
const roundedAlpha = Math.round(a * 1000) / 1000;
|
|
79
|
+
return `rgba(${r}, ${g}, ${b}, ${roundedAlpha})`;
|
|
80
|
+
};
|
|
81
|
+
export {
|
|
82
|
+
hexToRgba,
|
|
83
|
+
SIMPLE_COLOR_NAMES,
|
|
84
|
+
SIMPLE_COLORS
|
|
85
|
+
};
|
|
1
86
|
|
|
2
|
-
//# debugId=
|
|
87
|
+
//# debugId=2AEC7FA91EDDC8D564756E2164756E21
|
package/dist/index.js.map
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": [],
|
|
3
|
+
"sources": ["src/constants.ts", "src/hexToRgba.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
+
"import type { SimpleColorType } from \"./types\";\n\nexport const SIMPLE_COLORS = [\n \"#3B82F6\",\n \"#10B981\",\n \"#8B5CF6\",\n \"#F59E0B\",\n \"#EC4899\",\n \"#F97316\",\n \"#6B7280\",\n \"#EF4444\",\n \"#14B8A6\",\n \"#6366F1\",\n \"#84CC16\",\n \"#06B6D4\",\n \"#A855F7\",\n \"#F43F5E\",\n \"#78716C\",\n \"#0EA5E9\",\n \"#22C55E\",\n \"#FACC15\",\n \"#E879F9\",\n \"#2DD4BF\",\n \"#FB923C\",\n \"#818CF8\",\n \"#F472B6\",\n \"#4ADE80\",\n \"#000000\",\n \"#FFFFFF\",\n] as const;\n\nexport const SIMPLE_COLOR_NAMES: Record<SimpleColorType, string> = {\n \"#3B82F6\": \"Blue\",\n \"#10B981\": \"Green\",\n \"#8B5CF6\": \"Purple\",\n \"#F59E0B\": \"Yellow\",\n \"#EC4899\": \"Pink\",\n \"#F97316\": \"Orange\",\n \"#6B7280\": \"Gray\",\n \"#EF4444\": \"Red\",\n \"#14B8A6\": \"Teal\",\n \"#6366F1\": \"Indigo\",\n \"#84CC16\": \"Lime\",\n \"#06B6D4\": \"Cyan\",\n \"#A855F7\": \"Violet\",\n \"#F43F5E\": \"Rose\",\n \"#78716C\": \"Stone\",\n \"#0EA5E9\": \"Sky\",\n \"#22C55E\": \"Emerald\",\n \"#FACC15\": \"Amber\",\n \"#E879F9\": \"Fuchsia\",\n \"#2DD4BF\": \"Mint\",\n \"#FB923C\": \"Tangerine\",\n \"#818CF8\": \"Periwinkle\",\n \"#F472B6\": \"Coral\",\n \"#4ADE80\": \"Spring\",\n \"#000000\": \"Black\",\n \"#FFFFFF\": \"White\",\n};\n",
|
|
6
|
+
"export const hexToRgba = (hex: string, alpha?: number): string | null => {\n const match = hex.trim().replace(/^#/, \"\");\n\n if (!/^([0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(match)) {\n return null;\n }\n\n const expand = (value: string): string =>\n value.length <= 4\n ? value\n .split(\"\")\n .map((c) => c + c)\n .join(\"\")\n : value;\n\n const full = expand(match);\n const r = Number.parseInt(full.slice(0, 2), 16);\n const g = Number.parseInt(full.slice(2, 4), 16);\n const b = Number.parseInt(full.slice(4, 6), 16);\n\n let a = 1;\n if (alpha !== undefined) {\n if (alpha < 0 || alpha > 1 || Number.isNaN(alpha)) {\n return null;\n }\n a = alpha;\n } else if (full.length === 8) {\n a = Number.parseInt(full.slice(6, 8), 16) / 255;\n }\n\n const roundedAlpha = Math.round(a * 1000) / 1000;\n\n return `rgba(${r}, ${g}, ${b}, ${roundedAlpha})`;\n};\n"
|
|
5
7
|
],
|
|
6
|
-
"mappings": "",
|
|
7
|
-
"debugId": "
|
|
8
|
+
"mappings": ";AAEO,IAAM,gBAAgB;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,IAAM,qBAAsD;AAAA,EACjE,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AACb;;AC1DO,IAAM,YAAY,CAAC,KAAa,UAAkC;AAAA,EACvE,MAAM,QAAQ,IAAI,KAAK,EAAE,QAAQ,MAAM,EAAE;AAAA,EAEzC,IAAI,CAAC,kEAAkE,KAAK,KAAK,GAAG;AAAA,IAClF,OAAO;AAAA,EACT;AAAA,EAEA,MAAM,SAAS,CAAC,UACd,MAAM,UAAU,IACZ,MACG,MAAM,EAAE,EACR,IAAI,CAAC,MAAM,IAAI,CAAC,EAChB,KAAK,EAAE,IACV;AAAA,EAEN,MAAM,OAAO,OAAO,KAAK;AAAA,EACzB,MAAM,IAAI,OAAO,SAAS,KAAK,MAAM,GAAG,CAAC,GAAG,EAAE;AAAA,EAC9C,MAAM,IAAI,OAAO,SAAS,KAAK,MAAM,GAAG,CAAC,GAAG,EAAE;AAAA,EAC9C,MAAM,IAAI,OAAO,SAAS,KAAK,MAAM,GAAG,CAAC,GAAG,EAAE;AAAA,EAE9C,IAAI,IAAI;AAAA,EACR,IAAI,UAAU,WAAW;AAAA,IACvB,IAAI,QAAQ,KAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,GAAG;AAAA,MACjD,OAAO;AAAA,IACT;AAAA,IACA,IAAI;AAAA,EACN,EAAO,SAAI,KAAK,WAAW,GAAG;AAAA,IAC5B,IAAI,OAAO,SAAS,KAAK,MAAM,GAAG,CAAC,GAAG,EAAE,IAAI;AAAA,EAC9C;AAAA,EAEA,MAAM,eAAe,KAAK,MAAM,IAAI,IAAI,IAAI;AAAA,EAE5C,OAAO,QAAQ,MAAM,MAAM,MAAM;AAAA;",
|
|
9
|
+
"debugId": "2AEC7FA91EDDC8D564756E2164756E21",
|
|
8
10
|
"names": []
|
|
9
11
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ooneex/color",
|
|
3
|
-
"description": "
|
|
4
|
-
"version": "0.0
|
|
3
|
+
"description": "Curated color palette with hex values and human-friendly names plus TypeScript types for UI theming",
|
|
4
|
+
"version": "0.1.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
@@ -22,22 +22,20 @@
|
|
|
22
22
|
},
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"scripts": {
|
|
25
|
+
"test": "bun test tests",
|
|
25
26
|
"build": "bunup",
|
|
26
27
|
"lint": "tsgo --noEmit && bunx biome lint",
|
|
27
|
-
"npm:publish": "bun publish --tolerate-republish --access public"
|
|
28
|
+
"npm:publish": "bun publish --tolerate-republish --force --production --access public"
|
|
28
29
|
},
|
|
29
30
|
"dependencies": {},
|
|
30
|
-
"devDependencies": {
|
|
31
|
-
"@ooneex/types": "0.0.16"
|
|
32
|
-
},
|
|
33
31
|
"keywords": [
|
|
34
32
|
"bun",
|
|
35
33
|
"color",
|
|
36
|
-
"
|
|
37
|
-
"css",
|
|
34
|
+
"hex",
|
|
38
35
|
"ooneex",
|
|
39
36
|
"palette",
|
|
40
|
-
"
|
|
41
|
-
"typescript"
|
|
37
|
+
"theme",
|
|
38
|
+
"typescript",
|
|
39
|
+
"ui"
|
|
42
40
|
]
|
|
43
41
|
}
|