meemup-library 1.1.81 → 1.1.82

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.
@@ -35,6 +35,8 @@ declare class ColorController {
35
35
  backgroundColor: any;
36
36
  textColor: any;
37
37
  };
38
+ rgbaToHexWithAlpha(rgba: string, defaultColor?: any): any;
39
+ hexWithAlphaToRgba(hexColor: string | null, defaultColor?: any): any;
38
40
  }
39
41
  declare const _default: ColorController;
40
42
  export default _default;
@@ -92,5 +92,52 @@ class ColorController {
92
92
  }
93
93
  return { backgroundColor, textColor };
94
94
  }
95
+ rgbaToHexWithAlpha(rgba, defaultColor = '#00000000') {
96
+ // از regex برای جدا کردن مقادیر RGBA استفاده می‌کنیم
97
+ const match = rgba.match(/(\d+(\.\d+)?)/g);
98
+ if (!match)
99
+ return defaultColor;
100
+ // استخراج مقادیر رنگ از رشته
101
+ const r = parseInt(match[0], 10);
102
+ const g = parseInt(match[1], 10);
103
+ const b = parseInt(match[2], 10);
104
+ let a = parseFloat(match[3]);
105
+ // اگر مقدار شفافیت (alpha) وارد نشده باشد، مقدار پیش فرض را استفاده می‌کنیم
106
+ if (isNaN(a) || a < 0 || a > 1)
107
+ a = 1;
108
+ // تبدیل رنگ به فرمت HEX
109
+ const hex = `#${((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)}${Math.round(a * 255).toString(16).padStart(2, '0')}`;
110
+ return hex;
111
+ }
112
+ hexWithAlphaToRgba(hexColor, defaultColor = 'rgba(0, 0, 0, 1)') {
113
+ // اگر hexColor null یا رشته خالی بود، مقدار پیش‌فرض را برگردان
114
+ if (!hexColor || hexColor === "")
115
+ return defaultColor;
116
+ // حذف # اگر وجود داشته باشد
117
+ hexColor = hexColor.replace('#', '');
118
+ // استخراج مقادیر رنگ از رشته HEX
119
+ let r, g, b, a;
120
+ if (hexColor.length === 8) {
121
+ // اگر رشته HEX شامل بخش شفافیت (alpha) باشد
122
+ r = parseInt(hexColor.substring(0, 2), 16);
123
+ g = parseInt(hexColor.substring(2, 4), 16);
124
+ b = parseInt(hexColor.substring(4, 6), 16);
125
+ a = parseInt(hexColor.substring(6, 8), 16) / 255;
126
+ }
127
+ else if (hexColor.length === 6) {
128
+ // اگر رشته HEX بدون بخش شفافیت (alpha) باشد
129
+ r = parseInt(hexColor.substring(0, 2), 16);
130
+ g = parseInt(hexColor.substring(2, 4), 16);
131
+ b = parseInt(hexColor.substring(4, 6), 16);
132
+ a = 1; // پیش‌فرض: کاملاً شفاف نبودن
133
+ }
134
+ else {
135
+ // اگر رشته HEX غیر معتبر باشد
136
+ throw new Error('Invalid HEX color format');
137
+ }
138
+ // ایجاد رشته RGBA
139
+ const rgba = `rgba(${r}, ${g}, ${b}, ${a})`;
140
+ return rgba;
141
+ }
95
142
  }
96
143
  export default new ColorController();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "meemup-library",
3
- "version": "1.1.81",
3
+ "version": "1.1.82",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",