dev-classes 1.4.13 → 1.4.15
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
CHANGED
|
@@ -45,7 +45,7 @@ interface ColorProps{
|
|
|
45
45
|
rgbaToHsla(r: number, g: number, b: number, a: number): Color_P['ColorHsla'];
|
|
46
46
|
hslaToRgba(h: number, s: number, l: number, a: number): Color_P['ColorRgba'];
|
|
47
47
|
hslaStringToRgba(hsla: string): Color_P['ColorRgba'];
|
|
48
|
-
hexaToRgba(hexa: string): Color_P['ColorRgba'];
|
|
48
|
+
hexaToRgba(hexa: string, isNormalizeAlpha?: boolean): Color_P['ColorRgba'];
|
|
49
49
|
hexToRgb(hex: string): Color_P['ColorRgb'];
|
|
50
50
|
hexaToHsla(hexa: string): Color_P['ColorHsla'];
|
|
51
51
|
rgbaToHexa(rgba: Color_P['ColorRgba'] | Color_P['ColorRgb'] ): string;
|
|
@@ -65,6 +65,7 @@ interface ColorProps{
|
|
|
65
65
|
getTextColor(luminance: number): Color_P['ColorRgb']
|
|
66
66
|
calculateOpacity(luminance: number, targetContrast: number): number;
|
|
67
67
|
clamp(v: number, min: number, max: number): number;
|
|
68
|
+
isHex(color:string):boolean;
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
```
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
1
|
+
var x = Object.defineProperty;
|
|
2
|
+
var b = (p, t, n) => t in p ? x(p, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : p[t] = n;
|
|
3
|
+
var i = (p, t, n) => (b(p, typeof t != "symbol" ? t + "" : t, n), n);
|
|
4
4
|
const a = class a {
|
|
5
5
|
};
|
|
6
6
|
/*Проверить свои методы и возможно исключить т.к. функционал возможно повторяется */
|
|
7
|
-
|
|
7
|
+
i(a, "componentToHex", (t) => {
|
|
8
8
|
const n = t.toString(16);
|
|
9
9
|
return n.length == 1 ? "0" + n : n;
|
|
10
10
|
}), // static getNumberRGB = (getComputedStyleRGB) => {
|
|
@@ -14,15 +14,15 @@ c(a, "componentToHex", (t) => {
|
|
|
14
14
|
// }
|
|
15
15
|
// return arrSTRNumber ? arrSTRNumber : [255, 255, 255];
|
|
16
16
|
// };
|
|
17
|
-
|
|
17
|
+
i(a, "rgbToHex", (t, n, s) => "#" + a.componentToHex(t) + a.componentToHex(n) + a.componentToHex(s)), /**
|
|
18
18
|
* https://stackoverflow.com/a/54070620/6758968
|
|
19
19
|
* r, g, b in [0, 255]
|
|
20
20
|
* @returns h in [0,360) and s, v in [0,1]
|
|
21
21
|
*/
|
|
22
|
-
|
|
23
|
-
t /= 255, n /= 255,
|
|
24
|
-
const
|
|
25
|
-
return [60 * (
|
|
22
|
+
i(a, "rgbToHsv", (t, n, s) => {
|
|
23
|
+
t /= 255, n /= 255, s /= 255;
|
|
24
|
+
const r = Math.max(t, n, s), e = r - Math.min(t, n, s), c = e && (r === t ? (n - s) / e : r == n ? 2 + (s - t) / e : 4 + (t - n) / e);
|
|
25
|
+
return [60 * (c < 0 ? c + 6 : c), r && e / r, r];
|
|
26
26
|
}), /**
|
|
27
27
|
* https://stackoverflow.com/a/54024653/6758968
|
|
28
28
|
* @param h [0, 360]
|
|
@@ -30,39 +30,39 @@ c(a, "rgbToHsv", (t, n, e) => {
|
|
|
30
30
|
* @param v [0, 1]
|
|
31
31
|
* @returns r, g, b in [0, 255]
|
|
32
32
|
*/
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
return [
|
|
33
|
+
i(a, "hsvToRgb", (t, n, s) => {
|
|
34
|
+
const r = (e, c = (e + t / 60) % 6) => Math.round((s - s * n * Math.max(Math.min(c, 4 - c, 1), 0)) * 255);
|
|
35
|
+
return [r(5), r(3), r(1)];
|
|
36
36
|
}), /**
|
|
37
37
|
* @returns h [0, 360], s [0, 100], l [0, 100], a [0, 1]
|
|
38
38
|
*/
|
|
39
|
-
|
|
40
|
-
t /= 255, n /= 255,
|
|
41
|
-
const
|
|
42
|
-
let h = 0,
|
|
43
|
-
const u = (
|
|
44
|
-
if (
|
|
45
|
-
h =
|
|
39
|
+
i(a, "rgbaToHsla", (t, n, s, r = 1) => {
|
|
40
|
+
t /= 255, n /= 255, s /= 255;
|
|
41
|
+
const e = Math.max(t, n, s), c = Math.min(t, n, s);
|
|
42
|
+
let h = 0, g;
|
|
43
|
+
const u = (e + c) / 2;
|
|
44
|
+
if (e === c)
|
|
45
|
+
h = g = 0;
|
|
46
46
|
else {
|
|
47
|
-
const
|
|
48
|
-
switch (
|
|
47
|
+
const o = e - c;
|
|
48
|
+
switch (g = u > 0.5 ? o / (2 - e - c) : o / (e + c), e) {
|
|
49
49
|
case t:
|
|
50
|
-
h = (n -
|
|
50
|
+
h = (n - s) / o + (n < s ? 6 : 0);
|
|
51
51
|
break;
|
|
52
52
|
case n:
|
|
53
|
-
h = (
|
|
53
|
+
h = (s - t) / o + 2;
|
|
54
54
|
break;
|
|
55
|
-
case
|
|
56
|
-
h = (t - n) /
|
|
55
|
+
case s:
|
|
56
|
+
h = (t - n) / o + 4;
|
|
57
57
|
break;
|
|
58
58
|
}
|
|
59
59
|
h /= 6;
|
|
60
60
|
}
|
|
61
61
|
return {
|
|
62
62
|
h: h * 360,
|
|
63
|
-
s:
|
|
63
|
+
s: g * 100,
|
|
64
64
|
l: u * 100,
|
|
65
|
-
a:
|
|
65
|
+
a: r
|
|
66
66
|
};
|
|
67
67
|
}), // * https://stackoverflow.com/a/9493060/6758968
|
|
68
68
|
/**
|
|
@@ -74,77 +74,77 @@ c(a, "rgbaToHsla", (t, n, e, s = 1) => {
|
|
|
74
74
|
* @param {number} l The lightness [0, 1]
|
|
75
75
|
* @return {Array} The RGB representation [0, 255]
|
|
76
76
|
*/
|
|
77
|
-
|
|
78
|
-
t /= 360, n /= 100,
|
|
79
|
-
let
|
|
77
|
+
i(a, "hslaToRgba", (t, n, s, r) => {
|
|
78
|
+
t /= 360, n /= 100, s /= 100;
|
|
79
|
+
let e, c, h;
|
|
80
80
|
if (n === 0)
|
|
81
|
-
|
|
81
|
+
e = c = h = s;
|
|
82
82
|
else {
|
|
83
|
-
const
|
|
84
|
-
return m < 0 && (m += 1), m > 1 && (m -= 1), m < 0.16666666666666666 ? T + (
|
|
85
|
-
}, u =
|
|
86
|
-
|
|
83
|
+
const g = function(T, f, m) {
|
|
84
|
+
return m < 0 && (m += 1), m > 1 && (m -= 1), m < 0.16666666666666666 ? T + (f - T) * 6 * m : m < 0.5 ? f : m < 0.6666666666666666 ? T + (f - T) * (0.6666666666666666 - m) * 6 : T;
|
|
85
|
+
}, u = s < 0.5 ? s * (1 + n) : s + n - s * n, o = 2 * s - u;
|
|
86
|
+
e = g(o, u, t + 1 / 3), c = g(o, u, t), h = g(o, u, t - 1 / 3);
|
|
87
87
|
}
|
|
88
|
-
return [
|
|
89
|
-
}),
|
|
90
|
-
const n = t.slice(5, -1).split(", "),
|
|
91
|
-
return a.hslaToRgba(
|
|
92
|
-
}),
|
|
93
|
-
const
|
|
94
|
-
if (t.length === 5 +
|
|
95
|
-
for (let
|
|
96
|
-
|
|
97
|
-
else if (t.length === 4 +
|
|
98
|
-
for (let
|
|
99
|
-
|
|
100
|
-
|
|
88
|
+
return [e, c, h, r].map((g) => Math.round(g * 255));
|
|
89
|
+
}), i(a, "hslaStringToRgba", (t) => {
|
|
90
|
+
const n = t.slice(5, -1).split(", "), s = Number(n.pop()), r = n.map((e) => e.endsWith("%") ? +e.slice(0, -1) : +e);
|
|
91
|
+
return a.hslaToRgba(r[0], r[1], r[2], s);
|
|
92
|
+
}), i(a, "hexaToRgba", (t, n) => {
|
|
93
|
+
const s = [], r = t[0] === "#" ? 1 : 0;
|
|
94
|
+
if (t.length === 5 + r && (t = (r ? "#" : "") + "0" + t.slice(r)), t.length === 3 + r)
|
|
95
|
+
for (let e = r; e < t.length; ++e)
|
|
96
|
+
s.push(parseInt(t[e] + t[e], 16));
|
|
97
|
+
else if (t.length === 4 + r) {
|
|
98
|
+
for (let e = r; e < t.length - 1; ++e)
|
|
99
|
+
s.push(parseInt(t[e] + t[e], 16));
|
|
100
|
+
s.push(parseInt(t[t.length - 1], 16));
|
|
101
101
|
} else
|
|
102
|
-
for (let
|
|
103
|
-
|
|
104
|
-
return n;
|
|
105
|
-
}),
|
|
102
|
+
for (let e = r; e < t.length; e += 2)
|
|
103
|
+
s.push(parseInt(t.slice(e, e + 2), 16));
|
|
104
|
+
return n && s.length === 4 && (s[3] = Math.round(s[3] / 255 * 100) / 100), s;
|
|
105
|
+
}), i(a, "hexaToHsla", (t) => {
|
|
106
106
|
const n = a.hexaToRgba(t);
|
|
107
107
|
return a.rgbaToHsla(n[0], n[1], n[2], n[3]);
|
|
108
|
-
}),
|
|
109
|
-
const n = [...t],
|
|
110
|
-
return "#" + n.map((
|
|
111
|
-
}),
|
|
108
|
+
}), i(a, "hexToRgb", (t) => a.hexaToRgba(t.slice(0, 7))), i(a, "rgbaToHexa", (t) => {
|
|
109
|
+
const n = [...t], s = n.pop(), r = Math.round(Math.min(Math.max(s ?? 1, 0), 1) * 255);
|
|
110
|
+
return "#" + n.map((e) => ("0" + e.toString(16)).slice(-2)).join("") + r.toString(16);
|
|
111
|
+
}), i(a, "hslaStringToHexa", (t) => a.rgbaToHexa(a.hslaStringToRgba(t))), i(a, "hslaStringToHex", (t) => a.hslaStringToHexa(t).slice(0, -2)), /**
|
|
112
112
|
* @param weight [0, 1]
|
|
113
113
|
*/
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
for (let
|
|
117
|
-
const
|
|
118
|
-
|
|
114
|
+
i(a, "mixColors", (t, n, s) => {
|
|
115
|
+
const r = new Array(3);
|
|
116
|
+
for (let e = 0; e < 3; ++e) {
|
|
117
|
+
const c = t[e], h = n[e];
|
|
118
|
+
r[e] = Math.floor(h + (c - h) * s);
|
|
119
119
|
}
|
|
120
|
-
return
|
|
121
|
-
}),
|
|
120
|
+
return r;
|
|
121
|
+
}), i(a, "getRgbByTypeBrightness", (t) => ({
|
|
122
122
|
BT601: [0.299, 0.587, 0.114],
|
|
123
123
|
BT709: [0.2126, 0.7152, 0.0722],
|
|
124
124
|
BT2020: [0.2627, 0.678, 0.0593]
|
|
125
|
-
})[t]),
|
|
126
|
-
const
|
|
127
|
-
return
|
|
128
|
-
}),
|
|
129
|
-
const
|
|
130
|
-
if (Math.min(Math.abs(
|
|
131
|
-
return
|
|
132
|
-
const h = t[1] ? Math.min(1.5 *
|
|
133
|
-
|
|
134
|
-
let
|
|
135
|
-
const u = a.calculateBrightness(
|
|
136
|
-
if (
|
|
137
|
-
const
|
|
138
|
-
|
|
125
|
+
})[t]), i(a, "getAverageColor", (t, n) => t.map((s, r) => Math.round((s + n[r]) / 2))), i(a, "getAccentColor", (t, n, s) => {
|
|
126
|
+
const r = a.rgbToHsv(...n), e = a.rgbToHsv(...s), c = Math.min(1.5 * r[1] / t[1], 1);
|
|
127
|
+
return r[0] = Math.min(360, e[0] - r[0] + t[0]), r[1] = Math.min(1, e[1] * t[1] / r[1]), r[2] = Math.min(1, (e[2] / r[2] + c - 1) * t[2] / c), r[2] < 0.3 ? s : a.hsvToRgb(...r);
|
|
128
|
+
}), i(a, "changeColorAccent", (t, n, s, r) => {
|
|
129
|
+
const e = a.rgbToHsv(...s);
|
|
130
|
+
if (Math.min(Math.abs(e[0] - t[0]), Math.abs(e[0] - t[0] - 360)) > 30)
|
|
131
|
+
return s;
|
|
132
|
+
const h = t[1] ? Math.min(1.5 * e[1] / t[1], 1) : 0;
|
|
133
|
+
e[0] = Math.min(360, e[0] + n[0] - t[0]), e[1] = t[1] ? Math.min(1, e[1] * n[1] / t[1]) : 0, e[2] = t[2] ? Math.min(1, e[2] * (1 - h + h * n[2] / t[2])) : 0;
|
|
134
|
+
let g = a.hsvToRgb(...e);
|
|
135
|
+
const u = a.calculateBrightness(s), o = a.calculateBrightness(g);
|
|
136
|
+
if (r ? u > o : u < o) {
|
|
137
|
+
const f = 0.4 * u / o + 0.6;
|
|
138
|
+
g = a.changeBrightness(g, f);
|
|
139
139
|
}
|
|
140
|
-
return
|
|
141
|
-
}),
|
|
142
|
-
const
|
|
143
|
-
return a.rgbToHex(
|
|
144
|
-
}),
|
|
140
|
+
return g;
|
|
141
|
+
}), i(a, "changeBrightness", (t, n) => t.map((s) => a.clamp(Math.round(s * n), 0, 255))), i(a, "hexBrightness", (t, n) => {
|
|
142
|
+
const s = a.hexToRgb(t), r = a.changeBrightness(s, n), [e, c, h] = r;
|
|
143
|
+
return a.rgbToHex(e, c, h);
|
|
144
|
+
}), i(a, "getHexColorFromTelegramColor", (t) => {
|
|
145
145
|
const n = (t < 0 ? 16777215 + t : t).toString(16);
|
|
146
146
|
return "#" + (n.length >= 6 ? n : "0".repeat(6 - n.length) + n);
|
|
147
|
-
}),
|
|
147
|
+
}), i(a, "getRgbColorFromTelegramColor", (t) => a.hexToRgb(a.getHexColorFromTelegramColor(t))), // static getColorsFromWallPaper(wallPaper) {
|
|
148
148
|
// return wallPaper.settings
|
|
149
149
|
// ? [
|
|
150
150
|
// wallPaper.settings.background_color,
|
|
@@ -157,17 +157,22 @@ c(a, "mixColors", (t, n, e) => {
|
|
|
157
157
|
// .join(",")
|
|
158
158
|
// : "";
|
|
159
159
|
// }
|
|
160
|
-
|
|
161
|
-
const
|
|
162
|
-
return t.slice(0, 3).map((
|
|
163
|
-
}),
|
|
164
|
-
const [
|
|
165
|
-
return
|
|
166
|
-
}),
|
|
167
|
-
const
|
|
168
|
-
return +Math.max(0.5, Math.min(0.64,
|
|
169
|
-
}),
|
|
170
|
-
|
|
160
|
+
i(a, "rgbaToRgb", (t, n) => {
|
|
161
|
+
const s = t[3];
|
|
162
|
+
return t.slice(0, 3).map((r, e) => a.clamp(Math.round((s * (r / 255) + s * (n[e] / 255)) * 255), 0, 255));
|
|
163
|
+
}), i(a, "calculateBrightness", (t, n = "BT709") => {
|
|
164
|
+
const [s, r, e] = t, c = a.getRgbByTypeBrightness(n);
|
|
165
|
+
return c[0] * s / 255 + c[1] * r / 255 + c[2] * e / 255;
|
|
166
|
+
}), i(a, "getTextColor", (t) => t > 0.5 ? [0, 0, 0] : [255, 255, 255]), i(a, "calculateOpacity", (t, n) => {
|
|
167
|
+
const s = t > 0.5 ? 0 : 1, r = (t - s + n) / n;
|
|
168
|
+
return +Math.max(0.5, Math.min(0.64, r)).toFixed(2);
|
|
169
|
+
}), i(a, "clamp", (t, n, s) => Math.min(s, Math.max(n, t))), i(a, "isHex", (t) => {
|
|
170
|
+
if (typeof t != "string")
|
|
171
|
+
return !1;
|
|
172
|
+
const n = t.replace(/^#/, "");
|
|
173
|
+
return /^[0-9A-Fa-f]{3}$|^[0-9A-Fa-f]{6}$|^[0-9A-Fa-f]{8}$/.test(n);
|
|
174
|
+
});
|
|
175
|
+
let l = a;
|
|
171
176
|
export {
|
|
172
|
-
|
|
177
|
+
l as Color
|
|
173
178
|
};
|
|
@@ -13,7 +13,7 @@ export interface ColorProps {
|
|
|
13
13
|
rgbaToHsla(r: number, g: number, b: number, a: number): Color_P['ColorHsla'];
|
|
14
14
|
hslaToRgba(h: number, s: number, l: number, a: number): Color_P['ColorRgba'];
|
|
15
15
|
hslaStringToRgba(hsla: string): Color_P['ColorRgba'];
|
|
16
|
-
hexaToRgba(hexa: string): Color_P['ColorRgba'];
|
|
16
|
+
hexaToRgba(hexa: string, isNormalizeAlpha?: boolean): Color_P['ColorRgba'];
|
|
17
17
|
hexToRgb(hex: string): Color_P['ColorRgb'];
|
|
18
18
|
hexaToHsla(hexa: string): Color_P['ColorHsla'];
|
|
19
19
|
rgbaToHexa(rgba: Color_P['ColorRgba'] | Color_P['ColorRgb']): string;
|