@via-profit/ui-kit 0.2.1-alpha.1 → 0.2.2
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/Autocomplete/AutocompleteContainer.d.ts +33 -6
- package/Autocomplete/AutocompleteContainer.js +48 -36
- package/Autocomplete/AutocompleteItem.d.ts +1 -1
- package/Autocomplete/AutocompleteTextField.d.ts +3 -0
- package/Autocomplete/AutocompleteTextField.js +63 -1
- package/Autocomplete/OverrideMenuList.d.ts +4 -0
- package/Autocomplete/OverrideMenuList.js +39 -0
- package/Autocomplete/context.d.ts +9 -1
- package/Autocomplete/context.js +15 -1
- package/Autocomplete/index.js +9 -10
- package/Autocomplete2/Autocomplete2.d.ts +12 -0
- package/Autocomplete2/Autocomplete2.js +83 -0
- package/Autocomplete2/Autocomplete2TextField.d.ts +7 -0
- package/Autocomplete2/Autocomplete2TextField.js +39 -0
- package/Autocomplete2/index.d.ts +2 -0
- package/Autocomplete2/index.js +7 -0
- package/Avatar/index.js +1 -1
- package/Badge/BadgeDeleteButton.js +6 -6
- package/Badge/BadgeOutlined.js +2 -2
- package/Badge/BadgeStandard.js +1 -1
- package/Button/ButtonOutlined.js +1 -1
- package/Button/ButtonPlain.js +1 -1
- package/Button/ButtonStandard.js +4 -11
- package/Calendar/CalendarCell.js +6 -2
- package/Calendar/CalendarComponent.d.ts +226 -0
- package/Calendar/CalendarComponent.js +572 -0
- package/Calendar/CalendarControlButton.js +16 -9
- package/Calendar/CalendarDayBadge.js +1 -1
- package/Calendar/CalendarEmptyCell.d.ts +2 -2
- package/Calendar/CalendarEmptyCell.js +8 -3
- package/Calendar/CalendarHeading.js +2 -1
- package/Calendar/CalendarSubheading.js +3 -2
- package/Calendar/CalendarWeekDayCell.d.ts +10 -0
- package/Calendar/CalendarWeekDayCell.js +32 -0
- package/Calendar/CalendarWeekDayWeekNumber.d.ts +7 -0
- package/Calendar/CalendarWeekDayWeekNumber.js +38 -0
- package/Calendar/CalendarWeekRow.d.ts +2 -2
- package/Calendar/CalendarWeekRow.js +2 -1
- package/Calendar/CalendarWeekRowButton.d.ts +13 -0
- package/Calendar/CalendarWeekRowButton.js +31 -0
- package/Calendar/CalendarYearsSelector.d.ts +39 -1
- package/Calendar/CalendarYearsSelector.js +52 -16
- package/Calendar/IconChevronDown.d.ts +3 -0
- package/Calendar/IconChevronDown.js +31 -0
- package/Calendar/index.d.ts +7 -224
- package/Calendar/index.js +19 -281
- package/Calendar/use-calendar.d.ts +1 -1
- package/Color/Color.d.ts +138 -0
- package/Color/Color.js +324 -0
- package/Color/ColorGenerator.d.ts +29 -0
- package/Color/ColorGenerator.js +141 -0
- package/Color/ColorParser.d.ts +20 -0
- package/Color/ColorParser.js +284 -0
- package/Color/index.d.ts +4 -122
- package/Color/index.js +18 -473
- package/CountryFlags/SwiperOverview.d.ts +257 -0
- package/CountryFlags/SwiperOverview.js +524 -0
- package/DatePicker/index.d.ts +2 -17
- package/DatePicker/index.js +47 -61
- package/DatePicker/useDatePickerFormat.js +5 -5
- package/ErrorBoundary/Fallback.d.ts +3 -0
- package/ErrorBoundary/Fallback.js +51 -0
- package/ErrorBoundary/RenderError.d.ts +6 -0
- package/ErrorBoundary/RenderError.js +80 -0
- package/ErrorBoundary/index.d.ts +7 -11
- package/ErrorBoundary/index.js +4 -51
- package/LoadingIndicator/Spinner.d.ts +5 -3
- package/LoadingIndicator/Spinner.js +61 -32
- package/LoadingIndicator/index.d.ts +3 -3
- package/LoadingIndicator/index.js +15 -2
- package/MaskedField/index.d.ts +2 -1
- package/MaskedField/index.js +52 -43
- package/MaskedField/useMasked.js +7 -5
- package/Menu/AutoHeightWrapper.d.ts +6 -0
- package/Menu/AutoHeightWrapper.js +43 -0
- package/Menu/MeasuredItem.d.ts +10 -0
- package/Menu/MeasuredItem.js +51 -0
- package/Menu/MenuContainer.d.ts +51 -18
- package/Menu/MenuContainer.js +19 -12
- package/Menu/MenuItem.d.ts +24 -7
- package/Menu/MenuItem.js +13 -6
- package/Menu/MenuList.d.ts +4 -2
- package/Menu/MenuList.js +26 -6
- package/Menu/VirtualizedItem.d.ts +22 -0
- package/Menu/VirtualizedItem.js +69 -0
- package/Menu/VirtualizedList.d.ts +18 -0
- package/Menu/VirtualizedList.js +28 -0
- package/Menu/VirtualizedListComponent.d.ts +20 -0
- package/Menu/VirtualizedListComponent.js +305 -0
- package/Menu/index.d.ts +3 -1
- package/Menu/index.js +2 -0
- package/Popper/Popper.d.ts +7 -80
- package/Popper/Popper.js +26 -12
- package/Popper/PopperContainer.js +1 -1
- package/Popper/usePopprer.d.ts +88 -3
- package/Popper/usePopprer.js +240 -65
- package/Selectbox/SelectboxButton.d.ts +5 -0
- package/Selectbox/SelectboxButton.js +48 -8
- package/Selectbox/SelectboxButtonWrapper.d.ts +2 -0
- package/Selectbox/SelectboxButtonWrapper.js +1 -17
- package/Selectbox/SelectboxMenu.d.ts +12 -0
- package/Selectbox/SelectboxMenu.js +50 -0
- package/Selectbox/index.d.ts +5 -5
- package/Selectbox/index.js +115 -97
- package/Surface/index.js +1 -1
- package/Swiper/Swiper.d.ts +57 -0
- package/Swiper/Swiper.js +412 -0
- package/Swiper/SwiperContainer.d.ts +7 -0
- package/Swiper/SwiperContainer.js +15 -0
- package/Swiper/SwiperSlide.d.ts +12 -0
- package/Swiper/SwiperSlide.js +58 -0
- package/Swiper/SwiperSlidesRenderer.d.ts +11 -0
- package/Swiper/SwiperSlidesRenderer.js +74 -0
- package/Swiper/SwiperTrack.d.ts +18 -0
- package/Swiper/SwiperTrack.js +55 -0
- package/Swiper/SwiperWrapper.d.ts +16 -0
- package/Swiper/SwiperWrapper.js +60 -0
- package/Swiper/index.d.ts +7 -0
- package/Swiper/index.js +26 -0
- package/Switch/SwitchDot.js +1 -1
- package/Switch/SwitchTrack.js +1 -1
- package/TextField/TextFieldContainer.d.ts +2 -2
- package/TextField/TextFieldContainer.js +5 -3
- package/TextField/TextFieldErrorText.d.ts +2 -2
- package/TextField/TextFieldErrorText.js +5 -4
- package/TextField/TextFieldIconWrapper.d.ts +3 -3
- package/TextField/TextFieldIconWrapper.js +5 -3
- package/TextField/TextFieldInput.d.ts +2 -2
- package/TextField/TextFieldInput.js +6 -4
- package/TextField/TextFieldInputWrapper.d.ts +2 -2
- package/TextField/TextFieldInputWrapper.js +5 -3
- package/TextField/TextFieldLabel.d.ts +2 -2
- package/TextField/TextFieldLabel.js +5 -3
- package/TextField/TextFieldLabelAsterisk.d.ts +2 -2
- package/TextField/TextFieldLabelAsterisk.js +5 -3
- package/TextField/index.d.ts +8 -1
- package/TextField/index.js +49 -22
- package/ThemeProvider/createTheme.js +2 -2
- package/package.json +1 -1
- package/Calendar/reducer.d.ts +0 -17
- package/Calendar/reducer.js +0 -50
- /package/Calendar/{IconChevronRight.d.ts → CalendarIconNext.d.ts} +0 -0
- /package/Calendar/{IconChevronRight.js → CalendarIconNext.js} +0 -0
package/Color/Color.js
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Color = void 0;
|
|
4
|
+
const ColorParser_1 = require("./ColorParser");
|
|
5
|
+
const ColorGenerator_1 = require("./ColorGenerator");
|
|
6
|
+
class Color {
|
|
7
|
+
get r() {
|
|
8
|
+
return this._r;
|
|
9
|
+
}
|
|
10
|
+
get g() {
|
|
11
|
+
return this._g;
|
|
12
|
+
}
|
|
13
|
+
get b() {
|
|
14
|
+
return this._b;
|
|
15
|
+
}
|
|
16
|
+
get a() {
|
|
17
|
+
return this._a;
|
|
18
|
+
}
|
|
19
|
+
constructor(r, g, b, a = 1) {
|
|
20
|
+
this._r = this.clamp(r, 0, 255);
|
|
21
|
+
this._g = this.clamp(g, 0, 255);
|
|
22
|
+
this._b = this.clamp(b, 0, 255);
|
|
23
|
+
this._a = this.clamp(a, 0, 1);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Создает цвет из строкового представления
|
|
27
|
+
*/
|
|
28
|
+
static fromString(value) {
|
|
29
|
+
const parsed = ColorParser_1.ColorParser.parse(value);
|
|
30
|
+
return new Color(parsed.r, parsed.g, parsed.b, parsed.a);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Создает цвет из RGB компонентов
|
|
34
|
+
*/
|
|
35
|
+
static fromRgb(r, g, b, a = 1) {
|
|
36
|
+
return new Color(r, g, b, a);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Создает цвет из HEX строки
|
|
40
|
+
*/
|
|
41
|
+
static fromHex(hex) {
|
|
42
|
+
return Color.fromString(hex);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Создает цвет из HSL строки
|
|
46
|
+
*/
|
|
47
|
+
static fromHsl(hsl) {
|
|
48
|
+
return Color.fromString(hsl);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Создает цвет из UUID (использует генератор)
|
|
52
|
+
*/
|
|
53
|
+
static fromUuid(uuid, palette) {
|
|
54
|
+
return ColorGenerator_1.ColorGenerator.fromUuid(uuid, palette);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Создает цвет из строки с хешированием
|
|
58
|
+
*/
|
|
59
|
+
static fromHashString(str) {
|
|
60
|
+
return ColorGenerator_1.ColorGenerator.fromString(str);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Возвращает новый цвет, осветленный на указанное количество единиц
|
|
64
|
+
*/
|
|
65
|
+
lighten(units) {
|
|
66
|
+
return new Color(this.clamp(this._r + units, 0, 255), this.clamp(this._g + units, 0, 255), this.clamp(this._b + units, 0, 255), this._a);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Возвращает новый цвет, затемненный на указанное количество единиц
|
|
70
|
+
*/
|
|
71
|
+
darken(units) {
|
|
72
|
+
return this.lighten(-units);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Изменяет яркость цвета путем умножения каждого канала на коэффициент
|
|
76
|
+
* @param lum - Коэффициент изменения яркости (от -1 до 1, где отрицательные значения затемняют, положительные - осветляют)
|
|
77
|
+
* @returns Новый объект Color с измененной яркостью
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* const color = Color.fromString('#ff0000');
|
|
82
|
+
* const lighter = color.luminance(0.2); // на 20% светлее
|
|
83
|
+
* const darker = color.luminance(-0.2); // на 20% темнее
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
luminance(lum) {
|
|
87
|
+
const factor = 1 + lum;
|
|
88
|
+
return new Color(this.clamp(Math.round(this._r * factor), 0, 255), this.clamp(Math.round(this._g * factor), 0, 255), this.clamp(Math.round(this._b * factor), 0, 255), this._a);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Возвращает новый цвет с измененной яркостью (процентное изменение)
|
|
92
|
+
*/
|
|
93
|
+
adjustBrightness(percent) {
|
|
94
|
+
const factor = 1 + percent / 100;
|
|
95
|
+
return new Color(this.clamp(Math.round(this._r * factor), 0, 255), this.clamp(Math.round(this._g * factor), 0, 255), this.clamp(Math.round(this._b * factor), 0, 255), this._a);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Возвращает новый цвет с измененным альфа-каналом
|
|
99
|
+
*/
|
|
100
|
+
alpha(value) {
|
|
101
|
+
return new Color(this._r, this._g, this._b, this.clamp(value, 0, 1));
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Возвращает относительную яркость цвета (luminance)
|
|
105
|
+
*/
|
|
106
|
+
getLuminance() {
|
|
107
|
+
const RED = 0.2126;
|
|
108
|
+
const GREEN = 0.7152;
|
|
109
|
+
const BLUE = 0.0722;
|
|
110
|
+
const GAMMA = 2.4;
|
|
111
|
+
const [r, g, b] = [this._r, this._g, this._b].map(v => {
|
|
112
|
+
v /= 255;
|
|
113
|
+
return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, GAMMA);
|
|
114
|
+
});
|
|
115
|
+
return r * RED + g * GREEN + b * BLUE;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Возвращает контраст между текущим цветом и переданным
|
|
119
|
+
*/
|
|
120
|
+
getContrast(other) {
|
|
121
|
+
const otherColor = other instanceof Color ? other : Color.fromString(other);
|
|
122
|
+
const lum1 = this.getLuminance();
|
|
123
|
+
const lum2 = otherColor.getLuminance();
|
|
124
|
+
const brightest = Math.max(lum1, lum2);
|
|
125
|
+
const darkest = Math.min(lum1, lum2);
|
|
126
|
+
return (brightest + 0.05) / (darkest + 0.05);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Проверяет, достаточно ли контрастен цвет для белого текста
|
|
130
|
+
*/
|
|
131
|
+
isLight() {
|
|
132
|
+
return this.getLuminance() > 0.5;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Возвращает наиболее контрастный цвет (черный или белый)
|
|
136
|
+
*/
|
|
137
|
+
getContrastColor() {
|
|
138
|
+
return this.isLight() ? Color.fromString('#000000') : Color.fromString('#FFFFFF');
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Возвращает новый цвет, смешанный с другим цветом
|
|
142
|
+
*/
|
|
143
|
+
mix(other, weight = 0.5) {
|
|
144
|
+
const otherColor = other instanceof Color ? other : Color.fromString(other);
|
|
145
|
+
const w = this.clamp(weight, 0, 1);
|
|
146
|
+
return new Color(Math.round(this._r * (1 - w) + otherColor.r * w), Math.round(this._g * (1 - w) + otherColor.g * w), Math.round(this._b * (1 - w) + otherColor.b * w), this._a * (1 - w) + otherColor.a * w);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Возвращает цвет в разных форматах
|
|
150
|
+
*/
|
|
151
|
+
toString(format = 'rgba') {
|
|
152
|
+
switch (format) {
|
|
153
|
+
case 'hex':
|
|
154
|
+
return this.toHexString();
|
|
155
|
+
case 'rgb':
|
|
156
|
+
return this.toRgbString(false);
|
|
157
|
+
case 'rgba':
|
|
158
|
+
return this.toRgbString(true);
|
|
159
|
+
case 'hsl':
|
|
160
|
+
case 'hsla':
|
|
161
|
+
return this.toHslString(format === 'hsla');
|
|
162
|
+
default:
|
|
163
|
+
return this.toRgbString(true);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
toRgbString(includeAlpha = true) {
|
|
167
|
+
if (includeAlpha) {
|
|
168
|
+
return `rgba(${this._r}, ${this._g}, ${this._b}, ${this._a})`;
|
|
169
|
+
}
|
|
170
|
+
return `rgb(${this._r}, ${this._g}, ${this._b})`;
|
|
171
|
+
}
|
|
172
|
+
toHexString(includeAlpha = false) {
|
|
173
|
+
const toHex = (n) => {
|
|
174
|
+
const hex = Math.round(n).toString(16);
|
|
175
|
+
return hex.length === 1 ? '0' + hex : hex;
|
|
176
|
+
};
|
|
177
|
+
let hex = '#' + toHex(this._r) + toHex(this._g) + toHex(this._b);
|
|
178
|
+
if (includeAlpha && this._a < 1) {
|
|
179
|
+
hex += toHex(this._a * 255);
|
|
180
|
+
}
|
|
181
|
+
return hex;
|
|
182
|
+
}
|
|
183
|
+
toHslString(includeAlpha = true) {
|
|
184
|
+
const [h, s, l] = this.toHsl();
|
|
185
|
+
if (includeAlpha) {
|
|
186
|
+
return `hsla(${h}, ${s}%, ${l}%, ${this._a})`;
|
|
187
|
+
}
|
|
188
|
+
return `hsl(${h}, ${s}%, ${l}%)`;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Возвращает HSL представление цвета
|
|
192
|
+
*/
|
|
193
|
+
toHsl() {
|
|
194
|
+
const r = this._r / 255;
|
|
195
|
+
const g = this._g / 255;
|
|
196
|
+
const b = this._b / 255;
|
|
197
|
+
const max = Math.max(r, g, b);
|
|
198
|
+
const min = Math.min(r, g, b);
|
|
199
|
+
let h = 0, s = 0;
|
|
200
|
+
const l = (max + min) / 2;
|
|
201
|
+
if (max !== min) {
|
|
202
|
+
const d = max - min;
|
|
203
|
+
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
204
|
+
switch (max) {
|
|
205
|
+
case r:
|
|
206
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
207
|
+
break;
|
|
208
|
+
case g:
|
|
209
|
+
h = (b - r) / d + 2;
|
|
210
|
+
break;
|
|
211
|
+
case b:
|
|
212
|
+
h = (r - g) / d + 4;
|
|
213
|
+
break;
|
|
214
|
+
default:
|
|
215
|
+
// do nothing
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
h /= 6;
|
|
219
|
+
}
|
|
220
|
+
return [Math.round(h * 360), Math.round(s * 100), Math.round(l * 100)];
|
|
221
|
+
}
|
|
222
|
+
clamp(value, min, max) {
|
|
223
|
+
return Math.max(min, Math.min(max, value));
|
|
224
|
+
}
|
|
225
|
+
// #region Deprecated methods
|
|
226
|
+
/**
|
|
227
|
+
* @deprecated Use {@link Color.toRgbString} instead
|
|
228
|
+
*/
|
|
229
|
+
rgbString() {
|
|
230
|
+
return this.toRgbString();
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* @deprecated Use {@link Color.toHslString} instead
|
|
234
|
+
*/
|
|
235
|
+
hslString() {
|
|
236
|
+
return this.toHslString();
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* @deprecated Use {@link Color.toHexString} instead
|
|
240
|
+
*/
|
|
241
|
+
hexString() {
|
|
242
|
+
return this.toHexString();
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* @deprecated Use getters `color.r`, `color.g`, `color.b`, `color.a` instead.
|
|
246
|
+
* This method will be removed in future versions.
|
|
247
|
+
*
|
|
248
|
+
* @returns {ParsedColor} Object with r, g, b, a properties
|
|
249
|
+
*/
|
|
250
|
+
rgb() {
|
|
251
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
252
|
+
console.warn('[Color] rgb() is deprecated. Use getters color.r, color.g, color.b, color.a.');
|
|
253
|
+
}
|
|
254
|
+
// Возвращаем копию текущих значений для обратной совместимости
|
|
255
|
+
return {
|
|
256
|
+
r: this._r,
|
|
257
|
+
g: this._g,
|
|
258
|
+
b: this._b,
|
|
259
|
+
a: this._a,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* @deprecated Use {@Link Color.fromString} or {@Link ColorParser.parse} instead.
|
|
264
|
+
*/
|
|
265
|
+
static parseColor(value) {
|
|
266
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
267
|
+
console.warn('[Color] parseColor() is deprecated. ' +
|
|
268
|
+
'Use Color.fromString(value) or ' +
|
|
269
|
+
'ColorParser.parse(value).');
|
|
270
|
+
}
|
|
271
|
+
try {
|
|
272
|
+
return ColorParser_1.ColorParser.parse(value);
|
|
273
|
+
}
|
|
274
|
+
catch (error) {
|
|
275
|
+
console.error(`Failed to parse color value «${value}»`);
|
|
276
|
+
return { r: 0, g: 0, b: 0, a: 1 };
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* @deprecated Use {@Link Color.fromHsl} or ColorParser.parse() instead.
|
|
281
|
+
*/
|
|
282
|
+
static hslToRgb(value) {
|
|
283
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
284
|
+
console.warn('[Color] hslToRgb() is deprecated. ' +
|
|
285
|
+
'Use Color.fromHsl(value) or ColorParser.parse(value)');
|
|
286
|
+
}
|
|
287
|
+
try {
|
|
288
|
+
return ColorParser_1.ColorParser.parse(value);
|
|
289
|
+
}
|
|
290
|
+
catch (error) {
|
|
291
|
+
throw new Error(`[@via-profit/ui-kit] «${value}» Is not a valid hsl color`);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* @deprecated Use {@Link Color.fromString} with named colors instead.
|
|
296
|
+
*/
|
|
297
|
+
static getHextByWebColor(value) {
|
|
298
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
299
|
+
console.warn('[Color] getHextByWebColor() is deprecated. ' +
|
|
300
|
+
'Use Color.fromString(value).toHslString() instead');
|
|
301
|
+
}
|
|
302
|
+
return Color.fromString(value).toHslString();
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* @deprecated Do not use.
|
|
306
|
+
*/
|
|
307
|
+
static intToRGB(i) {
|
|
308
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
309
|
+
console.warn('[Color] intToRGB() is deprecated. Do not use');
|
|
310
|
+
}
|
|
311
|
+
// Сохраняем функциональность для обратной совместимости
|
|
312
|
+
const r = (i >> 16) & 0xFF;
|
|
313
|
+
const g = (i >> 8) & 0xFF;
|
|
314
|
+
const b = i & 0xFF;
|
|
315
|
+
return `rgb(${r},${g},${b})`;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* @deprecated Use {@Link Color.fromUuid}
|
|
319
|
+
*/
|
|
320
|
+
static uuidToColor(uuid) {
|
|
321
|
+
return Color.fromUuid(uuid);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
exports.Color = Color;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Color } from './Color';
|
|
2
|
+
export declare class ColorGenerator {
|
|
3
|
+
private static readonly palettes;
|
|
4
|
+
/**
|
|
5
|
+
* Генерирует цвет на основе UUID
|
|
6
|
+
*/
|
|
7
|
+
static fromUuid(uuid: string, palette?: keyof typeof ColorGenerator.palettes): Color;
|
|
8
|
+
/**
|
|
9
|
+
* Генерирует цвет на основе строки с использованием хеш-функции
|
|
10
|
+
*/
|
|
11
|
+
static fromString(str: string): Color;
|
|
12
|
+
/**
|
|
13
|
+
* Генерирует набор цветов для заданной строки (например, для градиентов)
|
|
14
|
+
*/
|
|
15
|
+
static generatePalette(str: string, count?: number): Color[];
|
|
16
|
+
/**
|
|
17
|
+
* Возвращает доступные палитры
|
|
18
|
+
*/
|
|
19
|
+
static getPalettes(): {
|
|
20
|
+
pastel: string[];
|
|
21
|
+
vibrant: string[];
|
|
22
|
+
muted: string[];
|
|
23
|
+
autumn: string[];
|
|
24
|
+
ocean: string[];
|
|
25
|
+
forest: string[];
|
|
26
|
+
};
|
|
27
|
+
private static stringToHashCode;
|
|
28
|
+
}
|
|
29
|
+
export default ColorGenerator;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ColorGenerator = void 0;
|
|
4
|
+
const Color_1 = require("./Color");
|
|
5
|
+
class ColorGenerator {
|
|
6
|
+
/**
|
|
7
|
+
* Генерирует цвет на основе UUID
|
|
8
|
+
*/
|
|
9
|
+
static fromUuid(uuid, palette = 'pastel') {
|
|
10
|
+
const hash = this.stringToHashCode(uuid);
|
|
11
|
+
const paletteColors = this.palettes[palette];
|
|
12
|
+
const index = Math.abs(hash) % paletteColors.length;
|
|
13
|
+
// Используем публичный фабричный метод вместо конструктора
|
|
14
|
+
return Color_1.Color.fromString(paletteColors[index]);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Генерирует цвет на основе строки с использованием хеш-функции
|
|
18
|
+
*/
|
|
19
|
+
static fromString(str) {
|
|
20
|
+
const hash = this.stringToHashCode(str);
|
|
21
|
+
// Генерируем цвет в HSL пространстве для более равномерного распределения
|
|
22
|
+
const h = Math.abs(hash) % 360;
|
|
23
|
+
const s = 60 + (Math.abs(hash >> 8) % 40); // 60-100%
|
|
24
|
+
const l = 40 + (Math.abs(hash >> 16) % 40); // 40-80%
|
|
25
|
+
// Используем публичный фабричный метод вместо конструктора
|
|
26
|
+
return Color_1.Color.fromString(`hsl(${h}, ${s}%, ${l}%)`);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Генерирует набор цветов для заданной строки (например, для градиентов)
|
|
30
|
+
*/
|
|
31
|
+
static generatePalette(str, count = 5) {
|
|
32
|
+
const colors = [];
|
|
33
|
+
const baseHash = this.stringToHashCode(str);
|
|
34
|
+
for (let i = 0; i < count; i++) {
|
|
35
|
+
const hash = baseHash + i * 1000;
|
|
36
|
+
const h = (Math.abs(hash) + i * 30) % 360;
|
|
37
|
+
const s = 60 + (Math.abs(hash >> 8) % 40);
|
|
38
|
+
const l = 40 + (Math.abs(hash >> 16) % 40);
|
|
39
|
+
// Используем публичный фабричный метод
|
|
40
|
+
colors.push(Color_1.Color.fromString(`hsl(${h}, ${s}%, ${l}%)`));
|
|
41
|
+
}
|
|
42
|
+
return colors;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Возвращает доступные палитры
|
|
46
|
+
*/
|
|
47
|
+
static getPalettes() {
|
|
48
|
+
return Object.assign({}, this.palettes);
|
|
49
|
+
}
|
|
50
|
+
static stringToHashCode(str) {
|
|
51
|
+
let hash = 0;
|
|
52
|
+
for (let i = 0; i < str.length; i++) {
|
|
53
|
+
const char = str.charCodeAt(i);
|
|
54
|
+
hash = (hash << 5) - hash + char;
|
|
55
|
+
hash |= 0; // Преобразуем в 32-битное целое
|
|
56
|
+
}
|
|
57
|
+
return hash;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.ColorGenerator = ColorGenerator;
|
|
61
|
+
ColorGenerator.palettes = {
|
|
62
|
+
// Пастельная палитра
|
|
63
|
+
pastel: [
|
|
64
|
+
'#FFB6C1', // Светло-розовый
|
|
65
|
+
'#B0E0E6', // Голубой
|
|
66
|
+
'#C1FFC1', // Мятный
|
|
67
|
+
'#FFDAB9', // Персиковый
|
|
68
|
+
'#E6E6FA', // Лавандовый
|
|
69
|
+
'#FFFACD', // Лимонный
|
|
70
|
+
'#F0E68C', // Хаки
|
|
71
|
+
'#DDA0DD', // Сливовый
|
|
72
|
+
'#FBCEB1', // Абрикосовый
|
|
73
|
+
'#98FB98', // Бледно-зеленый
|
|
74
|
+
],
|
|
75
|
+
// Яркая палитра
|
|
76
|
+
vibrant: [
|
|
77
|
+
'#FF4D4D', // Ярко-красный
|
|
78
|
+
'#4DFF4D', // Ярко-зеленый
|
|
79
|
+
'#4D4DFF', // Ярко-синий
|
|
80
|
+
'#FFFF4D', // Ярко-желтый
|
|
81
|
+
'#FF4DFF', // Ярко-розовый
|
|
82
|
+
'#4DFFFF', // Циан
|
|
83
|
+
'#FFA64D', // Оранжевый
|
|
84
|
+
'#B84DFF', // Фиолетовый
|
|
85
|
+
'#FF4DA6', // Розовый
|
|
86
|
+
'#4DFFB8', // Бирюзовый
|
|
87
|
+
],
|
|
88
|
+
// Приглушенная палитра
|
|
89
|
+
muted: [
|
|
90
|
+
'#8B9DC3', // Приглушенный синий
|
|
91
|
+
'#B2C9AB', // Приглушенный зеленый
|
|
92
|
+
'#D3B5B5', // Приглушенный розовый
|
|
93
|
+
'#C9B79C', // Бежевый
|
|
94
|
+
'#9F9FAD', // Серо-синий
|
|
95
|
+
'#B8A99A', // Коричневатый
|
|
96
|
+
'#A7B3A2', // Серо-зеленый
|
|
97
|
+
'#C5AFA0', // Розовато-коричневый
|
|
98
|
+
'#9A9B73', // Оливковый
|
|
99
|
+
'#B79FAD', // Сиреневый
|
|
100
|
+
],
|
|
101
|
+
// Осенняя палитра
|
|
102
|
+
autumn: [
|
|
103
|
+
'#D2691E', // Шоколадный
|
|
104
|
+
'#8B4513', // Коричневый
|
|
105
|
+
'#B22222', // Кирпичный
|
|
106
|
+
'#CD853F', // Перу
|
|
107
|
+
'#DEB887', // Дуб
|
|
108
|
+
'#F4A460', // Песочный
|
|
109
|
+
'#DAA520', // Золотой
|
|
110
|
+
'#B8860B', // Темно-золотой
|
|
111
|
+
'#A0522D', // Сиена
|
|
112
|
+
'#8B5A2B', // Темно-коричневый
|
|
113
|
+
],
|
|
114
|
+
// Морская палитра
|
|
115
|
+
ocean: [
|
|
116
|
+
'#006994', // Темно-синий
|
|
117
|
+
'#20B2AA', // Зеленовато-голубой
|
|
118
|
+
'#87CEEB', // Небесно-голубой
|
|
119
|
+
'#4682B4', // Сине-серый
|
|
120
|
+
'#5F9EA0', // Кадетский синий
|
|
121
|
+
'#00CED1', // Бирюзовый
|
|
122
|
+
'#40E0D0', // Бирюзовый светлый
|
|
123
|
+
'#48D1CC', // Средний бирюзовый
|
|
124
|
+
'#AFEEEE', // Бледно-бирюзовый
|
|
125
|
+
'#B0E0E6', // Пудрово-голубой
|
|
126
|
+
],
|
|
127
|
+
// Лесная палитра
|
|
128
|
+
forest: [
|
|
129
|
+
'#228B22', // Лесной зеленый
|
|
130
|
+
'#32CD32', // Лаймово-зеленый
|
|
131
|
+
'#6B8E23', // Оливково-зеленый
|
|
132
|
+
'#808000', // Оливковый
|
|
133
|
+
'#556B2F', // Темно-оливковый
|
|
134
|
+
'#8FBC8F', // Темно-морской зеленый
|
|
135
|
+
'#2E8B57', // Морской зеленый
|
|
136
|
+
'#3CB371', // Средний морской зеленый
|
|
137
|
+
'#66CDAA', // Средний аквамарин
|
|
138
|
+
'#90EE90', // Светло-зеленый
|
|
139
|
+
],
|
|
140
|
+
};
|
|
141
|
+
exports.default = ColorGenerator;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type ParsedColor = {
|
|
2
|
+
r: number;
|
|
3
|
+
g: number;
|
|
4
|
+
b: number;
|
|
5
|
+
a: number;
|
|
6
|
+
};
|
|
7
|
+
export declare class ColorParser {
|
|
8
|
+
private static readonly webColors;
|
|
9
|
+
/**
|
|
10
|
+
* Парсит строковое представление цвета в объект ParsedColor
|
|
11
|
+
* @throws {Error} Если не удается распарсить цвет
|
|
12
|
+
*/
|
|
13
|
+
static parse(value: string): ParsedColor;
|
|
14
|
+
private static parseHex;
|
|
15
|
+
private static parseRgb;
|
|
16
|
+
private static parseHsl;
|
|
17
|
+
private static hslToRgb;
|
|
18
|
+
private static clamp;
|
|
19
|
+
}
|
|
20
|
+
export default ColorParser;
|