meemup-library 1.1.81 → 1.1.83
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import IProduct from "..//interfaces/IProduct";
|
|
2
1
|
import IPointOfSaleSetting from "../interfaces/IPointOfSaleSetting";
|
|
2
|
+
import IDProduct from "../interfaces/database/IDProduct";
|
|
3
3
|
/**
|
|
4
4
|
* کلاس ColorController برای مدیریت رنگها و تولید رنگ متن بر اساس رنگ پس زمینه استفاده میشود.
|
|
5
5
|
*/
|
|
@@ -31,10 +31,16 @@ declare class ColorController {
|
|
|
31
31
|
* @returns رنگ متن متناظر (به صورت hex) که برای نمایش بر روی رنگ پس زمینه انتخاب شده است.
|
|
32
32
|
*/
|
|
33
33
|
generateContrastColorForBackground(background_color: string | null, default_text_color?: string): string;
|
|
34
|
-
|
|
34
|
+
generateColorForPosProduct(product: IDProduct, setting: IPointOfSaleSetting, defaultBackgroundColor: any, defaultTextColor: any): {
|
|
35
35
|
backgroundColor: any;
|
|
36
36
|
textColor: any;
|
|
37
37
|
};
|
|
38
|
+
generateColorForPosCategory(color: string | null, setting: IPointOfSaleSetting, defaultBackgroundColor: any, defaultTextColor: any): {
|
|
39
|
+
backgroundColor: any;
|
|
40
|
+
textColor: any;
|
|
41
|
+
};
|
|
42
|
+
rgbaToHexWithAlpha(rgba: string, defaultColor?: any): any;
|
|
43
|
+
hexWithAlphaToRgba(hexColor: string | null, defaultColor?: any): any;
|
|
38
44
|
}
|
|
39
45
|
declare const _default: ColorController;
|
|
40
46
|
export default _default;
|
|
@@ -83,7 +83,7 @@ class ColorController {
|
|
|
83
83
|
// اگر هیچکدام از فرمتهای بالا نبود، رنگ سیاه را برگردانید
|
|
84
84
|
return default_text_color;
|
|
85
85
|
}
|
|
86
|
-
|
|
86
|
+
generateColorForPosProduct(product, setting, defaultBackgroundColor, defaultTextColor) {
|
|
87
87
|
let textColor = defaultTextColor;
|
|
88
88
|
let backgroundColor = defaultBackgroundColor;
|
|
89
89
|
if (setting.coloredTiles) {
|
|
@@ -92,5 +92,61 @@ class ColorController {
|
|
|
92
92
|
}
|
|
93
93
|
return { backgroundColor, textColor };
|
|
94
94
|
}
|
|
95
|
+
generateColorForPosCategory(color, setting, defaultBackgroundColor, defaultTextColor) {
|
|
96
|
+
let textColor = defaultTextColor;
|
|
97
|
+
let backgroundColor = defaultBackgroundColor;
|
|
98
|
+
if (setting.coloredTiles) {
|
|
99
|
+
textColor = this.generateContrastColorForBackground(color, defaultTextColor);
|
|
100
|
+
backgroundColor = textColor === defaultTextColor ? defaultBackgroundColor : color;
|
|
101
|
+
}
|
|
102
|
+
return { backgroundColor, textColor };
|
|
103
|
+
}
|
|
104
|
+
rgbaToHexWithAlpha(rgba, defaultColor = '#00000000') {
|
|
105
|
+
// از regex برای جدا کردن مقادیر RGBA استفاده میکنیم
|
|
106
|
+
const match = rgba.match(/(\d+(\.\d+)?)/g);
|
|
107
|
+
if (!match)
|
|
108
|
+
return defaultColor;
|
|
109
|
+
// استخراج مقادیر رنگ از رشته
|
|
110
|
+
const r = parseInt(match[0], 10);
|
|
111
|
+
const g = parseInt(match[1], 10);
|
|
112
|
+
const b = parseInt(match[2], 10);
|
|
113
|
+
let a = parseFloat(match[3]);
|
|
114
|
+
// اگر مقدار شفافیت (alpha) وارد نشده باشد، مقدار پیش فرض را استفاده میکنیم
|
|
115
|
+
if (isNaN(a) || a < 0 || a > 1)
|
|
116
|
+
a = 1;
|
|
117
|
+
// تبدیل رنگ به فرمت HEX
|
|
118
|
+
const hex = `#${((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)}${Math.round(a * 255).toString(16).padStart(2, '0')}`;
|
|
119
|
+
return hex;
|
|
120
|
+
}
|
|
121
|
+
hexWithAlphaToRgba(hexColor, defaultColor = 'rgba(0, 0, 0, 1)') {
|
|
122
|
+
// اگر hexColor null یا رشته خالی بود، مقدار پیشفرض را برگردان
|
|
123
|
+
if (!hexColor || hexColor === "")
|
|
124
|
+
return defaultColor;
|
|
125
|
+
// حذف # اگر وجود داشته باشد
|
|
126
|
+
hexColor = hexColor.replace('#', '');
|
|
127
|
+
// استخراج مقادیر رنگ از رشته HEX
|
|
128
|
+
let r, g, b, a;
|
|
129
|
+
if (hexColor.length === 8) {
|
|
130
|
+
// اگر رشته HEX شامل بخش شفافیت (alpha) باشد
|
|
131
|
+
r = parseInt(hexColor.substring(0, 2), 16);
|
|
132
|
+
g = parseInt(hexColor.substring(2, 4), 16);
|
|
133
|
+
b = parseInt(hexColor.substring(4, 6), 16);
|
|
134
|
+
a = parseInt(hexColor.substring(6, 8), 16) / 255;
|
|
135
|
+
}
|
|
136
|
+
else if (hexColor.length === 6) {
|
|
137
|
+
// اگر رشته HEX بدون بخش شفافیت (alpha) باشد
|
|
138
|
+
r = parseInt(hexColor.substring(0, 2), 16);
|
|
139
|
+
g = parseInt(hexColor.substring(2, 4), 16);
|
|
140
|
+
b = parseInt(hexColor.substring(4, 6), 16);
|
|
141
|
+
a = 1; // پیشفرض: کاملاً شفاف نبودن
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
// اگر رشته HEX غیر معتبر باشد
|
|
145
|
+
throw new Error('Invalid HEX color format');
|
|
146
|
+
}
|
|
147
|
+
// ایجاد رشته RGBA
|
|
148
|
+
const rgba = `rgba(${r}, ${g}, ${b}, ${a})`;
|
|
149
|
+
return rgba;
|
|
150
|
+
}
|
|
95
151
|
}
|
|
96
152
|
export default new ColorController();
|