namirasoft-core 1.4.117 → 1.4.118

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.
@@ -0,0 +1,27 @@
1
+ export declare class ColorOperation {
2
+ private static readonly GOLDEN_ANGLE;
3
+ private static readonly BASE_HUE;
4
+ private static readonly SATURATION;
5
+ private static readonly LIGHTNESS;
6
+ private index;
7
+ constructor(startIndex?: number);
8
+ generate(): string;
9
+ peek(): string;
10
+ reset(startIndex?: number): void;
11
+ static at(index: number): string;
12
+ static generate(count: number): string[];
13
+ static random(): string;
14
+ static randoms(count: number): string[];
15
+ static next(color: string): string;
16
+ static prev(color: string): string;
17
+ static hslToHex(h: number, s: number, l: number): string;
18
+ static toHsl(color: string): {
19
+ h: number;
20
+ s: number;
21
+ l: number;
22
+ };
23
+ private static normalizeHue;
24
+ private static hexToRgb;
25
+ private static rgbToHex;
26
+ private static rgbToHsl;
27
+ }
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ColorOperation = void 0;
4
+ class ColorOperation {
5
+ constructor(startIndex = 0) {
6
+ this.index = startIndex;
7
+ }
8
+ generate() {
9
+ return ColorOperation.at(this.index++);
10
+ }
11
+ peek() {
12
+ return ColorOperation.at(this.index);
13
+ }
14
+ reset(startIndex = 0) {
15
+ this.index = startIndex;
16
+ }
17
+ static at(index) {
18
+ let hue = ColorOperation.normalizeHue(ColorOperation.BASE_HUE + index * ColorOperation.GOLDEN_ANGLE);
19
+ return ColorOperation.hslToHex(hue, ColorOperation.SATURATION, ColorOperation.LIGHTNESS);
20
+ }
21
+ static generate(count) {
22
+ let colors = [];
23
+ for (let i = 0; i < count; i++)
24
+ colors.push(ColorOperation.at(i));
25
+ return colors;
26
+ }
27
+ static random() {
28
+ return ColorOperation.hslToHex(Math.random() * 360, ColorOperation.SATURATION, ColorOperation.LIGHTNESS);
29
+ }
30
+ static randoms(count) {
31
+ let start = Math.random() * 360;
32
+ let colors = [];
33
+ for (let i = 0; i < count; i++) {
34
+ let hue = ColorOperation.normalizeHue(start + i * ColorOperation.GOLDEN_ANGLE);
35
+ colors.push(ColorOperation.hslToHex(hue, ColorOperation.SATURATION, ColorOperation.LIGHTNESS));
36
+ }
37
+ return colors;
38
+ }
39
+ static next(color) {
40
+ let { h, s, l } = ColorOperation.toHsl(color);
41
+ return ColorOperation.hslToHex(ColorOperation.normalizeHue(h + ColorOperation.GOLDEN_ANGLE), s, l);
42
+ }
43
+ static prev(color) {
44
+ let { h, s, l } = ColorOperation.toHsl(color);
45
+ return ColorOperation.hslToHex(ColorOperation.normalizeHue(h - ColorOperation.GOLDEN_ANGLE), s, l);
46
+ }
47
+ static hslToHex(h, s, l) {
48
+ h = ColorOperation.normalizeHue(h);
49
+ s = Math.max(0, Math.min(100, s)) / 100;
50
+ l = Math.max(0, Math.min(100, l)) / 100;
51
+ let c = (1 - Math.abs(2 * l - 1)) * s;
52
+ let x = c * (1 - Math.abs(((h / 60) % 2) - 1));
53
+ let m = l - c / 2;
54
+ let r = 0, g = 0, b = 0;
55
+ if (h < 60) {
56
+ r = c;
57
+ g = x;
58
+ b = 0;
59
+ }
60
+ else if (h < 120) {
61
+ r = x;
62
+ g = c;
63
+ b = 0;
64
+ }
65
+ else if (h < 180) {
66
+ r = 0;
67
+ g = c;
68
+ b = x;
69
+ }
70
+ else if (h < 240) {
71
+ r = 0;
72
+ g = x;
73
+ b = c;
74
+ }
75
+ else if (h < 300) {
76
+ r = x;
77
+ g = 0;
78
+ b = c;
79
+ }
80
+ else {
81
+ r = c;
82
+ g = 0;
83
+ b = x;
84
+ }
85
+ return ColorOperation.rgbToHex((r + m) * 255, (g + m) * 255, (b + m) * 255);
86
+ }
87
+ static toHsl(color) {
88
+ let trimmed = color.trim().toLowerCase();
89
+ if (trimmed.startsWith("hsl")) {
90
+ let parts = trimmed.replace(/hsla?\(|\)|%/g, "").split(/[\s,/]+/).filter(Boolean);
91
+ return {
92
+ h: ColorOperation.normalizeHue(parseFloat(parts[0]) || 0),
93
+ s: parseFloat(parts[1]) || 0,
94
+ l: parseFloat(parts[2]) || 0,
95
+ };
96
+ }
97
+ let { r, g, b } = ColorOperation.hexToRgb(trimmed);
98
+ return ColorOperation.rgbToHsl(r, g, b);
99
+ }
100
+ static normalizeHue(hue) {
101
+ return ((hue % 360) + 360) % 360;
102
+ }
103
+ static hexToRgb(hex) {
104
+ let value = hex.replace("#", "");
105
+ if (value.length === 3)
106
+ value = value.split("").map(ch => ch + ch).join("");
107
+ let num = parseInt(value, 16);
108
+ return {
109
+ r: (num >> 16) & 255,
110
+ g: (num >> 8) & 255,
111
+ b: num & 255,
112
+ };
113
+ }
114
+ static rgbToHex(r, g, b) {
115
+ let toHex = (v) => Math.round(Math.max(0, Math.min(255, v))).toString(16).padStart(2, "0");
116
+ return `#${toHex(r)}${toHex(g)}${toHex(b)}`.toUpperCase();
117
+ }
118
+ static rgbToHsl(r, g, b) {
119
+ r /= 255;
120
+ g /= 255;
121
+ b /= 255;
122
+ let max = Math.max(r, g, b), min = Math.min(r, g, b);
123
+ let l = (max + min) / 2;
124
+ let d = max - min;
125
+ let h = 0, s = 0;
126
+ if (d !== 0) {
127
+ s = d / (1 - Math.abs(2 * l - 1));
128
+ switch (max) {
129
+ case r:
130
+ h = ((g - b) / d) % 6;
131
+ break;
132
+ case g:
133
+ h = (b - r) / d + 2;
134
+ break;
135
+ default:
136
+ h = (r - g) / d + 4;
137
+ break;
138
+ }
139
+ h *= 60;
140
+ }
141
+ return { h: ColorOperation.normalizeHue(h), s: s * 100, l: l * 100 };
142
+ }
143
+ }
144
+ exports.ColorOperation = ColorOperation;
145
+ ColorOperation.GOLDEN_ANGLE = 137.508;
146
+ ColorOperation.BASE_HUE = 210;
147
+ ColorOperation.SATURATION = 68;
148
+ ColorOperation.LIGHTNESS = 56;
149
+ //# sourceMappingURL=ColorOperation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ColorOperation.js","sourceRo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ist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export * from "./BaseServer";
6
6
  export * from "./BaseUUID";
