matterbridge 2.1.5-dev.7 → 2.1.5

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.
Files changed (112) hide show
  1. package/CHANGELOG.md +4 -2
  2. package/README-DOCKER.md +6 -0
  3. package/dist/cli.d.ts +25 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +26 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/cluster/export.d.ts +2 -0
  8. package/dist/cluster/export.d.ts.map +1 -0
  9. package/dist/cluster/export.js +2 -0
  10. package/dist/cluster/export.js.map +1 -0
  11. package/dist/defaultConfigSchema.d.ts +27 -0
  12. package/dist/defaultConfigSchema.d.ts.map +1 -0
  13. package/dist/defaultConfigSchema.js +23 -0
  14. package/dist/defaultConfigSchema.js.map +1 -0
  15. package/dist/deviceManager.d.ts +114 -0
  16. package/dist/deviceManager.d.ts.map +1 -0
  17. package/dist/deviceManager.js +94 -1
  18. package/dist/deviceManager.js.map +1 -0
  19. package/dist/frontend.d.ts +143 -0
  20. package/dist/frontend.d.ts.map +1 -0
  21. package/dist/frontend.js +270 -24
  22. package/dist/frontend.js.map +1 -0
  23. package/dist/index.d.ts +35 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +28 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/logger/export.d.ts +2 -0
  28. package/dist/logger/export.d.ts.map +1 -0
  29. package/dist/logger/export.js +1 -0
  30. package/dist/logger/export.js.map +1 -0
  31. package/dist/matter/behaviors.d.ts +2 -0
  32. package/dist/matter/behaviors.d.ts.map +1 -0
  33. package/dist/matter/behaviors.js +2 -0
  34. package/dist/matter/behaviors.js.map +1 -0
  35. package/dist/matter/clusters.d.ts +2 -0
  36. package/dist/matter/clusters.d.ts.map +1 -0
  37. package/dist/matter/clusters.js +2 -0
  38. package/dist/matter/clusters.js.map +1 -0
  39. package/dist/matter/devices.d.ts +2 -0
  40. package/dist/matter/devices.d.ts.map +1 -0
  41. package/dist/matter/devices.js +2 -0
  42. package/dist/matter/devices.js.map +1 -0
  43. package/dist/matter/endpoints.d.ts +2 -0
  44. package/dist/matter/endpoints.d.ts.map +1 -0
  45. package/dist/matter/endpoints.js +2 -0
  46. package/dist/matter/endpoints.js.map +1 -0
  47. package/dist/matter/export.d.ts +5 -0
  48. package/dist/matter/export.d.ts.map +1 -0
  49. package/dist/matter/export.js +2 -0
  50. package/dist/matter/export.js.map +1 -0
  51. package/dist/matter/types.d.ts +3 -0
  52. package/dist/matter/types.d.ts.map +1 -0
  53. package/dist/matter/types.js +2 -0
  54. package/dist/matter/types.js.map +1 -0
  55. package/dist/matterbridge.d.ts +409 -0
  56. package/dist/matterbridge.d.ts.map +1 -0
  57. package/dist/matterbridge.js +750 -41
  58. package/dist/matterbridge.js.map +1 -0
  59. package/dist/matterbridgeAccessoryPlatform.d.ts +39 -0
  60. package/dist/matterbridgeAccessoryPlatform.d.ts.map +1 -0
  61. package/dist/matterbridgeAccessoryPlatform.js +33 -0
  62. package/dist/matterbridgeAccessoryPlatform.js.map +1 -0
  63. package/dist/matterbridgeBehaviors.d.ts +1056 -0
  64. package/dist/matterbridgeBehaviors.d.ts.map +1 -0
  65. package/dist/matterbridgeBehaviors.js +32 -1
  66. package/dist/matterbridgeBehaviors.js.map +1 -0
  67. package/dist/matterbridgeDeviceTypes.d.ts +177 -0
  68. package/dist/matterbridgeDeviceTypes.d.ts.map +1 -0
  69. package/dist/matterbridgeDeviceTypes.js +112 -11
  70. package/dist/matterbridgeDeviceTypes.js.map +1 -0
  71. package/dist/matterbridgeDynamicPlatform.d.ts +39 -0
  72. package/dist/matterbridgeDynamicPlatform.d.ts.map +1 -0
  73. package/dist/matterbridgeDynamicPlatform.js +33 -0
  74. package/dist/matterbridgeDynamicPlatform.js.map +1 -0
  75. package/dist/matterbridgeEndpoint.d.ts +835 -0
  76. package/dist/matterbridgeEndpoint.d.ts.map +1 -0
  77. package/dist/matterbridgeEndpoint.js +690 -6
  78. package/dist/matterbridgeEndpoint.js.map +1 -0
  79. package/dist/matterbridgeEndpointHelpers.d.ts +2275 -0
  80. package/dist/matterbridgeEndpointHelpers.d.ts.map +1 -0
  81. package/dist/matterbridgeEndpointHelpers.js +117 -9
  82. package/dist/matterbridgeEndpointHelpers.js.map +1 -0
  83. package/dist/matterbridgePlatform.d.ts +159 -0
  84. package/dist/matterbridgePlatform.d.ts.map +1 -0
  85. package/dist/matterbridgePlatform.js +121 -5
  86. package/dist/matterbridgePlatform.js.map +1 -0
  87. package/dist/matterbridgeTypes.d.ts +169 -0
  88. package/dist/matterbridgeTypes.d.ts.map +1 -0
  89. package/dist/matterbridgeTypes.js +24 -0
  90. package/dist/matterbridgeTypes.js.map +1 -0
  91. package/dist/pluginManager.d.ts +236 -0
  92. package/dist/pluginManager.d.ts.map +1 -0
  93. package/dist/pluginManager.js +231 -4
  94. package/dist/pluginManager.js.map +1 -0
  95. package/dist/storage/export.d.ts +2 -0
  96. package/dist/storage/export.d.ts.map +1 -0
  97. package/dist/storage/export.js +1 -0
  98. package/dist/storage/export.js.map +1 -0
  99. package/dist/utils/colorUtils.d.ts +61 -0
  100. package/dist/utils/colorUtils.d.ts.map +1 -0
  101. package/dist/utils/colorUtils.js +205 -2
  102. package/dist/utils/colorUtils.js.map +1 -0
  103. package/dist/utils/export.d.ts +3 -0
  104. package/dist/utils/export.d.ts.map +1 -0
  105. package/dist/utils/export.js +1 -0
  106. package/dist/utils/export.js.map +1 -0
  107. package/dist/utils/utils.d.ts +231 -0
  108. package/dist/utils/utils.d.ts.map +1 -0
  109. package/dist/utils/utils.js +264 -10
  110. package/dist/utils/utils.js.map +1 -0
  111. package/npm-shrinkwrap.json +2 -2
  112. package/package.json +2 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"colorUtils.d.ts","sourceRoot":"","sources":["../../src/utils/colorUtils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,MAAM,WAAW,GAAG;IAClB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,MAAM,WAAW,EAAE;IACjB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,MAAM,WAAW,GAAG;IAClB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,GAAG,CA+C1F;AAGD,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,GAAG,GAAG,EAAE,CA6B9C;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,UAAU,SAAM,GAAG,GAAG,CAgD7E;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAmChD;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,GAAG,CAGjD;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAsC/C;AAwDD;;;;;;;GAOG;AAsDH;;;;;;;GAOG"}
