meemup-library 1.1.79 → 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.
@@ -1,3 +1,5 @@
1
+ import IProduct from "..//interfaces/IProduct";
2
+ import IPointOfSaleSetting from "../interfaces/IPointOfSaleSetting";
1
3
  /**
2
4
  * کلاس ColorController برای مدیریت رنگ‌ها و تولید رنگ متن بر اساس رنگ پس زمینه استفاده می‌شود.
3
5
  */
@@ -29,6 +31,12 @@ declare class ColorController {
29
31
  * @returns رنگ متن متناظر (به صورت hex) که برای نمایش بر روی رنگ پس زمینه انتخاب شده است.
30
32
  */
31
33
  generateContrastColorForBackground(background_color: string | null, default_text_color?: string): string;
34
+ generateColorForPosProductOrCategory(product: IProduct, setting: IPointOfSaleSetting, defaultBackgroundColor: any, defaultTextColor: any): {
35
+ backgroundColor: any;
36
+ textColor: any;
37
+ };
38
+ rgbaToHexWithAlpha(rgba: string, defaultColor?: any): any;
39
+ hexWithAlphaToRgba(hexColor: string | null, defaultColor?: any): any;
32
40
  }
33
41
  declare const _default: ColorController;
34
42
  export default _default;
@@ -83,5 +83,61 @@ class ColorController {
83
83
  // اگر هیچکدام از فرمت‌های بالا نبود، رنگ سیاه را برگردانید
84
84
  return default_text_color;
85
85
  }
86
+ generateColorForPosProductOrCategory(product, setting, defaultBackgroundColor, defaultTextColor) {
87
+ let textColor = defaultTextColor;
88
+ let backgroundColor = defaultBackgroundColor;
89
+ if (setting.coloredTiles) {
90
+ textColor = this.generateContrastColorForBackground(product.color, defaultTextColor);
91
+ backgroundColor = textColor === defaultTextColor ? defaultBackgroundColor : product.color;
92
+ }
93
+ return { backgroundColor, textColor };
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
+ }
86
142
  }
87
143
  export default new ColorController();
@@ -26,7 +26,7 @@ interface ICategory {
26
26
  spiciness: number;
27
27
  priority: number;
28
28
  allergicStuffs: number[];
29
- color: string;
29
+ color: string | null;
30
30
  }
31
31
  export declare const initCategory: ICategory;
32
32
  export default ICategory;
@@ -25,5 +25,5 @@ export const initCategory = {
25
25
  spiciness: 0,
26
26
  priority: 0,
27
27
  allergicStuffs: [],
28
- color: "transparent"
28
+ color: null
29
29
  };
package/package.json CHANGED
@@ -1,16 +1,17 @@
1
1
  {
2
2
  "name": "meemup-library",
3
- "version": "1.1.79",
3
+ "version": "1.1.82",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
8
- "build": "yarn remove:one && yarn remove:two && yarn build:esm && yarn build:cjs",
8
+ "build": "yarn remove:one && yarn remove:two && yarn build:esm && yarn build:cjs && yarn commit",
9
9
  "build:esm": "tsc",
10
10
  "build:cjs": "tsc --module commonjs --outDir src/dist",
11
11
  "remove:one": "rimraf dist",
12
12
  "remove:two": "rimraf ./src/dist",
13
- "test": "echo \"Error: no test specified\" && exit 1"
13
+ "test": "echo \"Error: no test specified\" && exit 1",
14
+ "commit": "git add . && git commit -m \"version.$(jq -r .version package.json)\" && git push origin "
14
15
  },
15
16
  "files": [
16
17
  "/dist"
@@ -25,4 +26,4 @@
25
26
  "dependencies": {
26
27
  "axios": "^1.6.7"
27
28
  }
28
- }
29
+ }