matterbridge-zigbee2mqtt 2.0.0 → 2.0.2
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/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +9 -5
- package/dist/platform.js.map +1 -1
- package/link-matterbridge-script.js +0 -1
- package/package.json +4 -5
- package/.eslintignore +0 -2
- package/.eslintrc.json +0 -46
- package/.gitattributes +0 -2
- package/.prettierignore +0 -2
- package/.prettierrc.json +0 -12
- package/src/colorUtils.ts +0 -372
- package/src/entity.ts +0 -578
- package/src/index.ts +0 -42
- package/src/payloadTypes.ts +0 -28
- package/src/platform.ts +0 -257
- package/src/zigbee2mqtt.ts +0 -1202
- package/src/zigbee2mqttTypes.ts +0 -322
- package/tsconfig.json +0 -112
package/dist/platform.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAiB,YAAY,EAAsB,2BAA2B,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC5H,OAAO,EAAE,UAAU,EAA4C,MAAM,kBAAkB,CAAC;AAGxF,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAA4B,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAI9E,qBAAa,cAAe,SAAQ,2BAA2B;IAE7D,OAAO,CAAC,cAAc,CAA2B;IACjD,OAAO,CAAC,eAAe,CAAsB;IAG7C,OAAO,CAAC,QAAQ,CAAe;IAC/B,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,SAAS,CAAiB;IAClC,OAAO,CAAC,SAAS,CAAgB;IACjC,OAAO,CAAC,SAAS,CAAgB;IAG1B,YAAY,EAAE,OAAO,CAAC;IACtB,GAAG,EAAE,WAAW,CAAC;IACjB,UAAU,UAAS;IACnB,oBAAoB,UAAS;IAC7B,mBAAmB,UAAS;IACnC,OAAO,CAAC,aAAa,CAAyB;IAC9C,OAAO,CAAC,gBAAgB,CAA6B;IACrD,OAAO,CAAC,eAAe,CAA4B;gBAEvC,YAAY,EAAE,YAAY,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc;IAwBhE,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM;IAuDvB,WAAW;IAsBX,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM;YAO3B,mBAAmB;YAqBnB,kBAAkB;IASzB,sBAAsB,CAAC,UAAU,EAAE,MAAM;YAYlC,oBAAoB;IAcrB,mBAAmB,CAAC,KAAK,EAAE,WAAW;IAgC5C,kBAAkB,CAAC,SAAS,EAAE,OAAO;CAM7C"}
|
package/dist/platform.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
* See the License for the specific language governing permissions and
|
|
21
21
|
* limitations under the License. *
|
|
22
22
|
*/
|
|
23
|
-
import { MatterbridgeDynamicPlatform } from 'matterbridge';
|
|
23
|
+
import { Level, Logger, MatterbridgeDynamicPlatform } from 'matterbridge';
|
|
24
24
|
import { dn, gn, db, wr, zb, payloadStringify, rs } from 'node-ansi-logger';
|
|
25
25
|
import { ZigbeeDevice, ZigbeeGroup } from './entity.js';
|
|
26
26
|
import { Zigbee2MQTT } from './zigbee2mqtt.js';
|
|
@@ -91,7 +91,8 @@ export class ZigbeePlatform extends MatterbridgeDynamicPlatform {
|
|
|
91
91
|
this.log.debug(`zigbee2MQTT sent bridge-info version: ${this.z2mBridgeInfo.version}`);
|
|
92
92
|
});
|
|
93
93
|
this.z2m.on('bridge-devices', (devices) => {
|
|
94
|
-
|
|
94
|
+
if (this.debugEnabled)
|
|
95
|
+
Logger.defaultLogLevel = Level.INFO;
|
|
95
96
|
this.z2mBridgeDevices = devices;
|
|
96
97
|
this.log.debug(`zigbee2MQTT sent ${devices.length} devices ${this.z2mDevicesRegistered ? 'already registered' : ''}`);
|
|
97
98
|
if (this.z2mDevicesRegistered)
|
|
@@ -101,10 +102,12 @@ export class ZigbeePlatform extends MatterbridgeDynamicPlatform {
|
|
|
101
102
|
await this.registerZigbeeDevice(device);
|
|
102
103
|
});
|
|
103
104
|
this.z2mDevicesRegistered = true;
|
|
104
|
-
|
|
105
|
+
if (this.debugEnabled)
|
|
106
|
+
Logger.defaultLogLevel = Level.DEBUG;
|
|
105
107
|
});
|
|
106
108
|
this.z2m.on('bridge-groups', (groups) => {
|
|
107
|
-
|
|
109
|
+
if (this.debugEnabled)
|
|
110
|
+
Logger.defaultLogLevel = Level.INFO;
|
|
108
111
|
this.z2mBridgeGroups = groups;
|
|
109
112
|
this.log.debug(`zigbee2MQTT sent ${groups.length} groups ${this.z2mGroupsRegistered ? 'already registered' : ''}`);
|
|
110
113
|
if (this.z2mGroupsRegistered)
|
|
@@ -114,7 +117,8 @@ export class ZigbeePlatform extends MatterbridgeDynamicPlatform {
|
|
|
114
117
|
await this.registerZigbeeGroup(group);
|
|
115
118
|
});
|
|
116
119
|
this.z2mGroupsRegistered = true;
|
|
117
|
-
|
|
120
|
+
if (this.debugEnabled)
|
|
121
|
+
Logger.defaultLogLevel = Level.DEBUG;
|
|
118
122
|
});
|
|
119
123
|
}
|
|
120
124
|
async onConfigure() {
|
package/dist/platform.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAoC,2BAA2B,EAAkB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;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a,GAAG,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;QAChG,CAAC;;YAAM,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,KAAK,CAAC,aAAa,GAAG,EAAE,QAAQ,KAAK,CAAC,EAAE,iBAAiB,CAAC,CAAC;IAChG,CAAC;IAED;;;;;;;;;;;;;;;;MAgBE;IAEK,kBAAkB,CAAC,SAAkB;QAC1C,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,4BAA4B,IAAI,CAAC,cAAc,CAAC,MAAM,cAAc,CAAC,CAAC;QACrF,KAAK,MAAM,aAAa,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YAChD,aAAa,CAAC,4BAA4B,CAAC,SAAS,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "matterbridge-zigbee2mqtt",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Matterbridge zigbee2mqtt plugin",
|
|
5
5
|
"author": "https://github.com/Luligu",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -51,18 +51,17 @@
|
|
|
51
51
|
"matterbridge:list": "matterbridge -list",
|
|
52
52
|
"dev:link": "npm link --save-dev matterbridge",
|
|
53
53
|
"dev:install": "npm install --save-dev matterbridge",
|
|
54
|
-
"dev:
|
|
55
|
-
"install": "node link-matterbridge-script.js
|
|
54
|
+
"dev:uninstall": "npm uninstall matterbridge && npm unlink matterbridge",
|
|
55
|
+
"install": "node link-matterbridge-script.js"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@stylistic/eslint-plugin": "^1.7.0",
|
|
59
|
-
"@tsconfig/node-lts": "^20.1.
|
|
59
|
+
"@tsconfig/node-lts": "^20.1.2",
|
|
60
60
|
"@types/node": "^20.11.30",
|
|
61
61
|
"@typescript-eslint/eslint-plugin": "^7.3.1",
|
|
62
62
|
"@typescript-eslint/parser": "^7.3.1",
|
|
63
63
|
"eslint-config-prettier": "^9.1.0",
|
|
64
64
|
"eslint-plugin-prettier": "^5.1.3",
|
|
65
|
-
"matterbridge": "file:../matterbridge",
|
|
66
65
|
"prettier": "^3.2.5",
|
|
67
66
|
"typescript": "^5.4.3"
|
|
68
67
|
},
|
package/.eslintignore
DELETED
package/.eslintrc.json
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"ignorePatterns":["dist/", "node_modules/"],
|
|
3
|
-
"plugins": [
|
|
4
|
-
"@typescript-eslint",
|
|
5
|
-
"@stylistic",
|
|
6
|
-
"prettier"
|
|
7
|
-
],
|
|
8
|
-
"parser": "@typescript-eslint/parser",
|
|
9
|
-
"parserOptions": {
|
|
10
|
-
"ecmaVersion": "latest",
|
|
11
|
-
"sourceType": "module"
|
|
12
|
-
},
|
|
13
|
-
"env": {
|
|
14
|
-
"browser": true,
|
|
15
|
-
"es2021": true,
|
|
16
|
-
"node": true
|
|
17
|
-
},
|
|
18
|
-
"extends": [
|
|
19
|
-
"eslint:recommended",
|
|
20
|
-
"plugin:@typescript-eslint/eslint-recommended",
|
|
21
|
-
"plugin:@typescript-eslint/recommended",
|
|
22
|
-
"prettier"
|
|
23
|
-
],
|
|
24
|
-
"rules": {
|
|
25
|
-
"prettier/prettier": ["error"],
|
|
26
|
-
"indent": ["error", 2, { "SwitchCase": 1 }],
|
|
27
|
-
"max-len": ["warn", 300],
|
|
28
|
-
"no-console": ["warn"],
|
|
29
|
-
"quotes": ["error", "single", { "avoidEscape": true, "allowTemplateLiterals": false }],
|
|
30
|
-
"comma-spacing": ["error", { "before": false, "after": true }],
|
|
31
|
-
"space-before-function-paren": ["error", { "anonymous": "always", "named": "never", "asyncArrow": "always" }],
|
|
32
|
-
"keyword-spacing": ["error", { "before": true, "after": true }],
|
|
33
|
-
"no-multi-spaces": "error",
|
|
34
|
-
"object-curly-spacing": ["error", "always"],
|
|
35
|
-
"@typescript-eslint/type-annotation-spacing": ["error", {
|
|
36
|
-
"before": false,
|
|
37
|
-
"after": true,
|
|
38
|
-
"overrides": {
|
|
39
|
-
"arrow": {
|
|
40
|
-
"before": true,
|
|
41
|
-
"after": true
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}]
|
|
45
|
-
}
|
|
46
|
-
}
|
package/.gitattributes
DELETED
package/.prettierignore
DELETED
package/.prettierrc.json
DELETED
package/src/colorUtils.ts
DELETED
|
@@ -1,372 +0,0 @@
|
|
|
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.2.5
|
|
8
|
-
*
|
|
9
|
-
* Copyright 2023, 2024 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
|
-
import { assert } from 'console';
|
|
25
|
-
|
|
26
|
-
export type RGB = {
|
|
27
|
-
r: number;
|
|
28
|
-
g: number;
|
|
29
|
-
b: number;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export type XY = {
|
|
33
|
-
x: number;
|
|
34
|
-
y: number;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export type HSL = {
|
|
38
|
-
h: number;
|
|
39
|
-
s: number;
|
|
40
|
-
l: number;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export function hslColorToRgbColor(hue: number, saturation: number, luminance: number): RGB {
|
|
44
|
-
if (hue === 360) {
|
|
45
|
-
hue = 0;
|
|
46
|
-
}
|
|
47
|
-
assert(hue >= 0 && hue <= 359, 'hslColorToRgbColor Hue error');
|
|
48
|
-
assert(saturation >= 0 && saturation <= 100, 'hslColorToRgbColor Saturation error');
|
|
49
|
-
assert(luminance === 50, 'hslColorToRgbColor Luminance error');
|
|
50
|
-
|
|
51
|
-
saturation /= 100;
|
|
52
|
-
luminance /= 100;
|
|
53
|
-
let r: number, g: number, b: number;
|
|
54
|
-
|
|
55
|
-
if (saturation === 0) {
|
|
56
|
-
r = g = b = luminance; // achromatic
|
|
57
|
-
} else {
|
|
58
|
-
const hue2rgb = (p: number, q: number, t: number): number => {
|
|
59
|
-
if (t < 0) {
|
|
60
|
-
t += 1;
|
|
61
|
-
}
|
|
62
|
-
if (t > 1) {
|
|
63
|
-
t -= 1;
|
|
64
|
-
}
|
|
65
|
-
if (t < 1 / 6) {
|
|
66
|
-
return p + (q - p) * 6 * t;
|
|
67
|
-
}
|
|
68
|
-
if (t < 1 / 2) {
|
|
69
|
-
return q;
|
|
70
|
-
}
|
|
71
|
-
if (t < 2 / 3) {
|
|
72
|
-
return p + (q - p) * (2 / 3 - t) * 6;
|
|
73
|
-
}
|
|
74
|
-
return p;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const q = luminance < 0.5 ? luminance * (1 + saturation) : luminance + saturation - luminance * saturation;
|
|
78
|
-
const p = 2 * luminance - q;
|
|
79
|
-
|
|
80
|
-
r = hue2rgb(p, q, hue / 360 + 1 / 3);
|
|
81
|
-
g = hue2rgb(p, q, hue / 360);
|
|
82
|
-
b = hue2rgb(p, q, hue / 360 - 1 / 3);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return {
|
|
86
|
-
r: Math.ceil(r * 255),
|
|
87
|
-
g: Math.ceil(g * 255),
|
|
88
|
-
b: Math.ceil(b * 255),
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// Converts from RGB to the XY color (CIE 1931 color space)
|
|
93
|
-
export function rgbColorToXYColor(rgb: RGB): XY {
|
|
94
|
-
let r = rgb.r / 255;
|
|
95
|
-
let g = rgb.g / 255;
|
|
96
|
-
let b = rgb.b / 255;
|
|
97
|
-
|
|
98
|
-
// Apply gamma correction
|
|
99
|
-
r = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
|
|
100
|
-
g = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
|
|
101
|
-
b = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
|
|
102
|
-
|
|
103
|
-
// Scale the values to the D65 illuminant
|
|
104
|
-
r = r * 100;
|
|
105
|
-
g = g * 100;
|
|
106
|
-
b = b * 100;
|
|
107
|
-
|
|
108
|
-
// Convert RGB to XYZ
|
|
109
|
-
const X = r * 0.664511 + g * 0.154324 + b * 0.162028;
|
|
110
|
-
const Y = r * 0.283881 + g * 0.668433 + b * 0.047685;
|
|
111
|
-
const Z = r * 0.000088 + g * 0.07231 + b * 0.986039;
|
|
112
|
-
|
|
113
|
-
// Normalization
|
|
114
|
-
let x = X / (X + Y + Z);
|
|
115
|
-
let y = Y / (X + Y + Z);
|
|
116
|
-
|
|
117
|
-
// Round to 4 digits
|
|
118
|
-
x = Math.round(x * 10000) / 10000;
|
|
119
|
-
y = Math.round(y * 10000) / 10000;
|
|
120
|
-
|
|
121
|
-
return { x, y };
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export function xyColorToRgbColor(x: number, y: number, brightness = 254): RGB {
|
|
125
|
-
const z = 1.0 - x - y;
|
|
126
|
-
const Y = (brightness / 254).toFixed(2);
|
|
127
|
-
const X = (Number(Y) / y) * x;
|
|
128
|
-
const Z = (Number(Y) / y) * z;
|
|
129
|
-
|
|
130
|
-
//Convert to RGB using Wide RGB D65 conversion
|
|
131
|
-
let red = X * 1.656492 - Number(Y) * 0.354851 - Z * 0.255038;
|
|
132
|
-
let green = -X * 0.707196 + Number(Y) * 1.655397 + Z * 0.036152;
|
|
133
|
-
let blue = X * 0.051713 - Number(Y) * 0.121364 + Z * 1.01153;
|
|
134
|
-
|
|
135
|
-
//If red, green or blue is larger than 1.0 set it back to the maximum of 1.0
|
|
136
|
-
if (red > blue && red > green && red > 1.0) {
|
|
137
|
-
green = green / red;
|
|
138
|
-
blue = blue / red;
|
|
139
|
-
red = 1.0;
|
|
140
|
-
} else if (green > blue && green > red && green > 1.0) {
|
|
141
|
-
red = red / green;
|
|
142
|
-
blue = blue / green;
|
|
143
|
-
green = 1.0;
|
|
144
|
-
} else if (blue > red && blue > green && blue > 1.0) {
|
|
145
|
-
red = red / blue;
|
|
146
|
-
green = green / blue;
|
|
147
|
-
blue = 1.0;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
//Reverse gamma correction
|
|
151
|
-
red = red <= 0.0031308 ? 12.92 * red : (1.0 + 0.055) * Math.pow(red, 1.0 / 2.4) - 0.055;
|
|
152
|
-
green = green <= 0.0031308 ? 12.92 * green : (1.0 + 0.055) * Math.pow(green, 1.0 / 2.4) - 0.055;
|
|
153
|
-
blue = blue <= 0.0031308 ? 12.92 * blue : (1.0 + 0.055) * Math.pow(blue, 1.0 / 2.4) - 0.055;
|
|
154
|
-
|
|
155
|
-
//Convert normalized decimal to decimal
|
|
156
|
-
red = Math.round(red * 255);
|
|
157
|
-
green = Math.round(green * 255);
|
|
158
|
-
blue = Math.round(blue * 255);
|
|
159
|
-
|
|
160
|
-
//Normalize
|
|
161
|
-
if (isNaN(red) || red < 0) {
|
|
162
|
-
red = 0;
|
|
163
|
-
}
|
|
164
|
-
if (isNaN(green) || green < 0) {
|
|
165
|
-
green = 0;
|
|
166
|
-
}
|
|
167
|
-
if (isNaN(blue) || blue < 0) {
|
|
168
|
-
blue = 0;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return { r: red, g: green, b: blue };
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export function rgbColorToHslColor(rgb: RGB): HSL {
|
|
175
|
-
const r = rgb.r / 255;
|
|
176
|
-
const g = rgb.g / 255;
|
|
177
|
-
const b = rgb.b / 255;
|
|
178
|
-
|
|
179
|
-
const max = Math.max(r, g, b);
|
|
180
|
-
const min = Math.min(r, g, b);
|
|
181
|
-
let h = 0,
|
|
182
|
-
s = 0;
|
|
183
|
-
const l = (max + min) / 2;
|
|
184
|
-
|
|
185
|
-
if (max === min) {
|
|
186
|
-
h = s = 0; // achromatic
|
|
187
|
-
} else {
|
|
188
|
-
const d = max - min;
|
|
189
|
-
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
190
|
-
switch (max) {
|
|
191
|
-
case r:
|
|
192
|
-
h = (g - b) / d + (g < b ? 6 : 0);
|
|
193
|
-
break;
|
|
194
|
-
case g:
|
|
195
|
-
h = (b - r) / d + 2;
|
|
196
|
-
break;
|
|
197
|
-
case b:
|
|
198
|
-
h = (r - g) / d + 4;
|
|
199
|
-
break;
|
|
200
|
-
}
|
|
201
|
-
h /= 6;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return {
|
|
205
|
-
h: Math.round(h * 360),
|
|
206
|
-
s: Math.round(s * 100),
|
|
207
|
-
l: Math.round(l * 100),
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export function xyToHsl(x: number, y: number): HSL {
|
|
212
|
-
const rgb = xyColorToRgbColor(x, y);
|
|
213
|
-
return rgbColorToHslColor(rgb);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
export function testColors(): void {
|
|
217
|
-
// this table has been checked with different apps and sites and is correct 100%
|
|
218
|
-
const colors = [
|
|
219
|
-
{ 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 } },
|
|
220
|
-
{ 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 } },
|
|
221
|
-
{ 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 } },
|
|
222
|
-
{ 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 } },
|
|
223
|
-
{ 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 } },
|
|
224
|
-
{ 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 } },
|
|
225
|
-
{ 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 } },
|
|
226
|
-
{ 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 } },
|
|
227
|
-
{ 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 } },
|
|
228
|
-
{ 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 } },
|
|
229
|
-
{ 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 } },
|
|
230
|
-
{ 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 } },
|
|
231
|
-
|
|
232
|
-
{ 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 } },
|
|
233
|
-
{ 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 } },
|
|
234
|
-
{ 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 } },
|
|
235
|
-
{ 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 } },
|
|
236
|
-
{ 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 } },
|
|
237
|
-
{ 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 } },
|
|
238
|
-
{ 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 } },
|
|
239
|
-
{ 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 } },
|
|
240
|
-
{ 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 } },
|
|
241
|
-
{ 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 } },
|
|
242
|
-
{ 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 } },
|
|
243
|
-
{ 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 } },
|
|
244
|
-
];
|
|
245
|
-
|
|
246
|
-
colors.forEach((color) => {
|
|
247
|
-
// eslint-disable-next-line no-console
|
|
248
|
-
console.log(`\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} }`);
|
|
249
|
-
|
|
250
|
-
const rgb = hslColorToRgbColor(color.hsl.h, color.hsl.s, color.hsl.l);
|
|
251
|
-
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`);
|
|
252
|
-
|
|
253
|
-
const hsl = rgbColorToHslColor({ r: color.rgb.r, g: color.rgb.g, b: color.rgb.b });
|
|
254
|
-
assert(hsl.h === color.hsl.h && hsl.s === color.hsl.s && hsl.l === color.hsl.l, `Color: ${color.name} rgbColorToHslColor conversion error`);
|
|
255
|
-
|
|
256
|
-
const xy = rgbColorToXYColor({ r: color.rgb.r, g: color.rgb.g, b: color.rgb.b });
|
|
257
|
-
assert(xy.x === color.xy.x && xy.y === color.xy.y, `Color: ${color.name} rgbColorToXYColor conversion error got x ${xy.x} y ${xy.y}`);
|
|
258
|
-
|
|
259
|
-
const rgb2 = xyColorToRgbColor(color.xy.x, color.xy.y);
|
|
260
|
-
assert(rgb2.r === color.rgb.r && rgb2.g === color.rgb.g && rgb2.b === color.rgb.b, `\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}`);
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Converts CIE color space to RGB color space
|
|
266
|
-
* @param {Number} x
|
|
267
|
-
* @param {Number} y
|
|
268
|
-
* @param {Number} brightness - Ranges from 1 to 254
|
|
269
|
-
* @return {Array} Array that contains the color values for red, green and blue
|
|
270
|
-
* From: https://github.com/usolved/cie-rgb-converter/blob/master/cie_rgb_converter.js
|
|
271
|
-
*/
|
|
272
|
-
export function cie_to_rgb(x: number, y: number, brightness: number = 254): RGB {
|
|
273
|
-
//Set to maximum brightness if no custom value was given (Not the slick ECMAScript 6 way for compatibility reasons)
|
|
274
|
-
|
|
275
|
-
const z = 1.0 - x - y;
|
|
276
|
-
const Y = (brightness / 254).toFixed(2);
|
|
277
|
-
const X = (Number(Y) / y) * x;
|
|
278
|
-
const Z = (Number(Y) / y) * z;
|
|
279
|
-
|
|
280
|
-
//Convert to RGB using Wide RGB D65 conversion
|
|
281
|
-
let red = X * 1.656492 - Number(Y) * 0.354851 - Z * 0.255038;
|
|
282
|
-
let green = -X * 0.707196 + Number(Y) * 1.655397 + Z * 0.036152;
|
|
283
|
-
let blue = X * 0.051713 - Number(Y) * 0.121364 + Z * 1.01153;
|
|
284
|
-
|
|
285
|
-
//If red, green or blue is larger than 1.0 set it back to the maximum of 1.0
|
|
286
|
-
if (red > blue && red > green && red > 1.0) {
|
|
287
|
-
green = green / red;
|
|
288
|
-
blue = blue / red;
|
|
289
|
-
red = 1.0;
|
|
290
|
-
} else if (green > blue && green > red && green > 1.0) {
|
|
291
|
-
red = red / green;
|
|
292
|
-
blue = blue / green;
|
|
293
|
-
green = 1.0;
|
|
294
|
-
} else if (blue > red && blue > green && blue > 1.0) {
|
|
295
|
-
red = red / blue;
|
|
296
|
-
green = green / blue;
|
|
297
|
-
blue = 1.0;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
//Reverse gamma correction
|
|
301
|
-
red = red <= 0.0031308 ? 12.92 * red : (1.0 + 0.055) * Math.pow(red, 1.0 / 2.4) - 0.055;
|
|
302
|
-
green = green <= 0.0031308 ? 12.92 * green : (1.0 + 0.055) * Math.pow(green, 1.0 / 2.4) - 0.055;
|
|
303
|
-
blue = blue <= 0.0031308 ? 12.92 * blue : (1.0 + 0.055) * Math.pow(blue, 1.0 / 2.4) - 0.055;
|
|
304
|
-
|
|
305
|
-
//Convert normalized decimal to decimal
|
|
306
|
-
red = Math.round(red * 255);
|
|
307
|
-
green = Math.round(green * 255);
|
|
308
|
-
blue = Math.round(blue * 255);
|
|
309
|
-
|
|
310
|
-
//Normalize
|
|
311
|
-
if (isNaN(red) || red < 0) {
|
|
312
|
-
red = 0;
|
|
313
|
-
}
|
|
314
|
-
if (isNaN(green) || green < 0) {
|
|
315
|
-
green = 0;
|
|
316
|
-
}
|
|
317
|
-
if (isNaN(blue) || blue < 0) {
|
|
318
|
-
blue = 0;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
return { r: red, g: green, b: blue };
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* Converts RGB color space to CIE color space
|
|
326
|
-
* @param {Number} red
|
|
327
|
-
* @param {Number} green
|
|
328
|
-
* @param {Number} blue
|
|
329
|
-
* @return {Array} Array that contains the CIE color values for x and y
|
|
330
|
-
* From: https://github.com/usolved/cie-rgb-converter/blob/master/cie_rgb_converter.js
|
|
331
|
-
*/
|
|
332
|
-
export function rgb_to_cie(red: number, green: number, blue: number): XY {
|
|
333
|
-
//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
|
|
334
|
-
red = red > 0.04045 ? Math.pow((red + 0.055) / (1.0 + 0.055), 2.4) : red / 12.92;
|
|
335
|
-
green = green > 0.04045 ? Math.pow((green + 0.055) / (1.0 + 0.055), 2.4) : green / 12.92;
|
|
336
|
-
blue = blue > 0.04045 ? Math.pow((blue + 0.055) / (1.0 + 0.055), 2.4) : blue / 12.92;
|
|
337
|
-
|
|
338
|
-
//RGB values to XYZ using the Wide RGB D65 conversion formula
|
|
339
|
-
const X = red * 0.664511 + green * 0.154324 + blue * 0.162028;
|
|
340
|
-
const Y = red * 0.283881 + green * 0.668433 + blue * 0.047685;
|
|
341
|
-
const Z = red * 0.000088 + green * 0.07231 + blue * 0.986039;
|
|
342
|
-
|
|
343
|
-
//Calculate the xy values from the XYZ values
|
|
344
|
-
let x = (X / (X + Y + Z)).toFixed(4);
|
|
345
|
-
let y = (Y / (X + Y + Z)).toFixed(4);
|
|
346
|
-
|
|
347
|
-
if (isNaN(Number(x))) {
|
|
348
|
-
x = '0';
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
if (isNaN(Number(y))) {
|
|
352
|
-
y = '0';
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
return { x: Number(x), y: Number(y) };
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
/*
|
|
359
|
-
testColors();
|
|
360
|
-
console.log('rgb_to_cie(0, 128, 255)', rgb_to_cie(0, 128, 255));
|
|
361
|
-
console.log('cie_to_rgb(0.1401, 0.1284, 254)', cie_to_rgb(0.1401, 0.1284, 254));
|
|
362
|
-
console.log('cie_to_rgb(0.1406, 0.1382, 254)', cie_to_rgb(0.1406, 0.1382, 254));
|
|
363
|
-
for (let h = 0; h < 360; h++) {
|
|
364
|
-
const rgb = hslColorToRgbColor(h, 100, 50);
|
|
365
|
-
const xy = rgbColorToXYColor({ r: rgb.r, g: rgb.g, b: rgb.b });
|
|
366
|
-
const rgb2 = cie_to_rgb(xy.x, xy.y, 254);
|
|
367
|
-
const hsl = rgbColorToHslColor({ r: rgb2.r, g: rgb2.g, b: rgb2.b });
|
|
368
|
-
assert(rgb.r === rgb2.r && rgb.g === rgb2.g && rgb.b === rgb2.b, 'Color rgb conversion error');
|
|
369
|
-
assert(h === hsl.h, 'Color hsl conversion error');
|
|
370
|
-
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`);
|
|
371
|
-
}
|
|
372
|
-
*/
|