@nearcade/accent-color 0.1.0
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/LICENSE +21 -0
- package/README.md +30 -0
- package/index.js +26 -0
- package/lib/darwin.js +66 -0
- package/lib/linux.js +93 -0
- package/lib/win32.js +57 -0
- package/package.json +21 -0
- package/test.js +16 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fame
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# @nearcade/accent-color
|
|
2
|
+
|
|
3
|
+
Cross-platform system accent color detection for Node.js.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
const accent = require('@nearcade/accent-color');
|
|
9
|
+
|
|
10
|
+
const color = accent.get();
|
|
11
|
+
// { hex: '#007aff', rgb: { r: 0, g: 122, b: 255 }, hsl: { h: 211, s: 100, l: 50 } }
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## API
|
|
15
|
+
|
|
16
|
+
### `accent.get()`
|
|
17
|
+
|
|
18
|
+
Returns `null` on unsupported platforms.
|
|
19
|
+
|
|
20
|
+
### `accent.getAsync()`
|
|
21
|
+
|
|
22
|
+
Async variant (same as sync for now, reserved for future native addons).
|
|
23
|
+
|
|
24
|
+
## Platforms
|
|
25
|
+
|
|
26
|
+
| Platform | Method |
|
|
27
|
+
|----------|--------|
|
|
28
|
+
| Windows | Registry `AccentColor` DWORD |
|
|
29
|
+
| macOS | `defaults read -g AppleAccentColor` |
|
|
30
|
+
| Linux | D-Bus portal → GNOME `gsettings` → KDE `kreadconfig5` |
|
package/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const os = require('os');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
const platform = os.platform();
|
|
5
|
+
|
|
6
|
+
function load() {
|
|
7
|
+
try {
|
|
8
|
+
return require(path.join(__dirname, 'lib', platform));
|
|
9
|
+
} catch {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function get() {
|
|
15
|
+
const mod = load();
|
|
16
|
+
if (!mod) return null;
|
|
17
|
+
return mod.get();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function getAsync() {
|
|
21
|
+
const mod = load();
|
|
22
|
+
if (!mod || !mod.getAsync) return get();
|
|
23
|
+
return mod.getAsync();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = { get, getAsync, load, platform };
|
package/lib/darwin.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const { execFileSync } = require('child_process');
|
|
2
|
+
|
|
3
|
+
const PRESET_COLORS = {
|
|
4
|
+
[-1]: { r: 142, g: 142, b: 147, name: 'graphite' },
|
|
5
|
+
[0]: { r: 255, g: 59, b: 48, name: 'red' },
|
|
6
|
+
[1]: { r: 255, g: 149, b: 0, name: 'orange' },
|
|
7
|
+
[2]: { r: 255, g: 204, b: 0, name: 'yellow' },
|
|
8
|
+
[3]: { r: 52, g: 199, b: 89, name: 'green' },
|
|
9
|
+
[4]: { r: 0, g: 122, b: 255, name: 'blue' },
|
|
10
|
+
[5]: { r: 175, g: 82, b: 222, name: 'purple' },
|
|
11
|
+
[6]: { r: 255, g: 45, b: 85, name: 'pink' },
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
function get() {
|
|
15
|
+
try {
|
|
16
|
+
const out = execFileSync('defaults', ['read', '-g', 'AppleAccentColor'], {
|
|
17
|
+
encoding: 'utf-8', timeout: 3000, stdio: ['ignore', 'pipe', 'ignore']
|
|
18
|
+
});
|
|
19
|
+
const preset = parseInt(out.trim(), 10);
|
|
20
|
+
if (preset in PRESET_COLORS) {
|
|
21
|
+
const c = PRESET_COLORS[preset];
|
|
22
|
+
return color(c.r, c.g, c.b, c.name);
|
|
23
|
+
}
|
|
24
|
+
} catch {}
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
const out = execFileSync('defaults', ['read', '-g', 'AppleAquaColorVariant'], {
|
|
28
|
+
encoding: 'utf-8', timeout: 3000, stdio: ['ignore', 'pipe', 'ignore']
|
|
29
|
+
});
|
|
30
|
+
const variant = parseInt(out.trim(), 10);
|
|
31
|
+
if (variant === 6) {
|
|
32
|
+
return PRESET_COLORS[4]; // Blue default
|
|
33
|
+
}
|
|
34
|
+
} catch {}
|
|
35
|
+
|
|
36
|
+
return getFallback();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function getFallback() {
|
|
40
|
+
const c = PRESET_COLORS[4];
|
|
41
|
+
return color(c.r, c.g, c.b, c.name);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function color(r, g, b, name) {
|
|
45
|
+
const h = (v) => v.toString(16).padStart(2, '0');
|
|
46
|
+
const hex = `#${h(r)}${h(g)}${h(b)}`;
|
|
47
|
+
return { hex, rgb: { r, g, b }, hsl: rgbToHsl(r, g, b), preset: name || null };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function rgbToHsl(r, g, b) {
|
|
51
|
+
r /= 255; g /= 255; b /= 255;
|
|
52
|
+
const mx = Math.max(r, g, b), mn = Math.min(r, g, b);
|
|
53
|
+
let h = 0, s = 0, l = (mx + mn) / 2;
|
|
54
|
+
if (mx !== mn) {
|
|
55
|
+
const d = mx - mn;
|
|
56
|
+
s = l > 0.5 ? d / (2 - mx - mn) : d / (mx + mn);
|
|
57
|
+
switch (mx) {
|
|
58
|
+
case r: h = ((g - b) / d + (g < b ? 6 : 0)) / 6; break;
|
|
59
|
+
case g: h = ((b - r) / d + 2) / 6; break;
|
|
60
|
+
case b: h = ((r - g) / d + 4) / 6; break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return { h: Math.round(h * 360), s: Math.round(s * 100), l: Math.round(l * 100) };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
module.exports = { get };
|
package/lib/linux.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
const { execFileSync } = require('child_process');
|
|
2
|
+
|
|
3
|
+
function get() {
|
|
4
|
+
try {
|
|
5
|
+
const out = execFileSync('dbus-send', [
|
|
6
|
+
'--session', '--print-reply',
|
|
7
|
+
'--dest=org.freedesktop.portal.Desktop',
|
|
8
|
+
'/org/freedesktop/portal/desktop',
|
|
9
|
+
'org.freedesktop.portal.Settings.ReadOne',
|
|
10
|
+
'string:org.freedesktop.appearance',
|
|
11
|
+
'string:accent-color',
|
|
12
|
+
], { encoding: 'utf-8', timeout: 5000, stdio: ['ignore', 'pipe', 'ignore'] });
|
|
13
|
+
|
|
14
|
+
const doubles = [...out.matchAll(/double\s+([\d.]+)/g)];
|
|
15
|
+
if (doubles.length >= 3) {
|
|
16
|
+
const r = Math.round(parseFloat(doubles[0][1]) * 255);
|
|
17
|
+
const g = Math.round(parseFloat(doubles[1][1]) * 255);
|
|
18
|
+
const b = Math.round(parseFloat(doubles[2][1]) * 255);
|
|
19
|
+
return color(r, g, b);
|
|
20
|
+
}
|
|
21
|
+
} catch {}
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
const out = execFileSync('gsettings', [
|
|
25
|
+
'get', 'org.gnome.desktop.interface', 'accent-color'
|
|
26
|
+
], { encoding: 'utf-8', timeout: 3000, stdio: ['ignore', 'pipe', 'ignore'] });
|
|
27
|
+
const name = out.trim().replace(/'/g, '');
|
|
28
|
+
const gnome = GNOME_COLORS[name];
|
|
29
|
+
if (gnome) return color(gnome.r, gnome.g, gnome.b, gnome.name);
|
|
30
|
+
} catch {}
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
const out = execFileSync('gsettings', [
|
|
34
|
+
'get', 'org.gnome.desktop.interface', 'gtk-theme'
|
|
35
|
+
], { encoding: 'utf-8', timeout: 3000, stdio: ['ignore', 'pipe', 'ignore'] });
|
|
36
|
+
if (out.toLowerCase().includes('dark')) {
|
|
37
|
+
return color(0x99, 0x99, 0x99, 'default-dark');
|
|
38
|
+
}
|
|
39
|
+
} catch {}
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
const out = execFileSync('kreadconfig5', [
|
|
43
|
+
'--file', 'kdeglobals', '--group', 'General', '--key', 'AccentColor'
|
|
44
|
+
], { encoding: 'utf-8', timeout: 3000, stdio: ['ignore', 'pipe', 'ignore'] });
|
|
45
|
+
const parts = out.trim().split(',').map(Number);
|
|
46
|
+
if (parts.length >= 3 && parts.every(n => !isNaN(n))) {
|
|
47
|
+
return color(parts[0], parts[1], parts[2]);
|
|
48
|
+
}
|
|
49
|
+
} catch {}
|
|
50
|
+
|
|
51
|
+
return getFallback();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const GNOME_COLORS = {
|
|
55
|
+
blue: { r: 53, g: 132, b: 228, name: 'blue' },
|
|
56
|
+
teal: { r: 25, g: 162, b: 155, name: 'teal' },
|
|
57
|
+
green: { r: 51, g: 171, b: 80, name: 'green' },
|
|
58
|
+
yellow: { r: 242, g: 185, b: 53, name: 'yellow' },
|
|
59
|
+
orange: { r: 245, g: 135, b: 31, name: 'orange' },
|
|
60
|
+
red: { r: 207, g: 73, b: 73, name: 'red' },
|
|
61
|
+
purple: { r: 130, g: 90, b: 209, name: 'purple' },
|
|
62
|
+
pink: { r: 222, g: 82, b: 150, name: 'pink' },
|
|
63
|
+
slate: { r: 120, g: 120, b: 130, name: 'slate' },
|
|
64
|
+
default: { r: 53, g: 132, b: 228, name: 'blue' },
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
function getFallback() {
|
|
68
|
+
return color(0x8b, 0x5c, 0xf6);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function color(r, g, b, name) {
|
|
72
|
+
const h = (v) => v.toString(16).padStart(2, '0');
|
|
73
|
+
const hex = `#${h(r)}${h(g)}${h(b)}`;
|
|
74
|
+
return { hex, rgb: { r, g, b }, hsl: rgbToHsl(r, g, b), preset: name || null };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function rgbToHsl(r, g, b) {
|
|
78
|
+
r /= 255; g /= 255; b /= 255;
|
|
79
|
+
const mx = Math.max(r, g, b), mn = Math.min(r, g, b);
|
|
80
|
+
let h = 0, s = 0, l = (mx + mn) / 2;
|
|
81
|
+
if (mx !== mn) {
|
|
82
|
+
const d = mx - mn;
|
|
83
|
+
s = l > 0.5 ? d / (2 - mx - mn) : d / (mx + mn);
|
|
84
|
+
switch (mx) {
|
|
85
|
+
case r: h = ((g - b) / d + (g < b ? 6 : 0)) / 6; break;
|
|
86
|
+
case g: h = ((b - r) / d + 2) / 6; break;
|
|
87
|
+
case b: h = ((r - g) / d + 4) / 6; break;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return { h: Math.round(h * 360), s: Math.round(s * 100), l: Math.round(l * 100) };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
module.exports = { get };
|
package/lib/win32.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const { execFileSync } = require('child_process');
|
|
2
|
+
|
|
3
|
+
function get() {
|
|
4
|
+
try {
|
|
5
|
+
const out = execFileSync('reg', [
|
|
6
|
+
'query',
|
|
7
|
+
'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Accent',
|
|
8
|
+
'/v', 'AccentColor'
|
|
9
|
+
], { encoding: 'utf-8', timeout: 5000, stdio: ['ignore', 'pipe', 'ignore'] });
|
|
10
|
+
|
|
11
|
+
const match = out.match(/AccentColor\s+REG_DWORD\s+0x([0-9a-fA-F]{6})/);
|
|
12
|
+
if (!match) {
|
|
13
|
+
return getFallback();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const abgr = parseInt(match[1], 16);
|
|
17
|
+
const b = (abgr >> 16) & 0xff;
|
|
18
|
+
const g = (abgr >> 8) & 0xff;
|
|
19
|
+
const r = abgr & 0xff;
|
|
20
|
+
|
|
21
|
+
return color(r, g, b);
|
|
22
|
+
} catch {
|
|
23
|
+
return getFallback();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function getAsync() {
|
|
28
|
+
return get();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function getFallback() {
|
|
32
|
+
return color(0x8b, 0x5c, 0xf6);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function color(r, g, b) {
|
|
36
|
+
const h = (v) => v.toString(16).padStart(2, '0');
|
|
37
|
+
const hex = `#${h(r)}${h(g)}${h(b)}`;
|
|
38
|
+
return { hex, rgb: { r, g, b }, hsl: rgbToHsl(r, g, b) };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function rgbToHsl(r, g, b) {
|
|
42
|
+
r /= 255; g /= 255; b /= 255;
|
|
43
|
+
const mx = Math.max(r, g, b), mn = Math.min(r, g, b);
|
|
44
|
+
let h = 0, s = 0, l = (mx + mn) / 2;
|
|
45
|
+
if (mx !== mn) {
|
|
46
|
+
const d = mx - mn;
|
|
47
|
+
s = l > 0.5 ? d / (2 - mx - mn) : d / (mx + mn);
|
|
48
|
+
switch (mx) {
|
|
49
|
+
case r: h = ((g - b) / d + (g < b ? 6 : 0)) / 6; break;
|
|
50
|
+
case g: h = ((b - r) / d + 2) / 6; break;
|
|
51
|
+
case b: h = ((r - g) / d + 4) / 6; break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return { h: Math.round(h * 360), s: Math.round(s * 100), l: Math.round(l * 100) };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
module.exports = { get, getAsync };
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nearcade/accent-color",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Cross-platform system accent color detection for Node.js — Windows, macOS, Linux",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "node test.js"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"accent",
|
|
11
|
+
"accent-color",
|
|
12
|
+
"system",
|
|
13
|
+
"theme",
|
|
14
|
+
"color",
|
|
15
|
+
"windows",
|
|
16
|
+
"macos",
|
|
17
|
+
"linux",
|
|
18
|
+
"electron"
|
|
19
|
+
],
|
|
20
|
+
"license": "MIT"
|
|
21
|
+
}
|
package/test.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const accent = require('./index.js');
|
|
2
|
+
|
|
3
|
+
const result = accent.get();
|
|
4
|
+
if (result) {
|
|
5
|
+
console.log(`Platform: ${accent.platform}`);
|
|
6
|
+
console.log(`Accent: ${result.hex}`);
|
|
7
|
+
console.log(`RGB: ${result.rgb.r}, ${result.rgb.g}, ${result.rgb.b}`);
|
|
8
|
+
console.log(`HSL: ${result.hsl.h}°, ${result.hsl.s}%, ${result.hsl.l}%`);
|
|
9
|
+
if (result.preset) console.log(`Preset: ${result.preset}`);
|
|
10
|
+
} else {
|
|
11
|
+
console.log(`Platform ${accent.platform} is not supported yet`);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
accent.getAsync().then(r => {
|
|
15
|
+
if (r) console.log(`Async: ${r.hex}`);
|
|
16
|
+
});
|