7
7
  export * from "./ByteOperation";
8
8
  export * from "./CacheService";
9
+ export * from "./ColorOperation";
9
10
  export * from "./ConsoleOperation";
10
11
  export * from "./ConvertService";
11
12
  export * from "./CookieService";
package/dist/index.js CHANGED
@@ -22,6 +22,7 @@ __exportStar(require("./BaseServer"), exports);
22
22
  __exportStar(require("./BaseUUID"), exports);
23
23
  __exportStar(require("./ByteOperation"), exports);
24
24
  __exportStar(require("./CacheService"), exports);
25
+ __exportStar(require("./ColorOperation"), exports);
25
26
  __exportStar(require("./ConsoleOperation"), exports);
26
27
  __exportStar(require("./ConvertService"), exports);
27
28
  __exportStar(require("./CookieService"), exports);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,mDAAiC;AACjC,qDAAmC;AACnC,kDAAgC;AAChC,+CAA6B;AAC7B,6CAA2B;AAC3B,kDAAgC;AAChC,iDAA+B;AAC/B,qDAAmC;AACnC,mDAAiC;AACjC,kDAAgC;AAChC,8CAA4B;AAC5B,4CAA0B;AAC1B,qDAAmC;AACnC,kDAAgC;AAChC,sDAAoC;AACpC,+CAA6B;AAC7B,mDAAiC;AACjC,kDAAgC;AAChC,+CAA6B;AAC7B,yDAAuC;AACvC,uDAAqC;AACrC,iDAA+B;AAC/B,kDAAgC;AAChC,8CAA4B;AAC5B,+CAA6B;AAC7B,6CAA2B;AAC3B,mDAAiC;AACjC,qDAAmC;AACnC,kDAAgC;AAChC,4DAA0C;AAC1C,yDAAuC;AACvC,oDAAkC;AAClC,qDAAmC;AACnC,kDAAgC;AAChC,mDAAiC;AACjC,oDAAkC;AAClC,sDAAoC;AACpC,mDAAiC;AACjC,mDAAiC;AACjC,oDAAkC;AAClC,qDAAmC;AACnC,6CAA2B;AAC3B,oDAAkC;AAClC,kDAAgC;AAChC,sDAAoC;AACpC,6CAA2B;AAC3B,iDAA+B;AAC/B,qDAAmC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,mDAAiC;AACjC,qDAAmC;AACnC,kDAAgC;AAChC,+CAA6B;AAC7B,6CAA2B;AAC3B,kDAAgC;AAChC,iDAA+B;AAC/B,mDAAiC;AACjC,qDAAmC;AACnC,mDAAiC;AACjC,kDAAgC;AAChC,8CAA4B;AAC5B,4CAA0B;AAC1B,qDAAmC;AACnC,kDAAgC;AAChC,sDAAoC;AACpC,+CAA6B;AAC7B,mDAAiC;AACjC,kDAAgC;AAChC,+CAA6B;AAC7B,yDAAuC;AACvC,uDAAqC;AACrC,iDAA+B;AAC/B,kDAAgC;AAChC,8CAA4B;AAC5B,+CAA6B;AAC7B,6CAA2B;AAC3B,mDAAiC;AACjC,qDAAmC;AACnC,kDAAgC;AAChC,4DAA0C;AAC1C,yDAAuC;AACvC,oDAAkC;AAClC,qDAAmC;AACnC,kDAAgC;AAChC,mDAAiC;AACjC,oDAAkC;AAClC,sDAAoC;AACpC,mDAAiC;AACjC,mDAAiC;AACjC,oDAAkC;AAClC,qDAAmC;AACnC,6CAA2B;AAC3B,oDAAkC;AAClC,kDAAgC;AAChC,sDAAoC;AACpC,6CAA2B;AAC3B,iDAA+B;AAC/B,qDAAmC"}
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "framework": "npm",
9
9
  "application": "package",
