@trishchuk/coolors-mcp 1.0.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/.claude/settings.local.json +39 -0
- package/.env +2 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +73 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +71 -0
- package/.github/pull_request_template.md +97 -0
- package/.github/workflows/ci.yml +127 -0
- package/.github/workflows/deploy-docs.yml +56 -0
- package/.github/workflows/release.yml +99 -0
- package/.mcp.json +12 -0
- package/.prettierignore +1 -0
- package/CLAUDE.md +201 -0
- package/DOCUMENTATION.md +274 -0
- package/GEMINI.md +54 -0
- package/LICENSE +21 -0
- package/README.md +401 -0
- package/demo/content_based_color.png +0 -0
- package/demo/music-player.html +621 -0
- package/demo/podcast-player.html +903 -0
- package/dist/bin/coolors-mcp.d.ts +1 -0
- package/dist/bin/coolors-mcp.js +154 -0
- package/dist/bin/coolors-mcp.js.map +1 -0
- package/dist/bin/server.d.ts +1 -0
- package/dist/bin/server.js +3292 -0
- package/dist/bin/server.js.map +1 -0
- package/dist/chunk-IQ7NN26V.js +114 -0
- package/dist/chunk-IQ7NN26V.js.map +1 -0
- package/dist/chunk-P3ARRKLS.js +1214 -0
- package/dist/chunk-P3ARRKLS.js.map +1 -0
- package/dist/color/index.d.ts +716 -0
- package/dist/color/index.js +153 -0
- package/dist/color/index.js.map +1 -0
- package/dist/coolors-mcp.d.ts +136 -0
- package/dist/coolors-mcp.js +7 -0
- package/dist/coolors-mcp.js.map +1 -0
- package/docs/.vitepress/cache/deps/@braintree_sanitize-url.js +93 -0
- package/docs/.vitepress/cache/deps/@braintree_sanitize-url.js.map +7 -0
- package/docs/.vitepress/cache/deps/_metadata.json +127 -0
- package/docs/.vitepress/cache/deps/chunk-BUSYA2B4.js +9 -0
- package/docs/.vitepress/cache/deps/chunk-BUSYA2B4.js.map +7 -0
- package/docs/.vitepress/cache/deps/chunk-JD3CXNQ6.js +12683 -0
- package/docs/.vitepress/cache/deps/chunk-JD3CXNQ6.js.map +7 -0
- package/docs/.vitepress/cache/deps/chunk-SYPOPCWC.js +9719 -0
- package/docs/.vitepress/cache/deps/chunk-SYPOPCWC.js.map +7 -0
- package/docs/.vitepress/cache/deps/cytoscape-cose-bilkent.js +4710 -0
- package/docs/.vitepress/cache/deps/cytoscape-cose-bilkent.js.map +7 -0
- package/docs/.vitepress/cache/deps/cytoscape.js +30278 -0
- package/docs/.vitepress/cache/deps/cytoscape.js.map +7 -0
- package/docs/.vitepress/cache/deps/dayjs.js +285 -0
- package/docs/.vitepress/cache/deps/dayjs.js.map +7 -0
- package/docs/.vitepress/cache/deps/debug.js +468 -0
- package/docs/.vitepress/cache/deps/debug.js.map +7 -0
- package/docs/.vitepress/cache/deps/package.json +3 -0
- package/docs/.vitepress/cache/deps/prismjs.js +1466 -0
- package/docs/.vitepress/cache/deps/prismjs.js.map +7 -0
- package/docs/.vitepress/cache/deps/prismjs_components_prism-bash.js +228 -0
- package/docs/.vitepress/cache/deps/prismjs_components_prism-bash.js.map +7 -0
- package/docs/.vitepress/cache/deps/prismjs_components_prism-javascript.js +142 -0
- package/docs/.vitepress/cache/deps/prismjs_components_prism-javascript.js.map +7 -0
- package/docs/.vitepress/cache/deps/prismjs_components_prism-json.js +27 -0
- package/docs/.vitepress/cache/deps/prismjs_components_prism-json.js.map +7 -0
- package/docs/.vitepress/cache/deps/prismjs_components_prism-python.js +65 -0
- package/docs/.vitepress/cache/deps/prismjs_components_prism-python.js.map +7 -0
- package/docs/.vitepress/cache/deps/prismjs_components_prism-typescript.js +53 -0
- package/docs/.vitepress/cache/deps/prismjs_components_prism-typescript.js.map +7 -0
- package/docs/.vitepress/cache/deps/prismjs_components_prism-yaml.js +73 -0
- package/docs/.vitepress/cache/deps/prismjs_components_prism-yaml.js.map +7 -0
- package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js +4507 -0
- package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js.map +7 -0
- package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js +584 -0
- package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js.map +7 -0
- package/docs/.vitepress/cache/deps/vitepress___@vueuse_integrations_useFocusTrap.js +1146 -0
- package/docs/.vitepress/cache/deps/vitepress___@vueuse_integrations_useFocusTrap.js.map +7 -0
- package/docs/.vitepress/cache/deps/vitepress___mark__js_src_vanilla__js.js +1667 -0
- package/docs/.vitepress/cache/deps/vitepress___mark__js_src_vanilla__js.js.map +7 -0
- package/docs/.vitepress/cache/deps/vitepress___minisearch.js +1814 -0
- package/docs/.vitepress/cache/deps/vitepress___minisearch.js.map +7 -0
- package/docs/.vitepress/cache/deps/vue.js +344 -0
- package/docs/.vitepress/cache/deps/vue.js.map +7 -0
- package/docs/.vitepress/components/ClientGrid.vue +125 -0
- package/docs/.vitepress/components/CodeBlock.vue +231 -0
- package/docs/.vitepress/components/ConfigModal.vue +477 -0
- package/docs/.vitepress/components/DiagramModal.vue +528 -0
- package/docs/.vitepress/components/TroubleshootingModal.vue +472 -0
- package/docs/.vitepress/config.js +162 -0
- package/docs/.vitepress/theme/FundingLayout.vue +251 -0
- package/docs/.vitepress/theme/Layout.vue +134 -0
- package/docs/.vitepress/theme/components/AdBanner.vue +317 -0
- package/docs/.vitepress/theme/components/AdPlaceholder.vue +78 -0
- package/docs/.vitepress/theme/components/FundingEffects.vue +322 -0
- package/docs/.vitepress/theme/components/FundingHero.vue +345 -0
- package/docs/.vitepress/theme/components/SupportSection.vue +511 -0
- package/docs/.vitepress/theme/custom-app.css +339 -0
- package/docs/.vitepress/theme/custom.css +699 -0
- package/docs/.vitepress/theme/index.js +25 -0
- package/docs/README.md +198 -0
- package/docs/concepts/accessibility.md +473 -0
- package/docs/concepts/color-spaces.md +222 -0
- package/docs/concepts/distance-metrics.md +384 -0
- package/docs/concepts/hct.md +261 -0
- package/docs/concepts/image-analysis.md +396 -0
- package/docs/concepts/material-design.md +306 -0
- package/docs/concepts/theme-matching.md +399 -0
- package/docs/examples/basic-colors.md +490 -0
- package/docs/examples/creating-themes.md +898 -0
- package/docs/examples/css-refactoring.md +824 -0
- package/docs/examples/image-extraction.md +882 -0
- package/docs/getting-started.md +366 -0
- package/docs/index.md +190 -0
- package/docs/installation.md +157 -0
- package/docs/tools/README.md +234 -0
- package/docs/tools/accessibility.md +614 -0
- package/docs/tools/color-operations.md +374 -0
- package/docs/tools/image-extraction.md +624 -0
- package/docs/tools/material-design.md +347 -0
- package/docs/tools/theme-matching.md +552 -0
- package/eslint.config.ts +14 -0
- package/examples/theme-matching.md +113 -0
- package/jsr.json +7 -0
- package/mcp-config.json +8 -0
- package/note.md +35 -0
- package/package.json +122 -0
- package/research_results.md +53 -0
- package/src/bin/coolors-mcp.ts +194 -0
- package/src/bin/server.ts +61 -0
- package/src/color/__tests__/conversions-argb.test.ts +198 -0
- package/src/color/__tests__/extract-colors.test.ts +360 -0
- package/src/color/__tests__/image-utils.test.ts +242 -0
- package/src/color/__tests__/reference-colors.test.ts +278 -0
- package/src/color/__tests__/round-trip.test.ts +197 -0
- package/src/color/conversions.test.ts +402 -0
- package/src/color/conversions.ts +393 -0
- package/src/color/dislike/__tests__/dislike-analyzer.test.ts +248 -0
- package/src/color/dislike/dislike-analyzer.ts +114 -0
- package/src/color/extract-colors.ts +228 -0
- package/src/color/hct/__tests__/hct-class.test.ts +232 -0
- package/src/color/hct/harmonization.ts +204 -0
- package/src/color/hct/hct-class.ts +109 -0
- package/src/color/hct/hct-solver.ts +168 -0
- package/src/color/hct/index.ts +39 -0
- package/src/color/hct/tonal-palette.ts +211 -0
- package/src/color/hct/types.ts +88 -0
- package/src/color/image-utils.ts +79 -0
- package/src/color/index.ts +87 -0
- package/src/color/material-theme.ts +157 -0
- package/src/color/metrics.test.ts +276 -0
- package/src/color/metrics.ts +281 -0
- package/src/color/quantize/__tests__/quantizer_celebi.test.ts +195 -0
- package/src/color/quantize/lab_point_provider.ts +55 -0
- package/src/color/quantize/point_provider.ts +27 -0
- package/src/color/quantize/quantizer_celebi.ts +51 -0
- package/src/color/quantize/quantizer_celebi_test.ts +71 -0
- package/src/color/quantize/quantizer_map.ts +47 -0
- package/src/color/quantize/quantizer_wsmeans.ts +232 -0
- package/src/color/quantize/quantizer_wu.ts +472 -0
- package/src/color/score/__tests__/score.test.ts +224 -0
- package/src/color/score/score.ts +175 -0
- package/src/color/types.ts +151 -0
- package/src/color/utils/color_utils.ts +292 -0
- package/src/color/utils/math_utils.ts +145 -0
- package/src/color/utils.test.ts +403 -0
- package/src/color/utils.ts +315 -0
- package/src/constants.ts +5 -0
- package/src/coolors-mcp.ts +37 -0
- package/src/examples/addition.ts +333 -0
- package/src/examples/color-demo.ts +125 -0
- package/src/examples/custom-logger.ts +201 -0
- package/src/examples/oauth-server.ts +113 -0
- package/src/examples/session-context.ts +269 -0
- package/src/session.ts +116 -0
- package/src/theme/__tests__/matcher.test.ts +180 -0
- package/src/theme/__tests__/parser.test.ts +148 -0
- package/src/theme/__tests__/refactor.test.ts +224 -0
- package/src/theme/index.ts +34 -0
- package/src/theme/matcher.ts +395 -0
- package/src/theme/parser.ts +392 -0
- package/src/theme/refactor.ts +360 -0
- package/src/theme/types.ts +152 -0
- package/src/tools/__tests__/gradient-generator.test.ts +206 -0
- package/src/tools/__tests__/palette-with-locks.test.ts +109 -0
- package/src/tools/color-conversion.tool.ts +54 -0
- package/src/tools/color-distance.tool.ts +41 -0
- package/src/tools/colors.ts +31 -0
- package/src/tools/contrast-checker.tool.ts +37 -0
- package/src/tools/dislike-analyzer.tool.ts +247 -0
- package/src/tools/gradient-generator.tool.ts +250 -0
- package/src/tools/image-extraction.tools.ts +289 -0
- package/src/tools/index.ts +39 -0
- package/src/tools/material-theme.tools.ts +250 -0
- package/src/tools/palette-generator.tool.ts +135 -0
- package/src/tools/palette-with-locks.tool.ts +221 -0
- package/src/tools/registry.ts +142 -0
- package/src/tools/simple-tools.ts +37 -0
- package/src/tools/theme-matching.tools.ts +334 -0
- package/src/types.ts +182 -0
- package/src/utils.ts +22 -0
- package/tsconfig.json +8 -0
- package/vitest.config.js +15 -0
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for color conversion functions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, expect, it } from "vitest";
|
|
6
|
+
|
|
7
|
+
import type { RGB } from "./types";
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
hexToRgb,
|
|
11
|
+
hslToRgb,
|
|
12
|
+
hsvToRgb,
|
|
13
|
+
labToRgb,
|
|
14
|
+
labToXyz,
|
|
15
|
+
parseColor,
|
|
16
|
+
rgbToHex,
|
|
17
|
+
rgbToHsl,
|
|
18
|
+
rgbToHsv,
|
|
19
|
+
rgbToLab,
|
|
20
|
+
rgbToXyz,
|
|
21
|
+
xyzToLab,
|
|
22
|
+
xyzToRgb,
|
|
23
|
+
} from "./conversions";
|
|
24
|
+
|
|
25
|
+
describe("Color Conversions", () => {
|
|
26
|
+
describe("RGB to HEX", () => {
|
|
27
|
+
it("should convert RGB to HEX correctly", () => {
|
|
28
|
+
expect(rgbToHex({ b: 0, g: 0, r: 255 })).toBe("#ff0000");
|
|
29
|
+
expect(rgbToHex({ b: 0, g: 255, r: 0 })).toBe("#00ff00");
|
|
30
|
+
expect(rgbToHex({ b: 255, g: 0, r: 0 })).toBe("#0000ff");
|
|
31
|
+
expect(rgbToHex({ b: 255, g: 255, r: 255 })).toBe("#ffffff");
|
|
32
|
+
expect(rgbToHex({ b: 0, g: 0, r: 0 })).toBe("#000000");
|
|
33
|
+
expect(rgbToHex({ b: 128, g: 128, r: 128 })).toBe("#808080");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("should handle edge cases", () => {
|
|
37
|
+
expect(rgbToHex({ b: 128, g: -1, r: 256 })).toBe("#ff0080");
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe("HEX to RGB", () => {
|
|
42
|
+
it("should convert HEX to RGB correctly", () => {
|
|
43
|
+
expect(hexToRgb("#ff0000")).toEqual({ b: 0, g: 0, r: 255 });
|
|
44
|
+
expect(hexToRgb("#00ff00")).toEqual({ b: 0, g: 255, r: 0 });
|
|
45
|
+
expect(hexToRgb("#0000ff")).toEqual({ b: 255, g: 0, r: 0 });
|
|
46
|
+
expect(hexToRgb("#ffffff")).toEqual({ b: 255, g: 255, r: 255 });
|
|
47
|
+
expect(hexToRgb("#000000")).toEqual({ b: 0, g: 0, r: 0 });
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("should handle 3-digit HEX", () => {
|
|
51
|
+
expect(hexToRgb("#f00")).toEqual({ b: 0, g: 0, r: 255 });
|
|
52
|
+
expect(hexToRgb("#0f0")).toEqual({ b: 0, g: 255, r: 0 });
|
|
53
|
+
expect(hexToRgb("#00f")).toEqual({ b: 255, g: 0, r: 0 });
|
|
54
|
+
expect(hexToRgb("#fff")).toEqual({ b: 255, g: 255, r: 255 });
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("should handle HEX without #", () => {
|
|
58
|
+
expect(hexToRgb("ff0000")).toEqual({ b: 0, g: 0, r: 255 });
|
|
59
|
+
expect(hexToRgb("f00")).toEqual({ b: 0, g: 0, r: 255 });
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe("RGB to HSL", () => {
|
|
64
|
+
it("should convert RGB to HSL correctly", () => {
|
|
65
|
+
// Red
|
|
66
|
+
const red = rgbToHsl({ b: 0, g: 0, r: 255 });
|
|
67
|
+
expect(red.h).toBe(0);
|
|
68
|
+
expect(red.s).toBe(100);
|
|
69
|
+
expect(red.l).toBe(50);
|
|
70
|
+
|
|
71
|
+
// Green
|
|
72
|
+
const green = rgbToHsl({ b: 0, g: 255, r: 0 });
|
|
73
|
+
expect(green.h).toBe(120);
|
|
74
|
+
expect(green.s).toBe(100);
|
|
75
|
+
expect(green.l).toBe(50);
|
|
76
|
+
|
|
77
|
+
// Blue
|
|
78
|
+
const blue = rgbToHsl({ b: 255, g: 0, r: 0 });
|
|
79
|
+
expect(blue.h).toBe(240);
|
|
80
|
+
expect(blue.s).toBe(100);
|
|
81
|
+
expect(blue.l).toBe(50);
|
|
82
|
+
|
|
83
|
+
// White
|
|
84
|
+
const white = rgbToHsl({ b: 255, g: 255, r: 255 });
|
|
85
|
+
expect(white.h).toBe(0);
|
|
86
|
+
expect(white.s).toBe(0);
|
|
87
|
+
expect(white.l).toBe(100);
|
|
88
|
+
|
|
89
|
+
// Black
|
|
90
|
+
const black = rgbToHsl({ b: 0, g: 0, r: 0 });
|
|
91
|
+
expect(black.h).toBe(0);
|
|
92
|
+
expect(black.s).toBe(0);
|
|
93
|
+
expect(black.l).toBe(0);
|
|
94
|
+
|
|
95
|
+
// Gray
|
|
96
|
+
const gray = rgbToHsl({ b: 128, g: 128, r: 128 });
|
|
97
|
+
expect(gray.h).toBe(0);
|
|
98
|
+
expect(gray.s).toBe(0);
|
|
99
|
+
expect(gray.l).toBe(50);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe("HSL to RGB", () => {
|
|
104
|
+
it("should convert HSL to RGB correctly", () => {
|
|
105
|
+
expect(hslToRgb({ h: 0, l: 50, s: 100 })).toEqual({ b: 0, g: 0, r: 255 });
|
|
106
|
+
expect(hslToRgb({ h: 120, l: 50, s: 100 })).toEqual({
|
|
107
|
+
b: 0,
|
|
108
|
+
g: 255,
|
|
109
|
+
r: 0,
|
|
110
|
+
});
|
|
111
|
+
expect(hslToRgb({ h: 240, l: 50, s: 100 })).toEqual({
|
|
112
|
+
b: 255,
|
|
113
|
+
g: 0,
|
|
114
|
+
r: 0,
|
|
115
|
+
});
|
|
116
|
+
expect(hslToRgb({ h: 0, l: 100, s: 0 })).toEqual({
|
|
117
|
+
b: 255,
|
|
118
|
+
g: 255,
|
|
119
|
+
r: 255,
|
|
120
|
+
});
|
|
121
|
+
expect(hslToRgb({ h: 0, l: 0, s: 0 })).toEqual({ b: 0, g: 0, r: 0 });
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("should handle achromatic colors", () => {
|
|
125
|
+
expect(hslToRgb({ h: 0, l: 50, s: 0 })).toEqual({
|
|
126
|
+
b: 128,
|
|
127
|
+
g: 128,
|
|
128
|
+
r: 128,
|
|
129
|
+
});
|
|
130
|
+
expect(hslToRgb({ h: 360, l: 75, s: 0 })).toEqual({
|
|
131
|
+
b: 191,
|
|
132
|
+
g: 191,
|
|
133
|
+
r: 191,
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe("RGB to HSV", () => {
|
|
139
|
+
it("should convert RGB to HSV correctly", () => {
|
|
140
|
+
// Red
|
|
141
|
+
const red = rgbToHsv({ b: 0, g: 0, r: 255 });
|
|
142
|
+
expect(red.h).toBe(0);
|
|
143
|
+
expect(red.s).toBe(100);
|
|
144
|
+
expect(red.v).toBe(100);
|
|
145
|
+
|
|
146
|
+
// Green
|
|
147
|
+
const green = rgbToHsv({ b: 0, g: 255, r: 0 });
|
|
148
|
+
expect(green.h).toBe(120);
|
|
149
|
+
expect(green.s).toBe(100);
|
|
150
|
+
expect(green.v).toBe(100);
|
|
151
|
+
|
|
152
|
+
// Blue
|
|
153
|
+
const blue = rgbToHsv({ b: 255, g: 0, r: 0 });
|
|
154
|
+
expect(blue.h).toBe(240);
|
|
155
|
+
expect(blue.s).toBe(100);
|
|
156
|
+
expect(blue.v).toBe(100);
|
|
157
|
+
|
|
158
|
+
// White
|
|
159
|
+
const white = rgbToHsv({ b: 255, g: 255, r: 255 });
|
|
160
|
+
expect(white.h).toBe(0);
|
|
161
|
+
expect(white.s).toBe(0);
|
|
162
|
+
expect(white.v).toBe(100);
|
|
163
|
+
|
|
164
|
+
// Black
|
|
165
|
+
const black = rgbToHsv({ b: 0, g: 0, r: 0 });
|
|
166
|
+
expect(black.h).toBe(0);
|
|
167
|
+
expect(black.s).toBe(0);
|
|
168
|
+
expect(black.v).toBe(0);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
describe("HSV to RGB", () => {
|
|
173
|
+
it("should convert HSV to RGB correctly", () => {
|
|
174
|
+
expect(hsvToRgb({ h: 0, s: 100, v: 100 })).toEqual({
|
|
175
|
+
b: 0,
|
|
176
|
+
g: 0,
|
|
177
|
+
r: 255,
|
|
178
|
+
});
|
|
179
|
+
expect(hsvToRgb({ h: 120, s: 100, v: 100 })).toEqual({
|
|
180
|
+
b: 0,
|
|
181
|
+
g: 255,
|
|
182
|
+
r: 0,
|
|
183
|
+
});
|
|
184
|
+
expect(hsvToRgb({ h: 240, s: 100, v: 100 })).toEqual({
|
|
185
|
+
b: 255,
|
|
186
|
+
g: 0,
|
|
187
|
+
r: 0,
|
|
188
|
+
});
|
|
189
|
+
expect(hsvToRgb({ h: 0, s: 0, v: 100 })).toEqual({
|
|
190
|
+
b: 255,
|
|
191
|
+
g: 255,
|
|
192
|
+
r: 255,
|
|
193
|
+
});
|
|
194
|
+
expect(hsvToRgb({ h: 0, s: 0, v: 0 })).toEqual({ b: 0, g: 0, r: 0 });
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it("should handle intermediate hues", () => {
|
|
198
|
+
const yellow = hsvToRgb({ h: 60, s: 100, v: 100 });
|
|
199
|
+
expect(yellow).toEqual({ b: 0, g: 255, r: 255 });
|
|
200
|
+
|
|
201
|
+
const cyan = hsvToRgb({ h: 180, s: 100, v: 100 });
|
|
202
|
+
expect(cyan).toEqual({ b: 255, g: 255, r: 0 });
|
|
203
|
+
|
|
204
|
+
const magenta = hsvToRgb({ h: 300, s: 100, v: 100 });
|
|
205
|
+
expect(magenta).toEqual({ b: 255, g: 0, r: 255 });
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
describe("RGB to XYZ", () => {
|
|
210
|
+
it("should convert RGB to XYZ correctly", () => {
|
|
211
|
+
const white = rgbToXyz({ b: 255, g: 255, r: 255 });
|
|
212
|
+
expect(white.x).toBeCloseTo(95.047, 1);
|
|
213
|
+
expect(white.y).toBeCloseTo(100.0, 1);
|
|
214
|
+
expect(white.z).toBeCloseTo(108.883, 1);
|
|
215
|
+
|
|
216
|
+
const black = rgbToXyz({ b: 0, g: 0, r: 0 });
|
|
217
|
+
expect(black.x).toBeCloseTo(0, 1);
|
|
218
|
+
expect(black.y).toBeCloseTo(0, 1);
|
|
219
|
+
expect(black.z).toBeCloseTo(0, 1);
|
|
220
|
+
|
|
221
|
+
const red = rgbToXyz({ b: 0, g: 0, r: 255 });
|
|
222
|
+
expect(red.x).toBeCloseTo(41.246, 1);
|
|
223
|
+
expect(red.y).toBeCloseTo(21.267, 1);
|
|
224
|
+
expect(red.z).toBeCloseTo(1.933, 1);
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
describe("XYZ to RGB", () => {
|
|
229
|
+
it("should convert XYZ to RGB correctly", () => {
|
|
230
|
+
expect(xyzToRgb({ x: 95.047, y: 100.0, z: 108.883 })).toEqual({
|
|
231
|
+
b: 255,
|
|
232
|
+
g: 255,
|
|
233
|
+
r: 255,
|
|
234
|
+
});
|
|
235
|
+
expect(xyzToRgb({ x: 0, y: 0, z: 0 })).toEqual({ b: 0, g: 0, r: 0 });
|
|
236
|
+
|
|
237
|
+
const red = xyzToRgb({ x: 41.246, y: 21.267, z: 1.933 });
|
|
238
|
+
expect(red.r).toBeCloseTo(255, 0);
|
|
239
|
+
expect(red.g).toBeCloseTo(0, 0);
|
|
240
|
+
expect(red.b).toBeCloseTo(0, 0);
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
describe("XYZ to LAB", () => {
|
|
245
|
+
it("should convert XYZ to LAB correctly", () => {
|
|
246
|
+
const white = xyzToLab({ x: 95.047, y: 100.0, z: 108.883 });
|
|
247
|
+
expect(white.l).toBeCloseTo(100, 1);
|
|
248
|
+
expect(white.a).toBeCloseTo(0, 1);
|
|
249
|
+
expect(white.b).toBeCloseTo(0, 1);
|
|
250
|
+
|
|
251
|
+
const black = xyzToLab({ x: 0, y: 0, z: 0 });
|
|
252
|
+
expect(black.l).toBeCloseTo(0, 1);
|
|
253
|
+
expect(black.a).toBeCloseTo(0, 1);
|
|
254
|
+
expect(black.b).toBeCloseTo(0, 1);
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
describe("LAB to XYZ", () => {
|
|
259
|
+
it("should convert LAB to XYZ correctly", () => {
|
|
260
|
+
const white = labToXyz({ a: 0, b: 0, l: 100 });
|
|
261
|
+
expect(white.x).toBeCloseTo(95.047, 1);
|
|
262
|
+
expect(white.y).toBeCloseTo(100.0, 1);
|
|
263
|
+
expect(white.z).toBeCloseTo(108.883, 1);
|
|
264
|
+
|
|
265
|
+
const black = labToXyz({ a: 0, b: 0, l: 0 });
|
|
266
|
+
expect(black.x).toBeCloseTo(0, 1);
|
|
267
|
+
expect(black.y).toBeCloseTo(0, 1);
|
|
268
|
+
expect(black.z).toBeCloseTo(0, 1);
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
describe("RGB to LAB", () => {
|
|
273
|
+
it("should convert RGB to LAB correctly", () => {
|
|
274
|
+
const white = rgbToLab({ b: 255, g: 255, r: 255 });
|
|
275
|
+
expect(white.l).toBeCloseTo(100, 1);
|
|
276
|
+
expect(white.a).toBeCloseTo(0, 1);
|
|
277
|
+
expect(white.b).toBeCloseTo(0, 1);
|
|
278
|
+
|
|
279
|
+
const black = rgbToLab({ b: 0, g: 0, r: 0 });
|
|
280
|
+
expect(black.l).toBeCloseTo(0, 1);
|
|
281
|
+
expect(black.a).toBeCloseTo(0, 1);
|
|
282
|
+
expect(black.b).toBeCloseTo(0, 1);
|
|
283
|
+
|
|
284
|
+
const red = rgbToLab({ b: 0, g: 0, r: 255 });
|
|
285
|
+
expect(red.l).toBeCloseTo(53.2, 0);
|
|
286
|
+
expect(red.a).toBeCloseTo(80.1, 0);
|
|
287
|
+
expect(red.b).toBeCloseTo(67.2, 0);
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
describe("LAB to RGB", () => {
|
|
292
|
+
it("should convert LAB to RGB correctly", () => {
|
|
293
|
+
expect(labToRgb({ a: 0, b: 0, l: 100 })).toEqual({
|
|
294
|
+
b: 255,
|
|
295
|
+
g: 255,
|
|
296
|
+
r: 255,
|
|
297
|
+
});
|
|
298
|
+
expect(labToRgb({ a: 0, b: 0, l: 0 })).toEqual({ b: 0, g: 0, r: 0 });
|
|
299
|
+
|
|
300
|
+
const red = labToRgb({ a: 80.1, b: 67.2, l: 53.2 });
|
|
301
|
+
expect(red.r).toBeCloseTo(255, 0);
|
|
302
|
+
expect(red.g).toBeCloseTo(0, 0);
|
|
303
|
+
expect(red.b).toBeCloseTo(0, 0);
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
describe("parseColor", () => {
|
|
308
|
+
it("should parse hex colors", () => {
|
|
309
|
+
expect(parseColor("#ff0000")).toEqual({ b: 0, g: 0, r: 255 });
|
|
310
|
+
expect(parseColor("#f00")).toEqual({ b: 0, g: 0, r: 255 });
|
|
311
|
+
expect(parseColor("#ff0000")).toEqual({ b: 0, g: 0, r: 255 }); // Use # prefix for consistency
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it("should parse rgb colors", () => {
|
|
315
|
+
expect(parseColor("rgb(255, 0, 0)")).toEqual({ b: 0, g: 0, r: 255 });
|
|
316
|
+
expect(parseColor("rgba(255, 0, 0, 0.5)")).toEqual({
|
|
317
|
+
b: 0,
|
|
318
|
+
g: 0,
|
|
319
|
+
r: 255,
|
|
320
|
+
});
|
|
321
|
+
expect(parseColor("rgb(128,128,128)")).toEqual({
|
|
322
|
+
b: 128,
|
|
323
|
+
g: 128,
|
|
324
|
+
r: 128,
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it("should parse hsl colors", () => {
|
|
329
|
+
expect(parseColor("hsl(0, 100%, 50%)")).toEqual({ b: 0, g: 0, r: 255 });
|
|
330
|
+
expect(parseColor("hsla(120, 100%, 50%, 0.5)")).toEqual({
|
|
331
|
+
b: 0,
|
|
332
|
+
g: 255,
|
|
333
|
+
r: 0,
|
|
334
|
+
});
|
|
335
|
+
expect(parseColor("hsl(240,100%,50%)")).toEqual({ b: 255, g: 0, r: 0 });
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
it("should return null for invalid colors", () => {
|
|
339
|
+
expect(parseColor("invalid")).toBeNull();
|
|
340
|
+
expect(parseColor("#gggggg")).toEqual({ b: 0, g: 0, r: 0 }); // Returns black for invalid hex
|
|
341
|
+
expect(parseColor("rgb(256, 256, 256)")).toEqual({
|
|
342
|
+
b: 256,
|
|
343
|
+
g: 256,
|
|
344
|
+
r: 256,
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
describe("Round-trip conversions", () => {
|
|
350
|
+
const testColors: RGB[] = [
|
|
351
|
+
{ b: 0, g: 0, r: 255 }, // Red
|
|
352
|
+
{ b: 0, g: 255, r: 0 }, // Green
|
|
353
|
+
{ b: 255, g: 0, r: 0 }, // Blue
|
|
354
|
+
{ b: 0, g: 255, r: 255 }, // Yellow
|
|
355
|
+
{ b: 255, g: 0, r: 255 }, // Magenta
|
|
356
|
+
{ b: 255, g: 255, r: 0 }, // Cyan
|
|
357
|
+
{ b: 128, g: 128, r: 128 }, // Gray
|
|
358
|
+
{ b: 255, g: 255, r: 255 }, // White
|
|
359
|
+
{ b: 0, g: 0, r: 0 }, // Black
|
|
360
|
+
];
|
|
361
|
+
|
|
362
|
+
it("should round-trip RGB -> HSL -> RGB", () => {
|
|
363
|
+
testColors.forEach((color) => {
|
|
364
|
+
const hsl = rgbToHsl(color);
|
|
365
|
+
const rgb = hslToRgb(hsl);
|
|
366
|
+
expect(rgb.r).toBeCloseTo(color.r, 0);
|
|
367
|
+
expect(rgb.g).toBeCloseTo(color.g, 0);
|
|
368
|
+
expect(rgb.b).toBeCloseTo(color.b, 0);
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
it("should round-trip RGB -> HSV -> RGB", () => {
|
|
373
|
+
testColors.forEach((color) => {
|
|
374
|
+
const hsv = rgbToHsv(color);
|
|
375
|
+
const rgb = hsvToRgb(hsv);
|
|
376
|
+
expect(rgb.r).toBeCloseTo(color.r, 0);
|
|
377
|
+
expect(rgb.g).toBeCloseTo(color.g, 0);
|
|
378
|
+
expect(rgb.b).toBeCloseTo(color.b, 0);
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it("should round-trip RGB -> XYZ -> RGB", () => {
|
|
383
|
+
testColors.forEach((color) => {
|
|
384
|
+
const xyz = rgbToXyz(color);
|
|
385
|
+
const rgb = xyzToRgb(xyz);
|
|
386
|
+
expect(rgb.r).toBeCloseTo(color.r, 0);
|
|
387
|
+
expect(rgb.g).toBeCloseTo(color.g, 0);
|
|
388
|
+
expect(rgb.b).toBeCloseTo(color.b, 0);
|
|
389
|
+
});
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
it("should round-trip RGB -> LAB -> RGB", () => {
|
|
393
|
+
testColors.forEach((color) => {
|
|
394
|
+
const lab = rgbToLab(color);
|
|
395
|
+
const rgb = labToRgb(lab);
|
|
396
|
+
expect(rgb.r).toBeCloseTo(color.r, 0);
|
|
397
|
+
expect(rgb.g).toBeCloseTo(color.g, 0);
|
|
398
|
+
expect(rgb.b).toBeCloseTo(color.b, 0);
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
});
|
|
402
|
+
});
|