multi-gauge 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/src/theme.js ADDED
@@ -0,0 +1,41 @@
1
+ export const DEFAULT_THEME = Object.freeze({
2
+ background: '#071014',
3
+ surface: '#0c171d',
4
+ surfaceRaised: '#102129',
5
+ grid: '#1b3540',
6
+ text: '#e7f7fa',
7
+ muted: '#78909a',
8
+ normal: '#41e6a1',
9
+ warning: '#ffc857',
10
+ critical: '#ff4d6d',
11
+ inactive: '#40515a',
12
+ target: '#f3f7a7',
13
+ cruise: '#6b8cff'
14
+ });
15
+
16
+ /** Parse #rgb, #rrggbb, #rrggbbaa or a numeric RGBA array. */
17
+ export function color(value, alpha = 1) {
18
+ if (Array.isArray(value)) {
19
+ return [value[0] ?? 0, value[1] ?? 0, value[2] ?? 0, (value[3] ?? 1) * alpha];
20
+ }
21
+ const hex = String(value ?? '#ffffff').replace('#', '');
22
+ const expanded = hex.length === 3 ? [...hex].map((part) => part + part).join('') : hex;
23
+ const parsed = Number.parseInt(expanded.slice(0, 8).padEnd(8, 'f'), 16);
24
+ if (!Number.isFinite(parsed)) {
25
+ return [1, 1, 1, alpha];
26
+ }
27
+ return [
28
+ ((parsed >>> 24) & 255) / 255,
29
+ ((parsed >>> 16) & 255) / 255,
30
+ ((parsed >>> 8) & 255) / 255,
31
+ (parsed & 255) / 255 * alpha
32
+ ];
33
+ }
34
+
35
+ export function resolveTheme(theme = {}, accent = '#00eaff') {
36
+ return { ...DEFAULT_THEME, ...theme, accent };
37
+ }
38
+
39
+ export function semanticColor(theme, kind, fallback = 'accent') {
40
+ return color(theme[kind] ?? theme[fallback] ?? theme.accent);
41
+ }