10
10
  "private": false,
11
- "version": "1.4.117",
11
+ "version": "1.4.118",
12
12
  "author": "Amir Abolhasani",
13
13
  "license": "MIT",
14
14
  "main": "./dist/index.js",
@@ -17,11 +17,11 @@
17
17
  "build": ""
18
18
  },
19
19
  "dependencies": {
20
- "@types/node": "^25.9.1",
20
+ "@types/node": "^26.0.0",
21
21
  "async-mutex": "^0.5.0",
22
- "axios": "^1.16.1",
22
+ "axios": "^1.18.1",
23
23
  "moment": "^2.30.1",
24
24
  "phone": "^3.1.71",
25
- "uuid": "^14.0.0"
25
+ "uuid": "^14.0.1"
26
26
  }
27
27
  }
@@ -0,0 +1,154 @@
1
+ export class ColorOperation
2
+ {
3
+ private static readonly GOLDEN_ANGLE = 137.508;
4
+ private static readonly BASE_HUE = 210;
5
+ private static readonly SATURATION = 68;
6
+ private static readonly LIGHTNESS = 56;
7
+
8
+ private index: number;
9
+
10
+ constructor(startIndex: number = 0)
11
+ {
12
+ this.index = startIndex;
13
+ }
14
+
15
+ generate(): string
16
+ {
17
+ return ColorOperation.at(this.index++);
18
+ }
19
+
20
+ peek(): string
21
+ {
22
+ return ColorOperation.at(this.index);
23
+ }
24
+
25
+ reset(startIndex: number = 0): void
26
+ {
27
+ this.index = startIndex;
28
+ }
29
+
30
+ static at(index: number): string
31
+ {
32
+ let hue = ColorOperation.normalizeHue(ColorOperation.BASE_HUE + index * ColorOperation.GOLDEN_ANGLE);
33
+ return ColorOperation.hslToHex(hue, ColorOperation.SATURATION, ColorOperation.LIGHTNESS);
34
+ }
35
+
36
+ static generate(count: number): string[]
37
+ {
38
+ let colors: string[] = [];
39
+ for (let i = 0; i < count; i++)
40
+ colors.push(ColorOperation.at(i));
41
+ return colors;
42
+ }
43
+
44
+ static random(): string
45
+ {
46
+ return ColorOperation.hslToHex(Math.random() * 360, ColorOperation.SATURATION, ColorOperation.LIGHTNESS);
47
+ }
48
+
49
+ static randoms(count: number): string[]
50
+ {
51
+ let start = Math.random() * 360;
52
+ let colors: string[] = [];
53
+ for (let i = 0; i < count; i++)
54
+ {
55
+ let hue = ColorOperation.normalizeHue(start + i * ColorOperation.GOLDEN_ANGLE);
56
+ colors.push(ColorOperation.hslToHex(hue, ColorOperation.SATURATION, ColorOperation.LIGHTNESS));
57
+ }
58
+ return colors;
59
+ }
60
+
61
+ static next(color: string): string
62
+ {
63
+ let { h, s, l } = ColorOperation.toHsl(color);
64
+ return ColorOperation.hslToHex(ColorOperation.normalizeHue(h + ColorOperation.GOLDEN_ANGLE), s, l);
65
+ }
66
+
67
+ static prev(color: string): string
68
+ {
69
+ let { h, s, l } = ColorOperation.toHsl(color);
70
+ return ColorOperation.hslToHex(ColorOperation.normalizeHue(h - ColorOperation.GOLDEN_ANGLE), s, l);
71
+ }
72
+
73
+ static hslToHex(h: number, s: number, l: number): string
74
+ {
75
+ h = ColorOperation.normalizeHue(h);
76
+ s = Math.max(0, Math.min(100, s)) / 100;
77
+ l = Math.max(0, Math.min(100, l)) / 100;
78
+
79
+ let c = (1 - Math.abs(2 * l - 1)) * s;
80
+ let x = c * (1 - Math.abs(((h / 60) % 2) - 1));
81
+ let m = l - c / 2;
82
+
83
+ let r = 0, g = 0, b = 0;
84
+ if (h < 60) { r = c; g = x; b = 0; }
85
+ else if (h < 120) { r = x; g = c; b = 0; }
86
+ else if (h < 180) { r = 0; g = c; b = x; }
87
+ else if (h < 240) { r = 0; g = x; b = c; }
88
+ else if (h < 300) { r = x; g = 0; b = c; }
89
+ else { r = c; g = 0; b = x; }
90
+
91
+ return ColorOperation.rgbToHex((r + m) * 255, (g + m) * 255, (b + m) * 255);
92
+ }
93
+
94
+ static toHsl(color: string): { h: number, s: number, l: number }
95
+ {
96
+ let trimmed = color.trim().toLowerCase();
97
+ if (trimmed.startsWith("hsl"))
98
+ {
99
+ let parts = trimmed.replace(/hsla?\(|\)|%/g, "").split(/[\s,/]+/).filter(Boolean);
100
+ return {
101
+ h: ColorOperation.normalizeHue(parseFloat(parts[0]) || 0),
102
+ s: parseFloat(parts[1]) || 0,
103
+ l: parseFloat(parts[2]) || 0,
104
+ };
105
+ }
106
+ let { r, g, b } = ColorOperation.hexToRgb(trimmed);
107
+ return ColorOperation.rgbToHsl(r, g, b);
108
+ }
109
+
110
+ private static normalizeHue(hue: number): number
111
+ {
112
+ return ((hue % 360) + 360) % 360;
113
+ }
114
+
115
+ private static hexToRgb(hex: string): { r: number, g: number, b: number }
116
+ {
117
+ let value = hex.replace("#", "");
118
+ if (value.length === 3)
119
+ value = value.split("").map(ch => ch + ch).join("");
120
+ let num = parseInt(value, 16);
121
+ return {
122
+ r: (num >> 16) & 255,
123
+ g: (num >> 8) & 255,
124
+ b: num & 255,
125
+ };
126
+ }
127
+
128
+ private static rgbToHex(r: number, g: number, b: number): string
129
+ {
130
+ let toHex = (v: number) => Math.round(Math.max(0, Math.min(255, v))).toString(16).padStart(2, "0");
131
+ return `#${toHex(r)}${toHex(g)}${toHex(b)}`.toUpperCase();
132
+ }
133
+
134
+ private static rgbToHsl(r: number, g: number, b: number): { h: number, s: number, l: number }
135
+ {
136
+ r /= 255; g /= 255; b /= 255;
137
+ let max = Math.max(r, g, b), min = Math.min(r, g, b);
138
+ let l = (max + min) / 2;
139
+ let d = max - min;
140
+ let h = 0, s = 0;
141
+ if (d !== 0)
142
+ {
143
+ s = d / (1 - Math.abs(2 * l - 1));
144
+ switch (max)
145
+ {
146
+ case r: h = ((g - b) / d) % 6; break;
147
+ case g: h = (b - r) / d + 2; break;
148
+ default: h = (r - g) / d + 4; break;
149
+ }
150
+ h *= 60;
151
+ }
152
+ return { h: ColorOperation.normalizeHue(h), s: s * 100, l: l * 100 };
153
+ }
154
+ }
package/src/index.ts CHANGED
@@ -6,6 +6,7 @@ export * from "./BaseServer";
6
6
  export * from "./BaseUUID";
7
7
  export * from "./ByteOperation";
8
8
  export * from "./CacheService";
9
+ export * from "./ColorOperation";
9
10
  export * from "./ConsoleOperation";
10
11
  export * from "./ConvertService";
11
12
  export * from "./CookieService";