@@ -1,3 +1,25 @@
1
+ /**
2
+ * This file contains the color utilities.
3
+ *
4
+ * @file colorUtils.ts
5
+ * @author Luca Liguori
6
+ * @date 2023-10-05
7
+ * @version 1.3.0
8
+ *
9
+ * Copyright 2023, 2024, 2025 Luca Liguori.
10
+ *
11
+ * Licensed under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License.
13
+ * You may obtain a copy of the License at
14
+ *
15
+ * http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ * See the License for the specific language governing permissions and
21
+ * limitations under the License. *
22
+ */
1
23
  import { assert } from 'console';
2
24
  export function hslColorToRgbColor(hue, saturation, luminance) {
3
25
  if (hue === 360) {
@@ -10,7 +32,7 @@ export function hslColorToRgbColor(hue, saturation, luminance) {
10
32
  luminance /= 100;
11
33
  let r, g, b;
12
34
  if (saturation === 0) {
13
- r = g = b = luminance;
35
+ r = g = b = luminance; // achromatic
14
36
  }
15
37
  else {
16
38
  const hue2rgb = (p, q, t) => {
@@ -43,21 +65,27 @@ export function hslColorToRgbColor(hue, saturation, luminance) {
43
65
  b: Math.ceil(b * 255),
44
66
  };
45
67
  }
68
+ // Converts from RGB to the XY color (CIE 1931 color space)
46
69
  export function rgbColorToXYColor(rgb) {
47
70
  let r = rgb.r / 255;
48
71
  let g = rgb.g / 255;
49
72
  let b = rgb.b / 255;
73
+ // Apply gamma correction
50
74
  r = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
51
75
  g = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
52
76
  b = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
77
+ // Scale the values to the D65 illuminant
53
78
  r = r * 100;
54
79
  g = g * 100;
55
80
  b = b * 100;
81
+ // Convert RGB to XYZ
56
82
  const X = r * 0.664511 + g * 0.154324 + b * 0.162028;
57
83
  const Y = r * 0.283881 + g * 0.668433 + b * 0.047685;
58
84
  const Z = r * 0.000088 + g * 0.07231 + b * 0.986039;
85
+ // Normalization
59
86
  let x = X / (X + Y + Z);
60
87
  let y = Y / (X + Y + Z);
88
+ // Round to 4 digits
61
89
  x = Math.round(x * 10000) / 10000;
62
90
  y = Math.round(y * 10000) / 10000;
63
91
  return { x, y };
@@ -67,9 +95,11 @@ export function xyColorToRgbColor(x, y, brightness = 254) {
67
95
  const Y = (brightness / 254).toFixed(2);
68
96
  const X = (Number(Y) / y) * x;
69
97
  const Z = (Number(Y) / y) * z;
98
+ // Convert to RGB using Wide RGB D65 conversion
70
99
  let red = X * 1.656492 - Number(Y) * 0.354851 - Z * 0.255038;
71
100
  let green = -X * 0.707196 + Number(Y) * 1.655397 + Z * 0.036152;
72
101
  let blue = X * 0.051713 - Number(Y) * 0.121364 + Z * 1.01153;
102
+ // If red, green or blue is larger than 1.0 set it back to the maximum of 1.0
73
103
  if (red > blue && red > green && red > 1.0) {
74
104
  green = green / red;
75
105
  blue = blue / red;
@@ -85,12 +115,15 @@ export function xyColorToRgbColor(x, y, brightness = 254) {
85
115
  green = green / blue;
86
116
  blue = 1.0;
87
117
  }
118
+ // Reverse gamma correction
88
119
  red = red <= 0.0031308 ? 12.92 * red : (1.0 + 0.055) * Math.pow(red, 1.0 / 2.4) - 0.055;
89
120
  green = green <= 0.0031308 ? 12.92 * green : (1.0 + 0.055) * Math.pow(green, 1.0 / 2.4) - 0.055;
90
121
  blue = blue <= 0.0031308 ? 12.92 * blue : (1.0 + 0.055) * Math.pow(blue, 1.0 / 2.4) - 0.055;
122
+ // Convert normalized decimal to decimal
91
123
  red = Math.round(red * 255);
92
124
  green = Math.round(green * 255);
93
125
  blue = Math.round(blue * 255);
126
+ // Normalize
94
127
  if (isNaN(red) || red < 0) {
95
128
  red = 0;
96
129
  }
@@ -111,7 +144,7 @@ export function rgbColorToHslColor(rgb) {
111
144
  let h = 0, s = 0;
112
145
  const l = (max + min) / 2;
113
146
  if (max === min) {
114
- h = s = 0;
147
+ h = s = 0; // achromatic
115
148
  }
116
149
  else {
117
150
  const d = max - min;
@@ -146,8 +179,10 @@ export function kelvinToMired(kelvin) {
146
179
  return Math.round(1000000 / kelvin);
147
180
  }
148
181
  export function kelvinToRGB(kelvin) {
182
+ // Clamp the temperature to the range 1000K to 40000K
149
183
  kelvin = Math.max(1000, Math.min(40000, kelvin)) / 100;
150
184
  let r, g, b;
185
+ // Calculate red
151
186
  if (kelvin <= 66) {
152
187
  r = 255;
153
188
  }
@@ -156,6 +191,7 @@ export function kelvinToRGB(kelvin) {
156
191
  r = 329.698727446 * Math.pow(r, -0.1332047592);
157
192
  r = Math.max(0, Math.min(255, r));
158
193
  }
194
+ // Calculate green
159
195
  if (kelvin <= 66) {
160
196
  g = kelvin;
161
197
  g = 99.4708025861 * Math.log(g) - 161.1195681661;
@@ -166,6 +202,7 @@ export function kelvinToRGB(kelvin) {
166
202
  g = 288.1221695283 * Math.pow(g, -0.0755148492);
167
203
  g = Math.max(0, Math.min(255, g));
168
204
  }
205
+ // Calculate blue
169
206
  if (kelvin >= 66) {
170
207
  b = 255;
171
208
  }
@@ -179,3 +216,169 @@ export function kelvinToRGB(kelvin) {
179
216
  }
180
217
  return { r: Math.round(r), g: Math.round(g), b: Math.round(b) };
181
218
  }
219
+ /*
220
+ export function testColors(): void {
221
+ // this table has been checked with different apps and sites and is correct 100%
222
+ const colors = [
223
+ { name: 'Pure Red 0', hsl: { h: 0, s: 100, l: 50 }, rgb: { r: 255, g: 0, b: 0 }, xy: { x: 0.7006, y: 0.2993 } },
224
+ { name: 'Bright Orange 30', hsl: { h: 30, s: 100, l: 50 }, rgb: { r: 255, g: 128, b: 0 }, xy: { x: 0.6112, y: 0.375 } },
225
+ { name: 'Pure Yellow 60', hsl: { h: 60, s: 100, l: 50 }, rgb: { r: 255, g: 255, b: 0 }, xy: { x: 0.4442, y: 0.5166 } },
226
+ { name: 'Lime Green 90', hsl: { h: 90, s: 100, l: 50 }, rgb: { r: 128, g: 255, b: 0 }, xy: { x: 0.2707, y: 0.6635 } },
227
+ { name: 'Pure Green 120', hsl: { h: 120, s: 100, l: 50 }, rgb: { r: 0, g: 255, b: 0 }, xy: { x: 0.1724, y: 0.7468 } },
228
+ { name: 'Light Sea Green 150', hsl: { h: 150, s: 100, l: 50 }, rgb: { r: 0, g: 255, b: 128 }, xy: { x: 0.1642, y: 0.5886 } },
229
+ { name: 'Pure Cyan 180', hsl: { h: 180, s: 100, l: 50 }, rgb: { r: 0, g: 255, b: 255 }, xy: { x: 0.1513, y: 0.3425 } },
230
+ { name: 'Deep Sky Blue 210', hsl: { h: 210, s: 100, l: 50 }, rgb: { r: 0, g: 128, b: 255 }, xy: { x: 0.1406, y: 0.1382 } },
231
+ { name: 'Pure Blue 240', hsl: { h: 240, s: 100, l: 50 }, rgb: { r: 0, g: 0, b: 255 }, xy: { x: 0.1355, y: 0.0399 } },
232
+ { name: 'Blue Violet 270', hsl: { h: 270, s: 100, l: 50 }, rgb: { r: 128, g: 0, b: 255 }, xy: { x: 0.2181, y: 0.0778 } },
233
+ { name: 'Pure Magenta 300', hsl: { h: 300, s: 100, l: 50 }, rgb: { r: 255, g: 0, b: 255 }, xy: { x: 0.3855, y: 0.1546 } },
234
+ { name: 'Deep Pink 330', hsl: { h: 330, s: 100, l: 50 }, rgb: { r: 255, g: 0, b: 128 }, xy: { x: 0.5797, y: 0.2438 } },
235
+
236
+ { name: 'Pure Red 50% 0', hsl: { h: 0, s: 50, l: 50 }, rgb: { r: 192, g: 64, b: 64 }, xy: { x: 0.6036, y: 0.3069 } },
237
+ { name: 'Bright Orange 50% 30', hsl: { h: 30, s: 50, l: 50 }, rgb: { r: 192, g: 128, b: 64 }, xy: { x: 0.5194, y: 0.3928 } },
238
+ { name: 'Pure Yellow 50% 60', hsl: { h: 60, s: 50, l: 50 }, rgb: { r: 192, g: 192, b: 64 }, xy: { x: 0.4258, y: 0.4883 } },
239
+ { name: 'Lime Green 50% 90', hsl: { h: 90, s: 50, l: 50 }, rgb: { r: 128, g: 192, b: 64 }, xy: { x: 0.3159, y: 0.5639 } },
240
+ { name: 'Pure Green 50% 120', hsl: { h: 120, s: 50, l: 50 }, rgb: { r: 64, g: 192, b: 64 }, xy: { x: 0.2127, y: 0.6349 } },
241
+ { name: 'Light Sea Green 50% 150', hsl: { h: 150, s: 50, l: 50 }, rgb: { r: 64, g: 192, b: 128 }, xy: { x: 0.1932, y: 0.4845 } },
242
+ { name: 'Pure Cyan 50% 180', hsl: { h: 180, s: 50, l: 50 }, rgb: { r: 64, g: 192, b: 192 }, xy: { x: 0.1745, y: 0.3407 } },
243
+ { name: 'Deep Sky Blue 50% 210', hsl: { h: 210, s: 50, l: 50 }, rgb: { r: 64, g: 128, b: 192 }, xy: { x: 0.1752, y: 0.211 } },
244
+ { name: 'Pure Blue 50% 240', hsl: { h: 240, s: 50, l: 50 }, rgb: { r: 64, g: 64, b: 192 }, xy: { x: 0.1758, y: 0.102 } },
245
+ { name: 'Blue Violet 50% 270', hsl: { h: 270, s: 50, l: 50 }, rgb: { r: 128, g: 64, b: 192 }, xy: { x: 0.2688, y: 0.137 } },
246
+ { name: 'Pure Magenta 50% 300', hsl: { h: 300, s: 50, l: 50 }, rgb: { r: 192, g: 64, b: 192 }, xy: { x: 0.3772, y: 0.1777 } },
247
+ { name: 'Deep Pink 50% 330', hsl: { h: 330, s: 50, l: 50 }, rgb: { r: 192, g: 64, b: 128 }, xy: { x: 0.489, y: 0.2416 } },
248
+ ];
249
+
250
+ colors.forEach((color) => {
251
+ // eslint-disable-next-line no-console
252
+ console.log(
253
+ `\x1b[48;2;${color.rgb.r};${color.rgb.g};${color.rgb.b}mColor: ${color.name}\x1b[0m, hsl: { h: ${color.hsl.h}, s: ${color.hsl.s}, l: ${color.hsl.l} }, rgb: { r: ${color.rgb.r}, g: ${color.rgb.g}, b: ${color.rgb.b} }, xy: { x: ${color.xy.x}, y: ${color.xy.y} }`,
254
+ );
255
+
256
+ const rgb = hslColorToRgbColor(color.hsl.h, color.hsl.s, color.hsl.l);
257
+ assert(rgb.r === color.rgb.r && rgb.g === color.rgb.g && rgb.b === color.rgb.b, `\x1b[48;2;${rgb.r};${rgb.g};${rgb.b}mColor: ${color.name}\x1b[0m hslColorToRgbColor { r: ${rgb.r}, g: ${rgb.g}, b: ${rgb.b} } conversion error`);
258
+
259
+ const hsl = rgbColorToHslColor({ r: color.rgb.r, g: color.rgb.g, b: color.rgb.b });
260
+ assert(hsl.h === color.hsl.h && hsl.s === color.hsl.s && hsl.l === color.hsl.l, `Color: ${color.name} rgbColorToHslColor conversion error`);
261
+
262
+ const xy = rgbColorToXYColor({ r: color.rgb.r, g: color.rgb.g, b: color.rgb.b });
263
+ assert(xy.x === color.xy.x && xy.y === color.xy.y, `Color: ${color.name} rgbColorToXYColor conversion error got x ${xy.x} y ${xy.y}`);
264
+
265
+ const rgb2 = xyColorToRgbColor(color.xy.x, color.xy.y);
266
+ assert(
267
+ rgb2.r === color.rgb.r && rgb2.g === color.rgb.g && rgb2.b === color.rgb.b,
268
+ `\x1b[48;2;${rgb2.r};${rgb2.g};${rgb2.b}mColor: ${color.name}\x1b[0m xyColorToRgbColor(${color.xy.x}, ${color.xy.y}) conversion error -> r: ${rgb2.r} g: ${rgb2.g} b: ${rgb2.g}`,
269
+ );
270
+ });
271
+ }
272
+ */
273
+ /**
274
+ * Converts CIE color space to RGB color space
275
+ * @param {Number} x
276
+ * @param {Number} y
277
+ * @param {Number} brightness - Ranges from 1 to 254
278
+ * @return {Array} Array that contains the color values for red, green and blue
279
+ * From: https://github.com/usolved/cie-rgb-converter/blob/master/cie_rgb_converter.js
280
+ */
281
+ /*
282
+ export function cie_to_rgb(x: number, y: number, brightness = 254): RGB {
283
+ // Set to maximum brightness if no custom value was given (Not the slick ECMAScript 6 way for compatibility reasons)
284
+
285
+ const z = 1.0 - x - y;
286
+ const Y = (brightness / 254).toFixed(2);
287
+ const X = (Number(Y) / y) * x;
288
+ const Z = (Number(Y) / y) * z;
289
+
290
+ // Convert to RGB using Wide RGB D65 conversion
291
+ let red = X * 1.656492 - Number(Y) * 0.354851 - Z * 0.255038;
292
+ let green = -X * 0.707196 + Number(Y) * 1.655397 + Z * 0.036152;
293
+ let blue = X * 0.051713 - Number(Y) * 0.121364 + Z * 1.01153;
294
+
295
+ // If red, green or blue is larger than 1.0 set it back to the maximum of 1.0
296
+ if (red > blue && red > green && red > 1.0) {
297
+ green = green / red;
298
+ blue = blue / red;
299
+ red = 1.0;
300
+ } else if (green > blue && green > red && green > 1.0) {
301
+ red = red / green;
302
+ blue = blue / green;
303
+ green = 1.0;
304
+ } else if (blue > red && blue > green && blue > 1.0) {
305
+ red = red / blue;
306
+ green = green / blue;
307
+ blue = 1.0;
308
+ }
309
+
310
+ // Reverse gamma correction
311
+ red = red <= 0.0031308 ? 12.92 * red : (1.0 + 0.055) * Math.pow(red, 1.0 / 2.4) - 0.055;
312
+ green = green <= 0.0031308 ? 12.92 * green : (1.0 + 0.055) * Math.pow(green, 1.0 / 2.4) - 0.055;
313
+ blue = blue <= 0.0031308 ? 12.92 * blue : (1.0 + 0.055) * Math.pow(blue, 1.0 / 2.4) - 0.055;
314
+
315
+ // Convert normalized decimal to decimal
316
+ red = Math.round(red * 255);
317
+ green = Math.round(green * 255);
318
+ blue = Math.round(blue * 255);
319
+
320
+ // Normalize
321
+ if (isNaN(red) || red < 0) {
322
+ red = 0;
323
+ }
324
+ if (isNaN(green) || green < 0) {
325
+ green = 0;
326
+ }
327
+ if (isNaN(blue) || blue < 0) {
328
+ blue = 0;
329
+ }
330
+
331
+ return { r: red, g: green, b: blue };
332
+ }
333
+ */
334
+ /**
335
+ * Converts RGB color space to CIE color space
336
+ * @param {Number} red
337
+ * @param {Number} green
338
+ * @param {Number} blue
339
+ * @return {Array} Array that contains the CIE color values for x and y
340
+ * From: https://github.com/usolved/cie-rgb-converter/blob/master/cie_rgb_converter.js
341
+ */
342
+ /*
343
+ export function rgb_to_cie(red: number, green: number, blue: number): XY {
344
+ // Apply a gamma correction to the RGB values, which makes the color more vivid and more the like the color displayed on the screen of your device
345
+ red = red > 0.04045 ? Math.pow((red + 0.055) / (1.0 + 0.055), 2.4) : red / 12.92;
346
+ green = green > 0.04045 ? Math.pow((green + 0.055) / (1.0 + 0.055), 2.4) : green / 12.92;
347
+ blue = blue > 0.04045 ? Math.pow((blue + 0.055) / (1.0 + 0.055), 2.4) : blue / 12.92;
348
+
349
+ // RGB values to XYZ using the Wide RGB D65 conversion formula
350
+ const X = red * 0.664511 + green * 0.154324 + blue * 0.162028;
351
+ const Y = red * 0.283881 + green * 0.668433 + blue * 0.047685;
352
+ const Z = red * 0.000088 + green * 0.07231 + blue * 0.986039;
353
+
354
+ // Calculate the xy values from the XYZ values
355
+ let x = (X / (X + Y + Z)).toFixed(4);
356
+ let y = (Y / (X + Y + Z)).toFixed(4);
357
+
358
+ if (isNaN(Number(x))) {
359
+ x = '0';
360
+ }
361
+
362
+ if (isNaN(Number(y))) {
363
+ y = '0';
364
+ }
365
+
366
+ return { x: Number(x), y: Number(y) };
367
+ }
368
+ */
369
+ /*
370
+ testColors();
371
+ console.log('rgb_to_cie(0, 128, 255)', rgb_to_cie(0, 128, 255));
372
+ console.log('cie_to_rgb(0.1401, 0.1284, 254)', cie_to_rgb(0.1401, 0.1284, 254));
373
+ console.log('cie_to_rgb(0.1406, 0.1382, 254)', cie_to_rgb(0.1406, 0.1382, 254));
374
+ for (let h = 0; h < 360; h++) {
375
+ const rgb = hslColorToRgbColor(h, 100, 50);
376
+ const xy = rgbColorToXYColor({ r: rgb.r, g: rgb.g, b: rgb.b });
377
+ const rgb2 = cie_to_rgb(xy.x, xy.y, 254);
378
+ const hsl = rgbColorToHslColor({ r: rgb2.r, g: rgb2.g, b: rgb2.b });
379
+ assert(rgb.r === rgb2.r && rgb.g === rgb2.g && rgb.b === rgb2.b, 'Color rgb conversion error');
380
+ assert(h === hsl.h, 'Color hsl conversion error');
381
+ console.log(`\x1b[48;2;${rgb.r};${rgb.g};${rgb.b}mColor: r:${rgb.r} g:${rgb.g} b:${rgb.b}\x1b[0m => x:${xy.x} y:${xy.y} => \x1b[48;2;${rgb2.r};${rgb2.g};${rgb2.b}mColor: r:${rgb2.r} g:${rgb2.g} b:${rgb2.b} h:${hsl.h} s:${hsl.s}\x1b[0m\x1b[K`);
382
+ }
383
+ */
384
+ //# sourceMappingURL=colorUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"colorUtils.js","sourceRoot":"","sources":["../../src/utils/colorUtils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAmBjC,MAAM,UAAU,kBAAkB,CAAC,GAAW,EAAE,UAAkB,EAAE,SAAiB;IACnF,IAAI,GAAG,KAAK,GAAG,EAAE,CAAC;QAChB,GAAG,GAAG,CAAC,CAAC;IACV,CAAC;IACD,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,EAAE,8BAA8B,CAAC,CAAC;IAC/D,MAAM,CAAC,UAAU,IAAI,CAAC,IAAI,UAAU,IAAI,GAAG,EAAE,qCAAqC,CAAC,CAAC;IACpF,MAAM,CAAC,SAAS,KAAK,EAAE,EAAE,oCAAoC,CAAC,CAAC;IAE/D,UAAU,IAAI,GAAG,CAAC;IAClB,SAAS,IAAI,GAAG,CAAC;IACjB,IAAI,CAAS,EAAE,CAAS,EAAE,CAAS,CAAC;IAEpC,IAAI,UAAU,KAAK,CAAC,EAAE,CAAC;QACrB,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,CAAC,aAAa;IACtC,CAAC;SAAM,CAAC;QACN,MAAM,OAAO,GAAG,CAAC,CAAS,EAAE,CAAS,EAAE,CAAS,EAAU,EAAE;YAC1D,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;gBACV,CAAC,IAAI,CAAC,CAAC;YACT,CAAC;YACD,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;gBACV,CAAC,IAAI,CAAC,CAAC;YACT,CAAC;YACD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;gBACd,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC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C,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC;QAChD,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;IACpC,CAAC;IAED,iBAAiB;IACjB,IAAI,MAAM,IAAI,EAAE,EAAE,CAAC;QACjB,CAAC,GAAG,GAAG,CAAC;IACV,CAAC;SAAM,IAAI,MAAM,IAAI,EAAE,EAAE,CAAC;QACxB,CAAC,GAAG,CAAC,CAAC;IACR,CAAC;SAAM,CAAC;QACN,CAAC,GAAG,MAAM,GAAG,EAAE,CAAC;QAChB,CAAC,GAAG,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC;QAClD,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;IACpC,CAAC;IAED,OAAO,EAAE,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AAClE,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqDE;AACF;;;;;;;GAOG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoDE;AACF;;;;;;;GAOG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;EA0BE;AACF;;;;;;;;;;;;;;EAcE"}
@@ -0,0 +1,3 @@
1
+ export * from './utils.js';
2
+ export * from './colorUtils.js';
3
+ //# sourceMappingURL=export.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../../src/utils/export.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC"}
@@ -1,2 +1,3 @@
1
1
  export * from './utils.js';
2
2
  export * from './colorUtils.js';
3
+ //# sourceMappingURL=export.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export.js","sourceRoot":"","sources":["../../src/utils/export.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,231 @@
1
+ /**
2
+ * This file contains the deepEqual function.
3
+ *
4
+ * @file utils.ts
5
+ * @author Luca Liguori
6
+ * @date 2024-02-17
7
+ * @version 1.2.9
8
+ *
9
+ * Copyright 2024, 2025, 2026 Luca Liguori.
10
+ *
11
+ * Licensed under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License.
13
+ * You may obtain a copy of the License at
14
+ *
15
+ * http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ * See the License for the specific language governing permissions and
21
+ * limitations under the License. *
22
+ */
23
+ /**
24
+ * Performs a deep comparison between two values to determine if they are equivalent.
25
+ * This comparison includes primitive types, arrays, and objects, allowing for optional
26
+ * exclusion of specific properties from the comparison in objects.
27
+ *
28
+ * @param {any} a The first value to compare.
29
+ * @param {any} b The second value to compare.
30
+ * @param {string[]} [excludeProperties=[]] An array of property names to exclude from the comparison in objects.
31
+ * @returns {boolean} True if the values are deeply equal, excluding any specified properties; otherwise, false.
32
+ *
33
+ * Note: This function utilizes recursion for deep comparison of nested structures and includes a debugging
34
+ * mechanism that can be toggled on or off for detailed comparison logging. It is important to ensure that
35
+ * objects do not contain circular references when enabling debug logging to avoid infinite loops.
36
+ *
37
+ * Example usage:
38
+ * ```
39
+ * const obj1 = { a: 1, b: { c: 2 } };
40
+ * const obj2 = { a: 1, b: { c: 2 } };
41
+ * console.log(deepEqual(obj1, obj2)); // true
42
+ *
43
+ * const arr1 = [1, 2, [3, 4]];
44
+ * const arr2 = [1, 2, [3, 4]];
45
+ * console.log(deepEqual(arr1, arr2)); // true
46
+ *
47
+ * const obj3 = { a: 1, b: { c: 2, d: 3 } };
48
+ * const obj4 = { a: 1, b: { c: 2 } };
49
+ * console.log(deepEqual(obj3, obj4, ['d'])); // true, excluding property 'd' from comparison
50
+ * ```
51
+ */
52
+ export declare function deepEqual(a: any, b: any, excludeProperties?: string[]): boolean;
53
+ /**
54
+ * Creates a deep copy of the given value.
55
+ *
56
+ * @template T - The type of the value being copied.
57
+ * @param {T} value - The value to be copied.
58
+ * @returns {T} - The deep copy of the value.
59
+ */
60
+ export declare function deepCopy<T>(value: T): T;
61
+ /**
62
+ * Retrieves the IPv4 address of the first non-internal network interface.
63
+ * @returns {string | undefined} The IPv4 address of the selected network interface, or undefined if not found.
64
+ */
65
+ export declare function getIpv4InterfaceAddress(): string | undefined;
66
+ /**
67
+ * Retrieves the IPv6 address of the first non-internal network interface.
68
+ * @returns {string | undefined} The IPv4 address of the selected network interface, or undefined if not found.
69
+ */
70
+ export declare function getIpv6InterfaceAddress(): string | undefined;
71
+ /**
72
+ * Retrieves the mac address of the first non-internal network interface.
73
+ * @returns {string | undefined} The IPv4 address of the selected network interface, or undefined if not found.
74
+ */
75
+ export declare function getMacAddress(): string | undefined;
76
+ /**
77
+ * Checks if a given string is a valid IPv4 address.
78
+ *
79
+ * @param {string} ipv4Address - The string to be checked.
80
+ * @returns {boolean} - Returns true if the string is a valid IPv4 address, otherwise returns false.
81
+ */
82
+ export declare function isValidIpv4Address(ipv4Address: string): boolean;
83
+ /**
84
+ * Checks if a value is a valid number within the specified range.
85
+ *
86
+ * @param {any} value - The value to be checked.
87
+ * @param {number} min - The minimum value allowed (optional).
88
+ * @param {number} max - The maximum value allowed (optional).
89
+ * @returns {boolean} Returns true if the value is a valid number within the specified range, otherwise false.
90
+ */
91
+ export declare function isValidNumber(value: any, min?: number, max?: number): value is number;
92
+ /**
93
+ * Checks if a value is a valid boolean.
94
+ *
95
+ * @param {any} value - The value to be checked.
96
+ * @returns {boolean} `true` if the value is a valid boolean, `false` otherwise.
97
+ */
98
+ export declare function isValidBoolean(value: any): value is boolean;
99
+ /**
100
+ * Checks if a value is a valid string.
101
+ *
102
+ * @param {any} value - The value to be checked.
103
+ * @param {number} minLength - The min string length (optional).
104
+ * @param {number} maxLength - The max string length (optional).
105
+ * @returns {boolean} A boolean indicating whether the value is a valid string.
106
+ */
107
+ export declare function isValidString(value: any, minLength?: number, maxLength?: number): value is string;
108
+ /**
109
+ * Checks if a value is a valid object.
110
+ *
111
+ * @param {any} value - The value to be checked.
112
+ * @param {number} minLength - The min number of keys (optional).
113
+ * @param {number} maxLength - The max number of keys (optional).
114
+ * @returns {boolean} A boolean indicating whether the value is a valid object.
115
+ */
116
+ export declare function isValidObject(value: any, minLength?: number, maxLength?: number): value is object;
117
+ /**
118
+ * Checks if a value is a valid array.
119
+ *
120
+ * @param {any} value - The value to be checked.
121
+ * @param {number} minLength - The min number of elements (optional).
122
+ * @param {number} maxLength - The max number of elements (optional).
123
+ * @returns {boolean} A boolean indicating whether the value is a valid array.
124
+ */
125
+ export declare function isValidArray(value: any, minLength?: number, maxLength?: number): value is unknown[];
126
+ /**
127
+ * Checks if the given value is null.
128
+ *
129
+ * @param {any} value - The value to check.
130
+ * @returns {boolean} `true` if the value is null, `false` otherwise.
131
+ */
132
+ export declare function isValidNull(value: any): value is null;
133
+ /**
134
+ * Checks if a value is undefined.
135
+ *
136
+ * @param {any} value - The value to check.
137
+ * @returns {boolean} `true` if the value is undefined, `false` otherwise.
138
+ */
139
+ export declare function isValidUndefined(value: any): value is undefined;
140
+ /**
141
+ * Logs the available network interfaces and their details.
142
+ * @param {boolean} log - Whether to enable logging of network interface details.
143
+ * @returns {string | undefined} The IPv6 address of the network interface, if available.
144
+ */
145
+ export declare function logInterfaces(debug?: boolean): string | undefined;
146
+ /**
147
+ * Asynchronous waiter function that resolves when the provided condition is met or rejects on timeout.
148
+ * @param {string} name - The name of the waiter.
149
+ * @param {() => boolean} check - A function that checks the condition. Should return a boolean.
150
+ * @param {boolean} [exitWithReject=false] - Optional. If true, the promise will be rejected on timeout. Default is false.
151
+ * @param {number} [resolveTimeout=5000] - Optional. The timeout duration in milliseconds. Default is 5000ms.
152
+ * @param {number} [resolveInterval=500] - Optional. The interval duration in milliseconds between condition checks. Default is 500ms.
153
+ * @param {boolean} [debug=false] - Optional. If true, debug messages will be logged to the console. Default is false.
154
+ * @returns {Promise<boolean>} A promise that resolves to true when the condition is met, or false if the timeout occurs.
155
+ */
156
+ export declare function waiter(name: string, check: () => boolean, exitWithReject?: boolean, resolveTimeout?: number, resolveInterval?: number, debug?: boolean): Promise<boolean>;
157
+ /**
158
+ * Asynchronously waits for a specified amount of time.
159
+ * @param {number} timeout - The duration to wait in milliseconds. Default is 1000ms.
160
+ * @param {string} name - The name of the wait operation. Default is undefined.
161
+ * @param {boolean} debug - Whether to enable debug logging. Default is false.
162
+ * @returns {Promise<void>} A Promise that resolves after the specified timeout.
163
+ */
164
+ export declare function wait(timeout?: number, name?: string, debug?: boolean): Promise<void>;
165
+ /**
166
+ * Creates a ZIP archive from the specified source pattern or directory and writes it to the specified output path.
167
+ *
168
+ * @param {string} outputPath - The path where the output ZIP file will be written.
169
+ * @param {string[]} sourcePaths - The source pattern or directory to be zipped (use path.join for sourcePath).
170
+ * @returns {Promise<number>} - A promise that resolves to the total number of bytes written to the ZIP file.
171
+ *
172
+ * @remarks
173
+ * This function uses the `archiver` library to create a ZIP archive. It sets the compression level to 9 (maximum compression).
174
+ * The function ensures that the output file is properly closed after the archiving process is complete.
175
+ * It logs the progress and the total number of bytes written to the console.
176
+ *
177
+ * This function uses the `glob` library to match files based on the source pattern (internally converted in posix).
178
+ */
179
+ export declare function createZip(outputPath: string, ...sourcePaths: string[]): Promise<number>;
180
+ /**
181
+ * Copies a directory and all its subdirectories and files to a new location.
182
+ *
183
+ * @param {string} srcDir - The path to the source directory.
184
+ * @param {string} destDir - The path to the destination directory.
185
+ * @returns {Promise<boolean>} - A promise that resolves when the copy operation is complete or fails for error.
186
+ * @throws {Error} - Throws an error if the copy operation fails.
187
+ */
188
+ export declare function copyDirectory(srcDir: string, destDir: string): Promise<boolean>;
189
+ /**
190
+ * Resolves the given hostname to an IP address.
191
+ *
192
+ * @param {string} hostname - The hostname to resolve.
193
+ * @param {0 | 4 | 6} [family=4] - The address family to use (0 for any, 4 for IPv4, 6 for IPv6). Default is 4.
194
+ * @returns {Promise<string | null>} - A promise that resolves to the IP address or null if not found.
195
+ *
196
+ * @remarks
197
+ * This function uses DNS lookup to resolve the hostname, which can take some time to complete.
198
+ */
199
+ export declare function resolveHostname(hostname: string, family?: 0 | 4 | 6): Promise<string | null>;
200
+ /**
201
+ * Retrieves the value of a command-line parameter.
202
+ *
203
+ * @param {string} name - The name of the parameter to retrieve.
204
+ * @returns {string | undefined} The value of the parameter, or undefined if not found.
205
+ */
206
+ export declare function getParameter(name: string): string | undefined;
207
+ /**
208
+ * Checks if a command-line parameter is present.
209
+ *
210
+ * @param {string} name - The name of the parameter to check.
211
+ * @returns {boolean} True if the parameter is present, otherwise false.
212
+ */
213
+ export declare function hasParameter(name: string): boolean;
214
+ /**
215
+ * Retrieves the value of a command-line parameter as an integer.
216
+ *
217
+ * @param {string} name - The name of the parameter to retrieve.
218
+ * @returns {number | undefined} The integer value of the parameter, or undefined if not found or invalid.
219
+ */
220
+ export declare function getIntParameter(name: string): number | undefined;
221
+ /**
222
+ * Retrieves the version of an npm package from the npm registry.
223
+ *
224
+ * @param {string} packageName - The name of the npm package.
225
+ * @param {string} [tag='latest'] - The tag of the package version to retrieve (default is 'latest').
226
+ * @param {number} [timeout=5000] - The timeout duration in milliseconds (default is 5000ms).
227
+ * @returns {Promise<string>} A promise that resolves to the version string of the package.
228
+ * @throws {Error} If the request fails or the tag is not found.
229
+ */
230
+ export declare function getNpmPackageVersion(packageName: string, tag?: string, timeout?: number): Promise<string>;
231
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAaH;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,iBAAiB,GAAE,MAAM,EAAO,GAAG,OAAO,CA6EnF;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAuCvC;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,GAAG,SAAS,CAmB5D;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,GAAG,SAAS,CAmB5D;AAED;;;GAGG;AACH,wBAAgB,aAAa,IAAI,MAAM,GAAG,SAAS,CAkBlD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAG/D;AAED;;;;;;;GAOG;AAEH,wBAAgB,aAAa,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,KAAK,IAAI,MAAM,CAKrF;AAED;;;;;GAKG;AAEH,wBAAgB,cAAc,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,OAAO,CAE3D;AAED;;;;;;;GAOG;AAEH,wBAAgB,aAAa,CAAC,KAAK,EAAE,GAAG,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,KAAK,IAAI,MAAM,CAKjG;AAED;;;;;;;GAOG;AAEH,wBAAgB,aAAa,CAAC,KAAK,EAAE,GAAG,EAAE,SAAS,CAAC,EAAE,MAAM,EA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