matterbridge 3.0.1-dev-20250506-c77ed36 → 3.0.1
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.
- package/CHANGELOG.md +4 -4
- package/dist/cli.d.ts +29 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +37 -2
- package/dist/cli.js.map +1 -0
- package/dist/cluster/export.d.ts +2 -0
- package/dist/cluster/export.d.ts.map +1 -0
- package/dist/cluster/export.js +2 -0
- package/dist/cluster/export.js.map +1 -0
- package/dist/defaultConfigSchema.d.ts +27 -0
- package/dist/defaultConfigSchema.d.ts.map +1 -0
- package/dist/defaultConfigSchema.js +23 -0
- package/dist/defaultConfigSchema.js.map +1 -0
- package/dist/deviceManager.d.ts +114 -0
- package/dist/deviceManager.d.ts.map +1 -0
- package/dist/deviceManager.js +94 -1
- package/dist/deviceManager.js.map +1 -0
- package/dist/frontend.d.ts +240 -0
- package/dist/frontend.d.ts.map +1 -0
- package/dist/frontend.js +328 -15
- package/dist/frontend.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -1
- package/dist/index.js.map +1 -0
- package/dist/logger/export.d.ts +2 -0
- package/dist/logger/export.d.ts.map +1 -0
- package/dist/logger/export.js +1 -0
- package/dist/logger/export.js.map +1 -0
- package/dist/matter/behaviors.d.ts +2 -0
- package/dist/matter/behaviors.d.ts.map +1 -0
- package/dist/matter/behaviors.js +2 -0
- package/dist/matter/behaviors.js.map +1 -0
- package/dist/matter/clusters.d.ts +2 -0
- package/dist/matter/clusters.d.ts.map +1 -0
- package/dist/matter/clusters.js +2 -0
- package/dist/matter/clusters.js.map +1 -0
- package/dist/matter/devices.d.ts +2 -0
- package/dist/matter/devices.d.ts.map +1 -0
- package/dist/matter/devices.js +2 -0
- package/dist/matter/devices.js.map +1 -0
- package/dist/matter/endpoints.d.ts +2 -0
- package/dist/matter/endpoints.d.ts.map +1 -0
- package/dist/matter/endpoints.js +2 -0
- package/dist/matter/endpoints.js.map +1 -0
- package/dist/matter/export.d.ts +5 -0
- package/dist/matter/export.d.ts.map +1 -0
- package/dist/matter/export.js +2 -0
- package/dist/matter/export.js.map +1 -0
- package/dist/matter/types.d.ts +3 -0
- package/dist/matter/types.d.ts.map +1 -0
- package/dist/matter/types.js +2 -0
- package/dist/matter/types.js.map +1 -0
- package/dist/matterbridge.d.ts +433 -0
- package/dist/matterbridge.d.ts.map +1 -0
- package/dist/matterbridge.js +747 -46
- package/dist/matterbridge.js.map +1 -0
- package/dist/matterbridgeAccessoryPlatform.d.ts +40 -0
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +1 -0
- package/dist/matterbridgeAccessoryPlatform.js +34 -0
- package/dist/matterbridgeAccessoryPlatform.js.map +1 -0
- package/dist/matterbridgeBehaviors.d.ts +1166 -0
- package/dist/matterbridgeBehaviors.d.ts.map +1 -0
- package/dist/matterbridgeBehaviors.js +48 -1
- package/dist/matterbridgeBehaviors.js.map +1 -0
- package/dist/matterbridgeDeviceTypes.d.ts +494 -0
- package/dist/matterbridgeDeviceTypes.d.ts.map +1 -0
- package/dist/matterbridgeDeviceTypes.js +431 -12
- package/dist/matterbridgeDeviceTypes.js.map +1 -0
- package/dist/matterbridgeDynamicPlatform.d.ts +40 -0
- package/dist/matterbridgeDynamicPlatform.d.ts.map +1 -0
- package/dist/matterbridgeDynamicPlatform.js +34 -0
- package/dist/matterbridgeDynamicPlatform.js.map +1 -0
- package/dist/matterbridgeEndpoint.d.ts +956 -0
- package/dist/matterbridgeEndpoint.d.ts.map +1 -0
- package/dist/matterbridgeEndpoint.js +801 -11
- package/dist/matterbridgeEndpoint.js.map +1 -0
- package/dist/matterbridgeEndpointHelpers.d.ts +2706 -0
- package/dist/matterbridgeEndpointHelpers.d.ts.map +1 -0
- package/dist/matterbridgeEndpointHelpers.js +142 -9
- package/dist/matterbridgeEndpointHelpers.js.map +1 -0
- package/dist/matterbridgePlatform.d.ts +294 -0
- package/dist/matterbridgePlatform.d.ts.map +1 -0
- package/dist/matterbridgePlatform.js +225 -7
- package/dist/matterbridgePlatform.js.map +1 -0
- package/dist/matterbridgeTypes.d.ts +187 -0
- package/dist/matterbridgeTypes.d.ts.map +1 -0
- package/dist/matterbridgeTypes.js +24 -0
- package/dist/matterbridgeTypes.js.map +1 -0
- package/dist/pluginManager.d.ts +273 -0
- package/dist/pluginManager.d.ts.map +1 -0
- package/dist/pluginManager.js +264 -3
- package/dist/pluginManager.js.map +1 -0
- package/dist/shelly.d.ts +92 -0
- package/dist/shelly.d.ts.map +1 -0
- package/dist/shelly.js +146 -6
- package/dist/shelly.js.map +1 -0
- package/dist/storage/export.d.ts +2 -0
- package/dist/storage/export.d.ts.map +1 -0
- package/dist/storage/export.js +1 -0
- package/dist/storage/export.js.map +1 -0
- package/dist/update.d.ts +32 -0
- package/dist/update.d.ts.map +1 -0
- package/dist/update.js +52 -0
- package/dist/update.js.map +1 -0
- package/dist/utils/colorUtils.d.ts +61 -0
- package/dist/utils/colorUtils.d.ts.map +1 -0
- package/dist/utils/colorUtils.js +205 -2
- package/dist/utils/colorUtils.js.map +1 -0
- package/dist/utils/copyDirectory.d.ts +32 -0
- package/dist/utils/copyDirectory.d.ts.map +1 -0
- package/dist/utils/copyDirectory.js +37 -1
- package/dist/utils/copyDirectory.js.map +1 -0
- package/dist/utils/createZip.d.ts +38 -0
- package/dist/utils/createZip.d.ts.map +1 -0
- package/dist/utils/createZip.js +42 -2
- package/dist/utils/createZip.js.map +1 -0
- package/dist/utils/deepCopy.d.ts +31 -0
- package/dist/utils/deepCopy.d.ts.map +1 -0
- package/dist/utils/deepCopy.js +40 -0
- package/dist/utils/deepCopy.js.map +1 -0
- package/dist/utils/deepEqual.d.ts +53 -0
- package/dist/utils/deepEqual.d.ts.map +1 -0
- package/dist/utils/deepEqual.js +65 -1
- package/dist/utils/deepEqual.js.map +1 -0
- package/dist/utils/export.d.ts +10 -0
- package/dist/utils/export.d.ts.map +1 -0
- package/dist/utils/export.js +1 -0
- package/dist/utils/export.js.map +1 -0
- package/dist/utils/isvalid.d.ts +95 -0
- package/dist/utils/isvalid.d.ts.map +1 -0
- package/dist/utils/isvalid.js +93 -0
- package/dist/utils/isvalid.js.map +1 -0
- package/dist/utils/network.d.ts +69 -0
- package/dist/utils/network.d.ts.map +1 -0
- package/dist/utils/network.js +76 -5
- package/dist/utils/network.js.map +1 -0
- package/dist/utils/parameter.d.ts +58 -0
- package/dist/utils/parameter.d.ts.map +1 -0
- package/dist/utils/parameter.js +53 -0
- package/dist/utils/parameter.js.map +1 -0
- package/dist/utils/wait.d.ts +43 -0
- package/dist/utils/wait.d.ts.map +1 -0
- package/dist/utils/wait.js +48 -5
- package/dist/utils/wait.js.map +1 -0
- package/frontend/build/asset-manifest.json +3 -3
- package/frontend/build/index.html +1 -1
- package/frontend/build/static/js/{main.f221e2c1.js → main.15906009.js} +3 -3
- package/frontend/build/static/js/{main.f221e2c1.js.map → main.15906009.js.map} +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -1
- /package/frontend/build/static/js/{main.f221e2c1.js.LICENSE.txt → main.15906009.js.LICENSE.txt} +0 -0
package/dist/utils/colorUtils.js
CHANGED
|
@@ -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 'node: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,cAAc,CAAC;AAmBtC,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,KA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C,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,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file contains the copyDirectory function.
|
|
3
|
+
*
|
|
4
|
+
* @file copyDirectory.ts
|
|
5
|
+
* @author Luca Liguori
|
|
6
|
+
* @date 2025-02-16
|
|
7
|
+
* @version 1.0.0
|
|
8
|
+
*
|
|
9
|
+
* Copyright 2025, 2026, 2027 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
|
+
* Copies a directory and all its subdirectories and files to a new location.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} srcDir - The path to the source directory.
|
|
27
|
+
* @param {string} destDir - The path to the destination directory.
|
|
28
|
+
* @returns {Promise<boolean>} - A promise that resolves when the copy operation is complete or fails for error.
|
|
29
|
+
* @throws {Error} - Throws an error if the copy operation fails.
|
|
30
|
+
*/
|
|
31
|
+
export declare function copyDirectory(srcDir: string, destDir: string): Promise<boolean>;
|
|
32
|
+
//# sourceMappingURL=copyDirectory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copyDirectory.d.ts","sourceRoot":"","sources":["../../src/utils/copyDirectory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAKH;;;;;;;GAOG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CA+BrF"}
|
|
@@ -1,19 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file contains the copyDirectory function.
|
|
3
|
+
*
|
|
4
|
+
* @file copyDirectory.ts
|
|
5
|
+
* @author Luca Liguori
|
|
6
|
+
* @date 2025-02-16
|
|
7
|
+
* @version 1.0.0
|
|
8
|
+
*
|
|
9
|
+
* Copyright 2025, 2026, 2027 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
|
+
// AnsiLogger module
|
|
1
24
|
import { AnsiLogger } from '../logger/export.js';
|
|
25
|
+
/**
|
|
26
|
+
* Copies a directory and all its subdirectories and files to a new location.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} srcDir - The path to the source directory.
|
|
29
|
+
* @param {string} destDir - The path to the destination directory.
|
|
30
|
+
* @returns {Promise<boolean>} - A promise that resolves when the copy operation is complete or fails for error.
|
|
31
|
+
* @throws {Error} - Throws an error if the copy operation fails.
|
|
32
|
+
*/
|
|
2
33
|
export async function copyDirectory(srcDir, destDir) {
|
|
3
|
-
const log = new AnsiLogger({ logName: 'Archive', logTimestampFormat: 4
|
|
34
|
+
const log = new AnsiLogger({ logName: 'Archive', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: "info" /* LogLevel.INFO */ });
|
|
4
35
|
const fs = await import('node:fs').then((mod) => mod.promises);
|
|
5
36
|
const path = await import('node:path');
|
|
6
37
|
log.debug(`copyDirectory: copying directory from ${srcDir} to ${destDir}`);
|
|
7
38
|
try {
|
|
39
|
+
// Create destination directory if it doesn't exist
|
|
8
40
|
await fs.mkdir(destDir, { recursive: true });
|
|
41
|
+
// Read contents of the source directory
|
|
9
42
|
const entries = await fs.readdir(srcDir, { withFileTypes: true });
|
|
10
43
|
for (const entry of entries) {
|
|
11
44
|
const srcPath = path.join(srcDir, entry.name);
|
|
12
45
|
const destPath = path.join(destDir, entry.name);
|
|
13
46
|
if (entry.isDirectory()) {
|
|
47
|
+
// Recursive call if entry is a directory
|
|
14
48
|
await copyDirectory(srcPath, destPath);
|
|
15
49
|
}
|
|
16
50
|
else if (entry.isFile()) {
|
|
51
|
+
// Copy file if entry is a file
|
|
17
52
|
await fs.copyFile(srcPath, destPath);
|
|
18
53
|
}
|
|
19
54
|
}
|
|
@@ -24,3 +59,4 @@ export async function copyDirectory(srcDir, destDir) {
|
|
|
24
59
|
return false;
|
|
25
60
|
}
|
|
26
61
|
}
|
|
62
|
+
//# sourceMappingURL=copyDirectory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":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,CAAC,CAAC;YACzC,CAAC;iBAAM,IAAI,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC;gBAC1B,+BAA+B;gBAC/B,MAAM,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YACvC,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,GAAG,CAAC,KAAK,CAAC,oCAAoC,MAAM,OAAO,OAAO,KAAK,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;QACzH,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file contains the createZip function.
|
|
3
|
+
*
|
|
4
|
+
* @file createZip.ts
|
|
5
|
+
* @author Luca Liguori
|
|
6
|
+
* @date 2025-02-16
|
|
7
|
+
* @version 1.0.0
|
|
8
|
+
*
|
|
9
|
+
* Copyright 2025, 2026, 2027 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
|
+
* Creates a ZIP archive from the specified source pattern or directory and writes it to the specified output path.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} outputPath - The path where the output ZIP file will be written.
|
|
27
|
+
* @param {string[]} sourcePaths - The source pattern or directory to be zipped (use path.join for sourcePath).
|
|
28
|
+
* @returns {Promise<number>} - A promise that resolves to the total number of bytes written to the ZIP file.
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* This function uses the `archiver` library to create a ZIP archive. It sets the compression level to 9 (maximum compression).
|
|
32
|
+
* The function ensures that the output file is properly closed after the archiving process is complete.
|
|
33
|
+
* It logs the progress and the total number of bytes written to the console.
|
|
34
|
+
*
|
|
35
|
+
* This function uses the `glob` library to match files based on the source pattern (internally converted in posix).
|
|
36
|
+
*/
|
|
37
|
+
export declare function createZip(outputPath: string, ...sourcePaths: string[]): Promise<number>;
|
|
38
|
+
//# sourceMappingURL=createZip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createZip.d.ts","sourceRoot":"","sources":["../../src/utils/createZip.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAQH;;;;;;;;;;;;;GAaG;AACH,wBAAsB,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,WAAW,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CA2E7F"}
|
package/dist/utils/createZip.js
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file contains the createZip function.
|
|
3
|
+
*
|
|
4
|
+
* @file createZip.ts
|
|
5
|
+
* @author Luca Liguori
|
|
6
|
+
* @date 2025-02-16
|
|
7
|
+
* @version 1.0.0
|
|
8
|
+
*
|
|
9
|
+
* Copyright 2025, 2026, 2027 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
|
+
// AnsiLogger module
|
|
1
24
|
import { AnsiLogger } from '../logger/export.js';
|
|
25
|
+
/**
|
|
26
|
+
* Creates a ZIP archive from the specified source pattern or directory and writes it to the specified output path.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} outputPath - The path where the output ZIP file will be written.
|
|
29
|
+
* @param {string[]} sourcePaths - The source pattern or directory to be zipped (use path.join for sourcePath).
|
|
30
|
+
* @returns {Promise<number>} - A promise that resolves to the total number of bytes written to the ZIP file.
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* This function uses the `archiver` library to create a ZIP archive. It sets the compression level to 9 (maximum compression).
|
|
34
|
+
* The function ensures that the output file is properly closed after the archiving process is complete.
|
|
35
|
+
* It logs the progress and the total number of bytes written to the console.
|
|
36
|
+
*
|
|
37
|
+
* This function uses the `glob` library to match files based on the source pattern (internally converted in posix).
|
|
38
|
+
*/
|
|
2
39
|
export async function createZip(outputPath, ...sourcePaths) {
|
|
3
|
-
const log = new AnsiLogger({ logName: 'Archive', logTimestampFormat: 4
|
|
40
|
+
const log = new AnsiLogger({ logName: 'Archive', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: "info" /* LogLevel.INFO */ });
|
|
4
41
|
const { default: archiver } = await import('archiver');
|
|
5
42
|
const { glob } = await import('glob');
|
|
6
43
|
const { createWriteStream, statSync } = await import('node:fs');
|
|
@@ -9,7 +46,7 @@ export async function createZip(outputPath, ...sourcePaths) {
|
|
|
9
46
|
return new Promise((resolve, reject) => {
|
|
10
47
|
const output = createWriteStream(outputPath);
|
|
11
48
|
const archive = archiver('zip', {
|
|
12
|
-
zlib: { level: 9 },
|
|
49
|
+
zlib: { level: 9 }, // Set compression level
|
|
13
50
|
});
|
|
14
51
|
output.on('close', () => {
|
|
15
52
|
log.debug(`archive ${outputPath} closed with ${archive.pointer()} total bytes`);
|
|
@@ -36,6 +73,7 @@ export async function createZip(outputPath, ...sourcePaths) {
|
|
|
36
73
|
});
|
|
37
74
|
archive.pipe(output);
|
|
38
75
|
for (const sourcePath of sourcePaths) {
|
|
76
|
+
// Check if the sourcePath is a file or directory
|
|
39
77
|
let stats;
|
|
40
78
|
try {
|
|
41
79
|
stats = statSync(sourcePath);
|
|
@@ -63,7 +101,9 @@ export async function createZip(outputPath, ...sourcePaths) {
|
|
|
63
101
|
archive.directory(sourcePath, path.basename(sourcePath));
|
|
64
102
|
}
|
|
65
103
|
}
|
|
104
|
+
// Finalize the archive (i.e., we are done appending files but streams have to finish yet)
|
|
66
105
|
log.debug(`finalizing archive ${outputPath}...`);
|
|
67
106
|
archive.finalize().catch(reject);
|
|
68
107
|
});
|
|
69
108
|
}
|
|
109
|
+
//# sourceMappingURL=createZip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createZip.js","sourceRoot":"","sources":["../../src/utils/createZip.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAKH,oBAAoB;AACpB,OAAO,EAAE,UAAU,EAA6B,MAAM,qBAAqB,CAAC;AAE5E;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,UAAkB,EAAE,GAAG,WAAqB;IAC1E,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,kBAAkB,qCAA6B,EAAE,QAAQ,4BAAe,EAAE,CAAC,CAAC;IAE7H,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,CAAC;IACvD,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;IACtC,MAAM,EAAE,i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C;YACD,IAAI,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC;gBACnB,GAAG,CAAC,KAAK,CAAC,gBAAgB,UAAU,EAAE,CAAC,CAAC;gBACxC,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;YAChE,CAAC;iBAAM,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;gBAC/B,GAAG,CAAC,KAAK,CAAC,qBAAqB,UAAU,EAAE,CAAC,CAAC;gBAC7C,OAAO,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC;YAC3D,CAAC;QACH,CAAC;QACD,0FAA0F;QAC1F,GAAG,CAAC,KAAK,CAAC,sBAAsB,UAAU,KAAK,CAAC,CAAC;QACjD,OAAO,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file contains the deepCopy function.
|
|
3
|
+
*
|
|
4
|
+
* @file deepCopy.ts
|
|
5
|
+
* @author Luca Liguori
|
|
6
|
+
* @date 2025-02-16
|
|
7
|
+
* @version 1.0.0
|
|
8
|
+
*
|
|
9
|
+
* Copyright 2025, 2026, 2027 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
|
+
* Creates a deep copy of the given value.
|
|
25
|
+
*
|
|
26
|
+
* @template T - The type of the value being copied.
|
|
27
|
+
* @param {T} value - The value to be copied.
|
|
28
|
+
* @returns {T} - The deep copy of the value.
|
|
29
|
+
*/
|
|
30
|
+
export declare function deepCopy<T>(value: T): T;
|
|
31
|
+
//# sourceMappingURL=deepCopy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deepCopy.d.ts","sourceRoot":"","sources":["../../src/utils/deepCopy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAuCvC"}
|
package/dist/utils/deepCopy.js
CHANGED
|
@@ -1,28 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file contains the deepCopy function.
|
|
3
|
+
*
|
|
4
|
+
* @file deepCopy.ts
|
|
5
|
+
* @author Luca Liguori
|
|
6
|
+
* @date 2025-02-16
|
|
7
|
+
* @version 1.0.0
|
|
8
|
+
*
|
|
9
|
+
* Copyright 2025, 2026, 2027 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
|
+
* Creates a deep copy of the given value.
|
|
25
|
+
*
|
|
26
|
+
* @template T - The type of the value being copied.
|
|
27
|
+
* @param {T} value - The value to be copied.
|
|
28
|
+
* @returns {T} - The deep copy of the value.
|
|
29
|
+
*/
|
|
1
30
|
export function deepCopy(value) {
|
|
2
31
|
if (typeof value !== 'object' || value === null) {
|
|
32
|
+
// Primitive value (string, number, boolean, bigint, undefined, symbol) or null
|
|
3
33
|
return value;
|
|
4
34
|
}
|
|
5
35
|
else if (Array.isArray(value)) {
|
|
36
|
+
// Array: Recursively copy each element
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
38
|
return value.map((item) => deepCopy(item));
|
|
7
39
|
}
|
|
8
40
|
else if (value instanceof Date) {
|
|
41
|
+
// Date objects
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
43
|
return new Date(value.getTime());
|
|
10
44
|
}
|
|
11
45
|
else if (value instanceof Map) {
|
|
46
|
+
// Maps
|
|
12
47
|
const mapCopy = new Map();
|
|
13
48
|
value.forEach((val, key) => {
|
|
14
49
|
mapCopy.set(key, deepCopy(val));
|
|
15
50
|
});
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
52
|
return mapCopy;
|
|
17
53
|
}
|
|
18
54
|
else if (value instanceof Set) {
|
|
55
|
+
// Sets
|
|
19
56
|
const setCopy = new Set();
|
|
20
57
|
value.forEach((item) => {
|
|
21
58
|
setCopy.add(deepCopy(item));
|
|
22
59
|
});
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
61
|
return setCopy;
|
|
24
62
|
}
|
|
25
63
|
else {
|
|
64
|
+
// Objects: Create a copy with the same prototype as the original
|
|
26
65
|
const proto = Object.getPrototypeOf(value);
|
|
27
66
|
const copy = Object.create(proto);
|
|
28
67
|
for (const key in value) {
|
|
@@ -33,3 +72,4 @@ export function deepCopy(value) {
|
|
|
33
72
|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