@thebuoyant-tsdev/mui-ts-library 3.12.0 → 3.13.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.de.md +34 -1
- package/README.md +34 -1
- package/dist/components/color-picker/ColorPicker.d.ts +11 -0
- package/dist/components/color-picker/ColorPicker.js +527 -0
- package/dist/components/color-picker/ColorPicker.types.d.ts +65 -0
- package/dist/components/color-picker/ColorPicker.types.js +18 -0
- package/dist/components/color-picker/util/colorConversion.util.d.ts +51 -0
- package/dist/components/color-picker/util/colorConversion.util.js +166 -0
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -1
- package/package.json +2 -2
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export type ColorPickerFormat = "hex" | "rgb" | "hsl";
|
|
2
|
+
/** Clean payload passed to `onChange` alongside the primary hex string — no internal HSV state exposed. */
|
|
3
|
+
export type ColorPickerColorInfo = {
|
|
4
|
+
hex: string;
|
|
5
|
+
rgb: {
|
|
6
|
+
r: number;
|
|
7
|
+
g: number;
|
|
8
|
+
b: number;
|
|
9
|
+
a: number;
|
|
10
|
+
};
|
|
11
|
+
hsl: {
|
|
12
|
+
h: number;
|
|
13
|
+
s: number;
|
|
14
|
+
l: number;
|
|
15
|
+
a: number;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export type ColorPickerTranslation = {
|
|
19
|
+
formatLabel: string;
|
|
20
|
+
hexFieldLabel: string;
|
|
21
|
+
redLabel: string;
|
|
22
|
+
greenLabel: string;
|
|
23
|
+
blueLabel: string;
|
|
24
|
+
hueFieldLabel: string;
|
|
25
|
+
saturationFieldLabel: string;
|
|
26
|
+
lightnessFieldLabel: string;
|
|
27
|
+
alphaFieldLabel: string;
|
|
28
|
+
eyeDropperLabel: string;
|
|
29
|
+
savedColorsLabel: string;
|
|
30
|
+
gradientAreaLabel: string;
|
|
31
|
+
hueSliderLabel: string;
|
|
32
|
+
};
|
|
33
|
+
export declare const DEFAULT_COLOR_PICKER_TRANSLATION: Required<ColorPickerTranslation>;
|
|
34
|
+
export type ColorPickerProps = {
|
|
35
|
+
/** Current color — accepts hex (#rgb, #rgba, #rrggbb, #rrggbbaa), rgb()/rgba(), or hsl()/hsla(). */
|
|
36
|
+
value: string;
|
|
37
|
+
/** Fires on every change — live while dragging, on every valid keystroke, and on swatch/eyedropper picks — with a normalized hex string plus a clean rgb/hsl breakdown. */
|
|
38
|
+
onChange: (hex: string, info: ColorPickerColorInfo) => void;
|
|
39
|
+
/** Fires once per "gesture" instead of continuously: on pointer-up after a drag, on blur after typing, or immediately for atomic actions (swatch click, eyedropper). Same dual-callback pattern as MUI's own `Slider` — use this instead of debouncing `onChange` yourself for expensive side effects (persisting to a backend, etc.). */
|
|
40
|
+
onChangeCommitted?: (hex: string, info: ColorPickerColorInfo) => void;
|
|
41
|
+
/** Initial display format for the value field — uncontrolled after mount (default: 'hex'). */
|
|
42
|
+
defaultFormat?: ColorPickerFormat;
|
|
43
|
+
/** Fires when the user switches the display format via the dropdown. */
|
|
44
|
+
onFormatChange?: (format: ColorPickerFormat) => void;
|
|
45
|
+
/** Shows the alpha slider and opacity field (default: true). */
|
|
46
|
+
showAlpha?: boolean;
|
|
47
|
+
/** Shows the eyedropper tool — auto-hidden when the browser doesn't support the EyeDropper API regardless of this prop (default: true). */
|
|
48
|
+
showEyeDropper?: boolean;
|
|
49
|
+
/** Shows the eyedropper button + hue/alpha slider row (default: true). Set `false` for a minimal gradient-area-only picker. */
|
|
50
|
+
showSliderSection?: boolean;
|
|
51
|
+
/** Shows the format dropdown + hex/RGB/HSL/alpha value fields row (default: true). Set `false` for a slider-only picker. */
|
|
52
|
+
showInputSection?: boolean;
|
|
53
|
+
/** Swatches shown below the picker — click to select. Purely a display list; the caller owns persistence. */
|
|
54
|
+
savedColors?: string[];
|
|
55
|
+
disabled?: boolean;
|
|
56
|
+
/** Scales the gradient area, slider thickness, and swatch size (default: 'medium'). */
|
|
57
|
+
colorGradientSize?: "small" | "medium";
|
|
58
|
+
/** Size of the format dropdown and value/alpha input fields, independent of `colorGradientSize` (default: 'medium'). */
|
|
59
|
+
inputSize?: "small" | "medium";
|
|
60
|
+
/** Overall panel width in px (default: 280). */
|
|
61
|
+
width?: number;
|
|
62
|
+
/** Form-integration: renders a hidden input so the value participates in native/React Hook Form/Formik form submission. */
|
|
63
|
+
name?: string;
|
|
64
|
+
translation?: Partial<ColorPickerTranslation>;
|
|
65
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/components/color-picker/ColorPicker.types.ts
|
|
2
|
+
var e = {
|
|
3
|
+
formatLabel: "Color format",
|
|
4
|
+
hexFieldLabel: "Hex value",
|
|
5
|
+
redLabel: "Red",
|
|
6
|
+
greenLabel: "Green",
|
|
7
|
+
blueLabel: "Blue",
|
|
8
|
+
hueFieldLabel: "Hue",
|
|
9
|
+
saturationFieldLabel: "Saturation",
|
|
10
|
+
lightnessFieldLabel: "Lightness",
|
|
11
|
+
alphaFieldLabel: "Alpha",
|
|
12
|
+
eyeDropperLabel: "Pick color from screen",
|
|
13
|
+
savedColorsLabel: "Saved colors",
|
|
14
|
+
gradientAreaLabel: "Saturation and brightness",
|
|
15
|
+
hueSliderLabel: "Hue"
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { e as DEFAULT_COLOR_PICKER_TRANSLATION };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export type RgbaColor = {
|
|
2
|
+
r: number;
|
|
3
|
+
g: number;
|
|
4
|
+
b: number;
|
|
5
|
+
a: number;
|
|
6
|
+
};
|
|
7
|
+
export type HsvaColor = {
|
|
8
|
+
h: number;
|
|
9
|
+
s: number;
|
|
10
|
+
v: number;
|
|
11
|
+
a: number;
|
|
12
|
+
};
|
|
13
|
+
export type HslaColor = {
|
|
14
|
+
h: number;
|
|
15
|
+
s: number;
|
|
16
|
+
l: number;
|
|
17
|
+
a: number;
|
|
18
|
+
};
|
|
19
|
+
export declare function clamp(value: number, min: number, max: number): number;
|
|
20
|
+
export declare function rgbaToHex({ r, g, b, a }: RgbaColor): string;
|
|
21
|
+
export declare function hexToRgba(hex: string): RgbaColor | null;
|
|
22
|
+
export declare function hsvToRgb(h: number, s: number, v: number): {
|
|
23
|
+
r: number;
|
|
24
|
+
g: number;
|
|
25
|
+
b: number;
|
|
26
|
+
};
|
|
27
|
+
export declare function rgbToHsv(r: number, g: number, b: number): {
|
|
28
|
+
h: number;
|
|
29
|
+
s: number;
|
|
30
|
+
v: number;
|
|
31
|
+
};
|
|
32
|
+
export declare function hslToRgb(h: number, s: number, l: number): {
|
|
33
|
+
r: number;
|
|
34
|
+
g: number;
|
|
35
|
+
b: number;
|
|
36
|
+
};
|
|
37
|
+
export declare function rgbToHsl(r: number, g: number, b: number): {
|
|
38
|
+
h: number;
|
|
39
|
+
s: number;
|
|
40
|
+
l: number;
|
|
41
|
+
};
|
|
42
|
+
export declare function hsvaToRgba({ h, s, v, a }: HsvaColor): RgbaColor;
|
|
43
|
+
export declare function rgbaToHsva({ r, g, b, a }: RgbaColor): HsvaColor;
|
|
44
|
+
export declare function hsvaToHsla({ h, s, v, a }: HsvaColor): HslaColor;
|
|
45
|
+
export declare function hslaToHsva({ h, s, l, a }: HslaColor): HsvaColor;
|
|
46
|
+
/** Accepts #hex (3/4/6/8 digits), rgb()/rgba(), and hsl()/hsla() — returns null when unparseable. */
|
|
47
|
+
export declare function parseColorString(input: string): RgbaColor | null;
|
|
48
|
+
export declare function formatRgbString({ r, g, b, a }: RgbaColor): string;
|
|
49
|
+
export declare function formatHslString({ h, s, l, a }: HslaColor): string;
|
|
50
|
+
/** WCAG-style luminance heuristic — picks black or white text for readable contrast on a given background. */
|
|
51
|
+
export declare function getContrastTextColor(r: number, g: number, b: number): "#000000" | "#ffffff";
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
//#region src/components/color-picker/util/colorConversion.util.ts
|
|
2
|
+
function e(e, t, n) {
|
|
3
|
+
return Math.min(n, Math.max(t, e));
|
|
4
|
+
}
|
|
5
|
+
function t(t) {
|
|
6
|
+
return e(Math.round(t), 0, 255).toString(16).padStart(2, "0");
|
|
7
|
+
}
|
|
8
|
+
function n({ r: e, g: n, b: r, a: i }) {
|
|
9
|
+
let a = `#${t(e)}${t(n)}${t(r)}`;
|
|
10
|
+
return i < 1 ? `${a}${t(i * 255)}` : a;
|
|
11
|
+
}
|
|
12
|
+
function r(e) {
|
|
13
|
+
let t = e.trim().replace(/^#/, ""), n, r, i, a = 1;
|
|
14
|
+
if (t.length === 3 || t.length === 4) n = parseInt(t[0] + t[0], 16), r = parseInt(t[1] + t[1], 16), i = parseInt(t[2] + t[2], 16), t.length === 4 && (a = parseInt(t[3] + t[3], 16) / 255);
|
|
15
|
+
else if (t.length === 6 || t.length === 8) n = parseInt(t.slice(0, 2), 16), r = parseInt(t.slice(2, 4), 16), i = parseInt(t.slice(4, 6), 16), t.length === 8 && (a = parseInt(t.slice(6, 8), 16) / 255);
|
|
16
|
+
else return null;
|
|
17
|
+
return [
|
|
18
|
+
n,
|
|
19
|
+
r,
|
|
20
|
+
i,
|
|
21
|
+
a
|
|
22
|
+
].some((e) => Number.isNaN(e)) ? null : {
|
|
23
|
+
r: n,
|
|
24
|
+
g: r,
|
|
25
|
+
b: i,
|
|
26
|
+
a
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function i(e, t, n) {
|
|
30
|
+
let r = t / 100, i = n / 100, a = i * r, o = a * (1 - Math.abs(e / 60 % 2 - 1)), s = i - a, [c, l, u] = e < 60 ? [
|
|
31
|
+
a,
|
|
32
|
+
o,
|
|
33
|
+
0
|
|
34
|
+
] : e < 120 ? [
|
|
35
|
+
o,
|
|
36
|
+
a,
|
|
37
|
+
0
|
|
38
|
+
] : e < 180 ? [
|
|
39
|
+
0,
|
|
40
|
+
a,
|
|
41
|
+
o
|
|
42
|
+
] : e < 240 ? [
|
|
43
|
+
0,
|
|
44
|
+
o,
|
|
45
|
+
a
|
|
46
|
+
] : e < 300 ? [
|
|
47
|
+
o,
|
|
48
|
+
0,
|
|
49
|
+
a
|
|
50
|
+
] : [
|
|
51
|
+
a,
|
|
52
|
+
0,
|
|
53
|
+
o
|
|
54
|
+
];
|
|
55
|
+
return {
|
|
56
|
+
r: (c + s) * 255,
|
|
57
|
+
g: (l + s) * 255,
|
|
58
|
+
b: (u + s) * 255
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function a(e, t, n) {
|
|
62
|
+
let r = e / 255, i = t / 255, a = n / 255, o = Math.max(r, i, a), s = o - Math.min(r, i, a), c = 0;
|
|
63
|
+
s !== 0 && (c = o === r ? 60 * ((i - a) / s % 6) : o === i ? 60 * ((a - r) / s + 2) : 60 * ((r - i) / s + 4)), c < 0 && (c += 360);
|
|
64
|
+
let l = o === 0 ? 0 : s / o;
|
|
65
|
+
return {
|
|
66
|
+
h: c,
|
|
67
|
+
s: l * 100,
|
|
68
|
+
v: o * 100
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function o(e, t, n) {
|
|
72
|
+
let r = t / 100, i = n / 100, a = (1 - Math.abs(2 * i - 1)) * r, o = a * (1 - Math.abs(e / 60 % 2 - 1)), s = i - a / 2, [c, l, u] = e < 60 ? [
|
|
73
|
+
a,
|
|
74
|
+
o,
|
|
75
|
+
0
|
|
76
|
+
] : e < 120 ? [
|
|
77
|
+
o,
|
|
78
|
+
a,
|
|
79
|
+
0
|
|
80
|
+
] : e < 180 ? [
|
|
81
|
+
0,
|
|
82
|
+
a,
|
|
83
|
+
o
|
|
84
|
+
] : e < 240 ? [
|
|
85
|
+
0,
|
|
86
|
+
o,
|
|
87
|
+
a
|
|
88
|
+
] : e < 300 ? [
|
|
89
|
+
o,
|
|
90
|
+
0,
|
|
91
|
+
a
|
|
92
|
+
] : [
|
|
93
|
+
a,
|
|
94
|
+
0,
|
|
95
|
+
o
|
|
96
|
+
];
|
|
97
|
+
return {
|
|
98
|
+
r: (c + s) * 255,
|
|
99
|
+
g: (l + s) * 255,
|
|
100
|
+
b: (u + s) * 255
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function s(e, t, n) {
|
|
104
|
+
let r = e / 255, i = t / 255, a = n / 255, o = Math.max(r, i, a), s = Math.min(r, i, a), c = (o + s) / 2, l = o - s, u = 0, d = 0;
|
|
105
|
+
return l !== 0 && (d = c > .5 ? l / (2 - o - s) : l / (o + s), u = o === r ? 60 * ((i - a) / l % 6) : o === i ? 60 * ((a - r) / l + 2) : 60 * ((r - i) / l + 4)), u < 0 && (u += 360), {
|
|
106
|
+
h: u,
|
|
107
|
+
s: d * 100,
|
|
108
|
+
l: c * 100
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function c({ h: e, s: t, v: n, a: r }) {
|
|
112
|
+
let { r: a, g: o, b: s } = i(e, t, n);
|
|
113
|
+
return {
|
|
114
|
+
r: a,
|
|
115
|
+
g: o,
|
|
116
|
+
b: s,
|
|
117
|
+
a: r
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function l({ r: e, g: t, b: n, a: r }) {
|
|
121
|
+
let { h: i, s: o, v: s } = a(e, t, n);
|
|
122
|
+
return {
|
|
123
|
+
h: i,
|
|
124
|
+
s: o,
|
|
125
|
+
v: s,
|
|
126
|
+
a: r
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function u({ h: e, s: t, v: n, a: r }) {
|
|
130
|
+
let { r: a, g: o, b: c } = i(e, t, n);
|
|
131
|
+
return {
|
|
132
|
+
...s(a, o, c),
|
|
133
|
+
a: r
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function d({ h: e, s: t, l: n, a: r }) {
|
|
137
|
+
let { r: i, g: s, b: c } = o(e, t, n);
|
|
138
|
+
return {
|
|
139
|
+
...a(i, s, c),
|
|
140
|
+
a: r
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function f(e) {
|
|
144
|
+
let t = e.trim();
|
|
145
|
+
if (t.startsWith("#")) return r(t);
|
|
146
|
+
let n = t.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+)\s*)?\)$/i);
|
|
147
|
+
if (n) return {
|
|
148
|
+
r: Number(n[1]),
|
|
149
|
+
g: Number(n[2]),
|
|
150
|
+
b: Number(n[3]),
|
|
151
|
+
a: n[4] === void 0 ? 1 : Number(n[4])
|
|
152
|
+
};
|
|
153
|
+
let i = t.match(/^hsla?\(\s*([\d.]+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%\s*(?:,\s*([\d.]+)\s*)?\)$/i);
|
|
154
|
+
if (i) {
|
|
155
|
+
let { r: e, g: t, b: n } = o(Number(i[1]), Number(i[2]), Number(i[3]));
|
|
156
|
+
return {
|
|
157
|
+
r: e,
|
|
158
|
+
g: t,
|
|
159
|
+
b: n,
|
|
160
|
+
a: i[4] === void 0 ? 1 : Number(i[4])
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
//#endregion
|
|
166
|
+
export { e as clamp, r as hexToRgba, d as hslaToHsva, u as hsvaToHsla, c as hsvaToRgba, f as parseColorString, n as rgbaToHex, l as rgbaToHsva };
|