@xenosystem/elements 0.0.9 → 0.0.11
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/README.md +65 -65
- package/dist/elements/activity.d.ts +11 -0
- package/dist/elements/activity.js +22 -0
- package/dist/elements/alert-octagon.d.ts +13 -0
- package/dist/elements/alert-octagon.js +26 -0
- package/dist/elements/arrow-down.d.ts +10 -0
- package/dist/elements/arrow-down.js +21 -0
- package/dist/elements/arrow-left.d.ts +11 -0
- package/dist/elements/arrow-left.js +22 -0
- package/dist/elements/chevron-left.d.ts +10 -0
- package/dist/elements/chevron-left.js +21 -0
- package/dist/elements/chevrons-up-down.d.ts +11 -0
- package/dist/elements/chevrons-up-down.js +23 -0
- package/dist/elements/cloud-off.d.ts +12 -0
- package/dist/elements/cloud-off.js +24 -0
- package/dist/elements/contact.d.ts +12 -0
- package/dist/elements/contact.js +26 -0
- package/dist/elements/cpu.d.ts +13 -0
- package/dist/elements/cpu.js +29 -0
- package/dist/elements/external-link.d.ts +12 -0
- package/dist/elements/external-link.js +25 -0
- package/dist/elements/file-code.d.ts +11 -0
- package/dist/elements/file-code.js +25 -0
- package/dist/elements/file-pen.d.ts +11 -0
- package/dist/elements/file-pen.js +25 -0
- package/dist/elements/film.d.ts +11 -0
- package/dist/elements/film.js +25 -0
- package/dist/elements/flask.d.ts +12 -0
- package/dist/elements/flask.js +25 -0
- package/dist/elements/folder-plus.d.ts +11 -0
- package/dist/elements/folder-plus.js +23 -0
- package/dist/elements/git-compare.d.ts +12 -0
- package/dist/elements/git-compare.js +26 -0
- package/dist/elements/git-merge.d.ts +11 -0
- package/dist/elements/git-merge.js +25 -0
- package/dist/elements/hard-drive.d.ts +12 -0
- package/dist/elements/hard-drive.js +26 -0
- package/dist/elements/hash.d.ts +10 -0
- package/dist/elements/hash.js +22 -0
- package/dist/elements/inbox.d.ts +11 -0
- package/dist/elements/inbox.js +23 -0
- package/dist/elements/mail.d.ts +11 -0
- package/dist/elements/mail.js +23 -0
- package/dist/elements/move-to.d.ts +12 -0
- package/dist/elements/move-to.js +25 -0
- package/dist/elements/pin.d.ts +16 -0
- package/dist/elements/pin.js +42 -0
- package/dist/elements/repeat.d.ts +12 -0
- package/dist/elements/repeat.js +26 -0
- package/dist/elements/rocket.d.ts +12 -0
- package/dist/elements/rocket.js +27 -0
- package/dist/elements/server.d.ts +11 -0
- package/dist/elements/server.js +25 -0
- package/dist/elements/shield-x.d.ts +11 -0
- package/dist/elements/shield-x.js +24 -0
- package/dist/elements/shield.d.ts +11 -0
- package/dist/elements/shield.js +22 -0
- package/dist/elements/users.d.ts +12 -0
- package/dist/elements/users.js +26 -0
- package/dist/elements/webhook.d.ts +12 -0
- package/dist/elements/webhook.js +27 -0
- package/dist/tokens/dtcg.d.ts +74 -0
- package/dist/tokens/dtcg.js +136 -0
- package/dist/tokens/index.d.ts +3 -0
- package/dist/tokens/index.js +3 -0
- package/dist/tokens/oklch.d.ts +73 -0
- package/dist/tokens/oklch.js +206 -0
- package/dist/tokens/platform-theme.d.ts +71 -0
- package/dist/tokens/platform-theme.js +164 -0
- package/dist/tokens.dtcg.json +393 -0
- package/package.json +4 -2
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `xeno.webhook` - Webhook. A degenerate element (pure geometry, no children).
|
|
3
|
+
*
|
|
4
|
+
* An event node with three lines leaving it for three endpoint squares: a webhook fans ONE event out to
|
|
5
|
+
* listeners. `xeno.link` is a URL and `xeno.share` is a network; the fan-out from a filled source is
|
|
6
|
+
* what makes it a hook.
|
|
7
|
+
*
|
|
8
|
+
* part[0] = source (filled), part[1] = the three routes, part[2..4] = endpoints.
|
|
9
|
+
*/
|
|
10
|
+
export const Webhook = {
|
|
11
|
+
id: 'xeno.webhook',
|
|
12
|
+
kind: 'icon',
|
|
13
|
+
contract: { viewBox: '0 0 24 24', weight: 'regular', strokeFamily: 'xeno-regular', axes: [], signals: [] },
|
|
14
|
+
geometry: {
|
|
15
|
+
base: [
|
|
16
|
+
{ kind: 'rect', x: 10, y: 10, w: 4, h: 4, rx: 0.8, fill: 'foreground' },
|
|
17
|
+
{ kind: 'path', d: 'M12 10V7M14 13l3.5 2.5M10 13l-3.5 2.5' },
|
|
18
|
+
{ kind: 'rect', x: 10, y: 3, w: 4, h: 4, rx: 0.8 },
|
|
19
|
+
{ kind: 'rect', x: 16.5, y: 15.5, w: 4, h: 4, rx: 0.8 },
|
|
20
|
+
{ kind: 'rect', x: 3.5, y: 15.5, w: 4, h: 4, rx: 0.8 },
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
bindings: [],
|
|
24
|
+
a11y: { role: 'img', label: 'Webhook' },
|
|
25
|
+
meta: { tags: ['webhook', 'callback', 'event', 'integration', 'trigger'], since: '0.0.10' },
|
|
26
|
+
};
|
|
27
|
+
export default Webhook;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* W3C Design Tokens Community Group (DTCG 2025.10) compiler & WCAG 2.2 AA contrast gate.
|
|
3
|
+
*
|
|
4
|
+
* Single machine-readable source for exporting XENO design tokens to Web, Electron, native
|
|
5
|
+
* renderers, XENO Canvas, and `@xenosystem/elements-mcp`, with fail-closed contrast verification
|
|
6
|
+
* across Industrial Warm Dark, Industrial Warm Light, and Soft Dark.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
export interface DtcgToken<T = string | number> {
|
|
11
|
+
readonly $value: T;
|
|
12
|
+
readonly $type: 'color' | 'dimension' | 'duration' | 'cubicBezier' | 'fontFamily' | 'shadow';
|
|
13
|
+
readonly $description?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface DtcgGroup {
|
|
16
|
+
readonly [key: string]: DtcgToken | DtcgGroup;
|
|
17
|
+
}
|
|
18
|
+
/** Reference warm ramps measured across Corpus v9, Creator v3, Motion v12, Workshop v3, Desktop. */
|
|
19
|
+
export declare const REFERENCE_PALETTES: Readonly<{
|
|
20
|
+
industrialDark: Readonly<{
|
|
21
|
+
canvas: "#141312";
|
|
22
|
+
surface: "#1c1b19";
|
|
23
|
+
viewport: "#232220";
|
|
24
|
+
elevated: "#282724";
|
|
25
|
+
control: "#2e2d2a";
|
|
26
|
+
border: "#33312e";
|
|
27
|
+
borderSubtle: "#2e2c29";
|
|
28
|
+
text: "#edebe7";
|
|
29
|
+
active: "#d6d2cb";
|
|
30
|
+
mutedText: "#aaa59d";
|
|
31
|
+
muted: "#7f7a72";
|
|
32
|
+
onAccent: "#1c1b19";
|
|
33
|
+
}>;
|
|
34
|
+
industrialLight: Readonly<{
|
|
35
|
+
canvas: "#e9e6e1";
|
|
36
|
+
surface: "#f6f4f1";
|
|
37
|
+
viewport: "#ffffff";
|
|
38
|
+
elevated: "#ffffff";
|
|
39
|
+
control: "#eae7e2";
|
|
40
|
+
border: "#dedad4";
|
|
41
|
+
borderSubtle: "#e4e0da";
|
|
42
|
+
text: "#1f1f1f";
|
|
43
|
+
active: "#2e2c29";
|
|
44
|
+
mutedText: "#4e4a45";
|
|
45
|
+
muted: "#6e6a64";
|
|
46
|
+
onAccent: "#faf9f7";
|
|
47
|
+
}>;
|
|
48
|
+
softDark: Readonly<{
|
|
49
|
+
canvas: "#08080a";
|
|
50
|
+
surface: "#161618";
|
|
51
|
+
viewport: "#111111";
|
|
52
|
+
elevated: "#111115";
|
|
53
|
+
control: "#2b2b2b";
|
|
54
|
+
text: "#d8d8de";
|
|
55
|
+
mutedText: "#9a9aa1";
|
|
56
|
+
muted: "#7f7f86";
|
|
57
|
+
onAccent: "#08080a";
|
|
58
|
+
}>;
|
|
59
|
+
}>;
|
|
60
|
+
/** Exact WCAG 2.2 relative-luminance contrast ratio (1..21). */
|
|
61
|
+
export declare function wcagContrastRatio(fgHex: string, bgHex: string): number;
|
|
62
|
+
export interface ContrastCheck {
|
|
63
|
+
readonly theme: string;
|
|
64
|
+
readonly pair: string;
|
|
65
|
+
readonly fg: string;
|
|
66
|
+
readonly bg: string;
|
|
67
|
+
readonly ratio: number;
|
|
68
|
+
readonly minRatio: number;
|
|
69
|
+
readonly pass: boolean;
|
|
70
|
+
}
|
|
71
|
+
/** Verify every primary, secondary, and primary-button ink/surface pair meets WCAG 2.2 AA (4.5:1). */
|
|
72
|
+
export declare function verifyThemeContrast(): readonly ContrastCheck[];
|
|
73
|
+
/** Compile the canonical W3C DTCG 2025.10 token document from live XENO token data. */
|
|
74
|
+
export declare function compileDtcgTokens(): DtcgGroup;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* W3C Design Tokens Community Group (DTCG 2025.10) compiler & WCAG 2.2 AA contrast gate.
|
|
3
|
+
*
|
|
4
|
+
* Single machine-readable source for exporting XENO design tokens to Web, Electron, native
|
|
5
|
+
* renderers, XENO Canvas, and `@xenosystem/elements-mcp`, with fail-closed contrast verification
|
|
6
|
+
* across Industrial Warm Dark, Industrial Warm Light, and Soft Dark.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { surface } from './surfaces.js';
|
|
11
|
+
import { text } from './interactive.js';
|
|
12
|
+
import { radius } from './radius.js';
|
|
13
|
+
import { controlSize } from './size.js';
|
|
14
|
+
import { status } from './status.js';
|
|
15
|
+
import { easing, duration } from './motion.js';
|
|
16
|
+
/** Reference warm ramps measured across Corpus v9, Creator v3, Motion v12, Workshop v3, Desktop. */
|
|
17
|
+
export const REFERENCE_PALETTES = Object.freeze({
|
|
18
|
+
industrialDark: Object.freeze({
|
|
19
|
+
canvas: '#141312',
|
|
20
|
+
surface: '#1c1b19',
|
|
21
|
+
viewport: '#232220',
|
|
22
|
+
elevated: '#282724',
|
|
23
|
+
control: '#2e2d2a',
|
|
24
|
+
border: '#33312e',
|
|
25
|
+
borderSubtle: '#2e2c29',
|
|
26
|
+
text: '#edebe7',
|
|
27
|
+
active: '#d6d2cb',
|
|
28
|
+
mutedText: '#aaa59d',
|
|
29
|
+
muted: '#7f7a72',
|
|
30
|
+
onAccent: '#1c1b19',
|
|
31
|
+
}),
|
|
32
|
+
industrialLight: Object.freeze({
|
|
33
|
+
canvas: '#e9e6e1',
|
|
34
|
+
surface: '#f6f4f1',
|
|
35
|
+
viewport: '#ffffff',
|
|
36
|
+
elevated: '#ffffff',
|
|
37
|
+
control: '#eae7e2',
|
|
38
|
+
border: '#dedad4',
|
|
39
|
+
borderSubtle: '#e4e0da',
|
|
40
|
+
text: '#1f1f1f',
|
|
41
|
+
active: '#2e2c29',
|
|
42
|
+
mutedText: '#4e4a45',
|
|
43
|
+
muted: '#6e6a64',
|
|
44
|
+
onAccent: '#faf9f7',
|
|
45
|
+
}),
|
|
46
|
+
softDark: Object.freeze({
|
|
47
|
+
canvas: surface.page,
|
|
48
|
+
surface: surface.panelBody,
|
|
49
|
+
viewport: surface.canvas,
|
|
50
|
+
elevated: surface.dialog,
|
|
51
|
+
control: surface.input,
|
|
52
|
+
text: text.hover,
|
|
53
|
+
mutedText: text.secondary,
|
|
54
|
+
muted: text.idle,
|
|
55
|
+
onAccent: surface.page,
|
|
56
|
+
}),
|
|
57
|
+
});
|
|
58
|
+
function parseHexRgb(hex) {
|
|
59
|
+
const clean = hex.trim().replace(/^#/, '');
|
|
60
|
+
if (!/^[0-9a-fA-F]{6}$/.test(clean)) {
|
|
61
|
+
throw new Error(`Expected 6-digit hex color, got "${hex}"`);
|
|
62
|
+
}
|
|
63
|
+
return [
|
|
64
|
+
parseInt(clean.slice(0, 2), 16) / 255,
|
|
65
|
+
parseInt(clean.slice(2, 4), 16) / 255,
|
|
66
|
+
parseInt(clean.slice(4, 6), 16) / 255,
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
function relativeLuminance(hex) {
|
|
70
|
+
const [r, g, b] = parseHexRgb(hex).map((c) => c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4));
|
|
71
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
72
|
+
}
|
|
73
|
+
/** Exact WCAG 2.2 relative-luminance contrast ratio (1..21). */
|
|
74
|
+
export function wcagContrastRatio(fgHex, bgHex) {
|
|
75
|
+
const l1 = relativeLuminance(fgHex);
|
|
76
|
+
const l2 = relativeLuminance(bgHex);
|
|
77
|
+
const lighter = Math.max(l1, l2);
|
|
78
|
+
const darker = Math.min(l1, l2);
|
|
79
|
+
return Number(((lighter + 0.05) / (darker + 0.05)).toFixed(2));
|
|
80
|
+
}
|
|
81
|
+
/** Verify every primary, secondary, and primary-button ink/surface pair meets WCAG 2.2 AA (4.5:1). */
|
|
82
|
+
export function verifyThemeContrast() {
|
|
83
|
+
const checks = [];
|
|
84
|
+
const push = (theme, pair, fg, bg, minRatio = 4.5) => {
|
|
85
|
+
const ratio = wcagContrastRatio(fg, bg);
|
|
86
|
+
checks.push({ theme, pair, fg, bg, ratio, minRatio, pass: ratio >= minRatio });
|
|
87
|
+
};
|
|
88
|
+
for (const [name, p] of Object.entries(REFERENCE_PALETTES)) {
|
|
89
|
+
push(name, 'text on viewport', p.text, p.viewport, 4.5);
|
|
90
|
+
push(name, 'text on surface', p.text, p.surface, 4.5);
|
|
91
|
+
push(name, 'text on control', p.text, p.control, 4.5);
|
|
92
|
+
push(name, 'mutedText on viewport', p.mutedText, p.viewport, 4.5);
|
|
93
|
+
push(name, 'mutedText on surface', p.mutedText, p.surface, 4.5);
|
|
94
|
+
push(name, 'mutedText on control', p.mutedText, p.control, 4.5);
|
|
95
|
+
push(name, 'onAccent on primary fill (text)', p.onAccent, p.text, 4.5);
|
|
96
|
+
}
|
|
97
|
+
return checks;
|
|
98
|
+
}
|
|
99
|
+
const color = (value, description) => ({
|
|
100
|
+
$value: value,
|
|
101
|
+
$type: 'color',
|
|
102
|
+
$description: description,
|
|
103
|
+
});
|
|
104
|
+
const dim = (px, description) => ({
|
|
105
|
+
$value: `${px}px`,
|
|
106
|
+
$type: 'dimension',
|
|
107
|
+
...(description ? { $description: description } : {}),
|
|
108
|
+
});
|
|
109
|
+
/** Compile the canonical W3C DTCG 2025.10 token document from live XENO token data. */
|
|
110
|
+
export function compileDtcgTokens() {
|
|
111
|
+
const mapPalette = (p, label) => Object.fromEntries(Object.entries(p).map(([k, v]) => [k, color(v, `${label} ${k}`)]));
|
|
112
|
+
return {
|
|
113
|
+
$schema: { $value: 'https://www.designtokens.org/tr/2025.10/format/', $type: 'fontFamily', $description: 'W3C DTCG 2025.10 format marker' },
|
|
114
|
+
color: {
|
|
115
|
+
industrialDark: mapPalette(REFERENCE_PALETTES.industrialDark, 'Industrial warm dark'),
|
|
116
|
+
industrialLight: mapPalette(REFERENCE_PALETTES.industrialLight, 'Industrial warm light'),
|
|
117
|
+
softDark: mapPalette(REFERENCE_PALETTES.softDark, 'Soft dark'),
|
|
118
|
+
status: Object.fromEntries(Object.entries(status).map(([k, v]) => [k, color(v, `Semantic status ${k}`)])),
|
|
119
|
+
},
|
|
120
|
+
radius: Object.fromEntries(Object.entries(radius).map(([k, v]) => [k, dim(v, `Corner radius ${k} (rounded squares, never circles)`)])),
|
|
121
|
+
controlSize: Object.fromEntries(Object.entries(controlSize).map(([k, s]) => [
|
|
122
|
+
k,
|
|
123
|
+
{
|
|
124
|
+
height: dim(s.height),
|
|
125
|
+
padX: dim(s.padX),
|
|
126
|
+
gap: dim(s.gap),
|
|
127
|
+
icon: dim(s.icon),
|
|
128
|
+
font: dim(s.font),
|
|
129
|
+
},
|
|
130
|
+
])),
|
|
131
|
+
motion: {
|
|
132
|
+
duration: Object.fromEntries(Object.entries(duration).map(([k, ms]) => [k, { $value: `${ms}ms`, $type: 'duration' }])),
|
|
133
|
+
easing: Object.fromEntries(Object.entries(easing).map(([k, curve]) => [k, { $value: curve, $type: 'cubicBezier' }])),
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
}
|
package/dist/tokens/index.d.ts
CHANGED
package/dist/tokens/index.js
CHANGED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Perceptual OKLCH + APCA (W3 0.0.98G-4g) Parametric Theme Engine.
|
|
3
|
+
*
|
|
4
|
+
* Derives an entire XENO surface/ink/border/semantic ramp mathematically from 3 perceptual knobs
|
|
5
|
+
* (`mode`, `warmthHue`, `chroma`, plus optional `contrast` tier), guaranteeing BOTH:
|
|
6
|
+
* - WCAG 2.2 AA (>= 4.5:1 standard, >= 7.0:1 high-contrast)
|
|
7
|
+
* - APCA Lc (|Lc| >= 75 primary text, |Lc| >= 60 secondary reading text)
|
|
8
|
+
* by construction — eliminating hand-tuned dark/light/high-contrast drift forever.
|
|
9
|
+
*
|
|
10
|
+
* Zero external dependencies. Runs identically in Node, Web, Electron, and MCP.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
export type ThemeMode = 'dark' | 'light';
|
|
15
|
+
export type ContrastTier = 'standard' | 'high' | 'oled';
|
|
16
|
+
export interface OklchThemeSpec {
|
|
17
|
+
readonly mode: ThemeMode;
|
|
18
|
+
/** Warmth hue angle in degrees (default `65` — warm stone matching the 5 XENO references). */
|
|
19
|
+
readonly warmthHue?: number;
|
|
20
|
+
/** Neutral chroma tint (default `0.008` warm neutral; `0` = pure achromatic grey). */
|
|
21
|
+
readonly chroma?: number;
|
|
22
|
+
/** Contrast tier: `'standard'` (AA + Lc 75/60), `'high'` (AAA + Lc 90/75), `'oled'` (true black dark). */
|
|
23
|
+
readonly contrast?: ContrastTier;
|
|
24
|
+
}
|
|
25
|
+
export interface GeneratedThemePalette {
|
|
26
|
+
readonly spec: Required<OklchThemeSpec>;
|
|
27
|
+
readonly canvas: string;
|
|
28
|
+
readonly surface: string;
|
|
29
|
+
readonly viewport: string;
|
|
30
|
+
readonly elevated: string;
|
|
31
|
+
readonly control: string;
|
|
32
|
+
readonly border: string;
|
|
33
|
+
readonly borderSubtle: string;
|
|
34
|
+
readonly text: string;
|
|
35
|
+
readonly active: string;
|
|
36
|
+
readonly mutedText: string;
|
|
37
|
+
readonly muted: string;
|
|
38
|
+
readonly onAccent: string;
|
|
39
|
+
readonly ok: string;
|
|
40
|
+
readonly warn: string;
|
|
41
|
+
readonly danger: string;
|
|
42
|
+
readonly info: string;
|
|
43
|
+
readonly audit: {
|
|
44
|
+
readonly textOnViewportWcag: number;
|
|
45
|
+
readonly textOnViewportApca: number;
|
|
46
|
+
readonly mutedOnSurfaceWcag: number;
|
|
47
|
+
readonly mutedOnSurfaceApca: number;
|
|
48
|
+
readonly mutedOnControlWcag: number;
|
|
49
|
+
readonly mutedOnControlApca: number;
|
|
50
|
+
readonly allPass: boolean;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/** Exact OKLCH (L in [0..1], C >= 0, H in degrees) → sRGB 6-digit hex converter. */
|
|
54
|
+
export declare function oklchToHex(l: number, c: number, hDeg: number): string;
|
|
55
|
+
/**
|
|
56
|
+
* APCA W3 (0.0.98G-4g) perceptual lightness contrast (`Lc`).
|
|
57
|
+
* Positive = dark text on light background; negative = light text on dark background.
|
|
58
|
+
* Reading targets: `|Lc| >= 75` for primary UI text, `|Lc| >= 60` for secondary reading text.
|
|
59
|
+
*/
|
|
60
|
+
export declare function apcaContrast(textHex: string, bgHex: string): number;
|
|
61
|
+
/**
|
|
62
|
+
* Compile a mathematically contrast-verified XENO theme from 3 perceptual OKLCH knobs.
|
|
63
|
+
*/
|
|
64
|
+
export declare function generateOklchTheme(input: OklchThemeSpec): GeneratedThemePalette;
|
|
65
|
+
/** Convert a generated OKLCH theme directly into `--xeno-*` CSS custom property assignments. */
|
|
66
|
+
export declare function themeToCssVars(theme: GeneratedThemePalette): Record<string, string>;
|
|
67
|
+
export declare const OKLCH_PRESETS: Readonly<{
|
|
68
|
+
warmDark: GeneratedThemePalette;
|
|
69
|
+
warmLight: GeneratedThemePalette;
|
|
70
|
+
highContrastDark: GeneratedThemePalette;
|
|
71
|
+
highContrastLight: GeneratedThemePalette;
|
|
72
|
+
oledDark: GeneratedThemePalette;
|
|
73
|
+
}>;
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Perceptual OKLCH + APCA (W3 0.0.98G-4g) Parametric Theme Engine.
|
|
3
|
+
*
|
|
4
|
+
* Derives an entire XENO surface/ink/border/semantic ramp mathematically from 3 perceptual knobs
|
|
5
|
+
* (`mode`, `warmthHue`, `chroma`, plus optional `contrast` tier), guaranteeing BOTH:
|
|
6
|
+
* - WCAG 2.2 AA (>= 4.5:1 standard, >= 7.0:1 high-contrast)
|
|
7
|
+
* - APCA Lc (|Lc| >= 75 primary text, |Lc| >= 60 secondary reading text)
|
|
8
|
+
* by construction — eliminating hand-tuned dark/light/high-contrast drift forever.
|
|
9
|
+
*
|
|
10
|
+
* Zero external dependencies. Runs identically in Node, Web, Electron, and MCP.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
import { wcagContrastRatio } from './dtcg.js';
|
|
15
|
+
function clamp01(v) {
|
|
16
|
+
return Math.max(0, Math.min(1, v));
|
|
17
|
+
}
|
|
18
|
+
function linearToSrgbByte(c) {
|
|
19
|
+
const clamped = clamp01(c);
|
|
20
|
+
const s = clamped <= 0.0031308 ? 12.92 * clamped : 1.055 * Math.pow(clamped, 1 / 2.4) - 0.055;
|
|
21
|
+
return Math.round(clamp01(s) * 255);
|
|
22
|
+
}
|
|
23
|
+
function parseHexRgbBytes(hex) {
|
|
24
|
+
const clean = hex.trim().replace(/^#/, '');
|
|
25
|
+
return [
|
|
26
|
+
parseInt(clean.slice(0, 2), 16),
|
|
27
|
+
parseInt(clean.slice(2, 4), 16),
|
|
28
|
+
parseInt(clean.slice(4, 6), 16),
|
|
29
|
+
];
|
|
30
|
+
}
|
|
31
|
+
/** Exact OKLCH (L in [0..1], C >= 0, H in degrees) → sRGB 6-digit hex converter. */
|
|
32
|
+
export function oklchToHex(l, c, hDeg) {
|
|
33
|
+
const hRad = (hDeg * Math.PI) / 180;
|
|
34
|
+
const a = c * Math.cos(hRad);
|
|
35
|
+
const b = c * Math.sin(hRad);
|
|
36
|
+
const l_ = l + 0.3963377774 * a + 0.2158037573 * b;
|
|
37
|
+
const m_ = l - 0.1055613458 * a - 0.0638541728 * b;
|
|
38
|
+
const s_ = l - 0.0894841775 * a - 1.291485548 * b;
|
|
39
|
+
const l3 = l_ * l_ * l_;
|
|
40
|
+
const m3 = m_ * m_ * m_;
|
|
41
|
+
const s3 = s_ * s_ * s_;
|
|
42
|
+
const rLin = +4.0767416621 * l3 - 3.3077115913 * m3 + 0.2309699292 * s3;
|
|
43
|
+
const gLin = -1.2684380046 * l3 + 2.6097574011 * m3 - 0.3413193965 * s3;
|
|
44
|
+
const bLin = -0.0041960863 * l3 - 0.7034186147 * m3 + 1.707614701 * s3;
|
|
45
|
+
const toHex = (n) => linearToSrgbByte(n).toString(16).padStart(2, '0');
|
|
46
|
+
return `#${toHex(rLin)}${toHex(gLin)}${toHex(bLin)}`;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* APCA W3 (0.0.98G-4g) perceptual lightness contrast (`Lc`).
|
|
50
|
+
* Positive = dark text on light background; negative = light text on dark background.
|
|
51
|
+
* Reading targets: `|Lc| >= 75` for primary UI text, `|Lc| >= 60` for secondary reading text.
|
|
52
|
+
*/
|
|
53
|
+
export function apcaContrast(textHex, bgHex) {
|
|
54
|
+
const toY = (hex) => {
|
|
55
|
+
const [r, g, b] = parseHexRgbBytes(hex);
|
|
56
|
+
const y = 0.2126729 * Math.pow(r / 255, 2.4) +
|
|
57
|
+
0.7151522 * Math.pow(g / 255, 2.4) +
|
|
58
|
+
0.072175 * Math.pow(b / 255, 2.4);
|
|
59
|
+
return y > 0.022 ? y : y + Math.pow(0.022 - y, 1.414);
|
|
60
|
+
};
|
|
61
|
+
const yTxt = toY(textHex);
|
|
62
|
+
const yBg = toY(bgHex);
|
|
63
|
+
if (Math.abs(yBg - yTxt) < 0.0005)
|
|
64
|
+
return 0;
|
|
65
|
+
let sapc = 0;
|
|
66
|
+
if (yBg > yTxt) {
|
|
67
|
+
sapc = (Math.pow(yBg, 0.56) - Math.pow(yTxt, 0.57)) * 1.14;
|
|
68
|
+
return sapc < 0.1 ? 0 : Number(((sapc - 0.027) * 100).toFixed(1));
|
|
69
|
+
}
|
|
70
|
+
sapc = (Math.pow(yBg, 0.65) - Math.pow(yTxt, 0.62)) * 1.14;
|
|
71
|
+
return sapc > -0.1 ? 0 : Number(((sapc + 0.027) * 100).toFixed(1));
|
|
72
|
+
}
|
|
73
|
+
/** Auto-nudge OKLCH lightness along the safe direction until both WCAG and APCA targets pass. */
|
|
74
|
+
function solveInkHex(startL, chroma, hue, backgrounds, direction, minWcag, minApca) {
|
|
75
|
+
let l = clamp01(startL);
|
|
76
|
+
for (let i = 0; i < 60; i++) {
|
|
77
|
+
const hex = oklchToHex(l, chroma, hue);
|
|
78
|
+
const passes = backgrounds.every((bg) => wcagContrastRatio(hex, bg) >= minWcag && Math.abs(apcaContrast(hex, bg)) >= minApca);
|
|
79
|
+
if (passes)
|
|
80
|
+
return hex;
|
|
81
|
+
l = clamp01(l + direction * 0.012);
|
|
82
|
+
}
|
|
83
|
+
return direction > 0 ? '#ffffff' : '#000000';
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Compile a mathematically contrast-verified XENO theme from 3 perceptual OKLCH knobs.
|
|
87
|
+
*/
|
|
88
|
+
export function generateOklchTheme(input) {
|
|
89
|
+
const spec = {
|
|
90
|
+
mode: input.mode,
|
|
91
|
+
warmthHue: input.warmthHue ?? 65,
|
|
92
|
+
chroma: Math.max(0, Math.min(0.03, input.chroma ?? 0.008)),
|
|
93
|
+
contrast: input.contrast ?? 'standard',
|
|
94
|
+
};
|
|
95
|
+
const isDark = spec.mode === 'dark';
|
|
96
|
+
const isHigh = spec.contrast === 'high';
|
|
97
|
+
const isOled = isDark && spec.contrast === 'oled';
|
|
98
|
+
const h = spec.warmthHue;
|
|
99
|
+
const c = isOled ? spec.chroma * 0.5 : spec.chroma;
|
|
100
|
+
// Perceptual lightness ladder (canvas -> surface -> viewport -> elevated -> control)
|
|
101
|
+
const canvas = isDark
|
|
102
|
+
? oklchToHex(isOled ? 0.0 : isHigh ? 0.14 : 0.185, isOled ? 0 : c * 0.7, h)
|
|
103
|
+
: oklchToHex(isHigh ? 0.91 : 0.928, c * 1.1, h);
|
|
104
|
+
const surface = isDark
|
|
105
|
+
? oklchToHex(isOled ? 0.13 : isHigh ? 0.18 : 0.22, c * 0.8, h)
|
|
106
|
+
: oklchToHex(isHigh ? 0.96 : 0.968, c * 0.8, h);
|
|
107
|
+
const viewport = isDark
|
|
108
|
+
? oklchToHex(isOled ? 0.165 : isHigh ? 0.21 : 0.252, c * 0.85, h)
|
|
109
|
+
: '#ffffff';
|
|
110
|
+
const elevated = isDark
|
|
111
|
+
? oklchToHex(isOled ? 0.2 : isHigh ? 0.24 : 0.278, c * 0.9, h)
|
|
112
|
+
: '#ffffff';
|
|
113
|
+
const control = isDark
|
|
114
|
+
? oklchToHex(isOled ? 0.24 : isHigh ? 0.27 : 0.3, c * 0.95, h)
|
|
115
|
+
: oklchToHex(isHigh ? 0.915 : 0.93, c * 1.0, h);
|
|
116
|
+
const border = isDark
|
|
117
|
+
? oklchToHex(isHigh ? 0.48 : 0.318, c * 0.9, h)
|
|
118
|
+
: oklchToHex(isHigh ? 0.62 : 0.892, c * 1.0, h);
|
|
119
|
+
const borderSubtle = isDark
|
|
120
|
+
? oklchToHex(isHigh ? 0.38 : 0.295, c * 0.8, h)
|
|
121
|
+
: oklchToHex(isHigh ? 0.72 : 0.912, c * 0.9, h);
|
|
122
|
+
const dir = isDark ? 1 : -1;
|
|
123
|
+
const primaryWcag = isHigh ? 7.0 : 4.5;
|
|
124
|
+
const primaryApca = isHigh ? 90 : 75;
|
|
125
|
+
const secondaryWcag = isHigh ? 7.0 : 4.5;
|
|
126
|
+
const secondaryApca = isHigh ? 75 : 60;
|
|
127
|
+
const text = solveInkHex(isDark ? 0.94 : 0.23, c * 0.6, h, [viewport, surface, control], dir, primaryWcag, primaryApca);
|
|
128
|
+
const active = solveInkHex(isDark ? 0.86 : 0.29, c * 0.7, h, [viewport, surface], dir, primaryWcag, 70);
|
|
129
|
+
const mutedText = solveInkHex(isDark ? 0.73 : 0.41, c * 0.9, h, [viewport, surface, control], dir, secondaryWcag, secondaryApca);
|
|
130
|
+
const muted = oklchToHex(isDark ? 0.58 : 0.53, c * 1.0, h);
|
|
131
|
+
const onAccent = solveInkHex(isDark ? 0.2 : 0.98, c * 0.5, h, [text], isDark ? -1 : 1, 7.0, 75);
|
|
132
|
+
const ok = oklchToHex(isDark ? 0.72 : 0.58, 0.13, 145);
|
|
133
|
+
const warn = oklchToHex(isDark ? 0.74 : 0.68, 0.13, 75);
|
|
134
|
+
const danger = oklchToHex(isDark ? 0.65 : 0.55, 0.15, 25);
|
|
135
|
+
const info = oklchToHex(isDark ? 0.72 : 0.55, 0.13, 250);
|
|
136
|
+
const textOnViewportWcag = wcagContrastRatio(text, viewport);
|
|
137
|
+
const textOnViewportApca = Math.abs(apcaContrast(text, viewport));
|
|
138
|
+
const mutedOnSurfaceWcag = wcagContrastRatio(mutedText, surface);
|
|
139
|
+
const mutedOnSurfaceApca = Math.abs(apcaContrast(mutedText, surface));
|
|
140
|
+
const mutedOnControlWcag = wcagContrastRatio(mutedText, control);
|
|
141
|
+
const mutedOnControlApca = Math.abs(apcaContrast(mutedText, control));
|
|
142
|
+
return Object.freeze({
|
|
143
|
+
spec,
|
|
144
|
+
canvas,
|
|
145
|
+
surface,
|
|
146
|
+
viewport,
|
|
147
|
+
elevated,
|
|
148
|
+
control,
|
|
149
|
+
border,
|
|
150
|
+
borderSubtle,
|
|
151
|
+
text,
|
|
152
|
+
active,
|
|
153
|
+
mutedText,
|
|
154
|
+
muted,
|
|
155
|
+
onAccent,
|
|
156
|
+
ok,
|
|
157
|
+
warn,
|
|
158
|
+
danger,
|
|
159
|
+
info,
|
|
160
|
+
audit: Object.freeze({
|
|
161
|
+
textOnViewportWcag,
|
|
162
|
+
textOnViewportApca,
|
|
163
|
+
mutedOnSurfaceWcag,
|
|
164
|
+
mutedOnSurfaceApca,
|
|
165
|
+
mutedOnControlWcag,
|
|
166
|
+
mutedOnControlApca,
|
|
167
|
+
allPass: textOnViewportWcag >= primaryWcag &&
|
|
168
|
+
textOnViewportApca >= primaryApca &&
|
|
169
|
+
mutedOnSurfaceWcag >= secondaryWcag &&
|
|
170
|
+
mutedOnSurfaceApca >= secondaryApca &&
|
|
171
|
+
mutedOnControlWcag >= secondaryWcag &&
|
|
172
|
+
mutedOnControlApca >= secondaryApca,
|
|
173
|
+
}),
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
/** Convert a generated OKLCH theme directly into `--xeno-*` CSS custom property assignments. */
|
|
177
|
+
export function themeToCssVars(theme) {
|
|
178
|
+
return {
|
|
179
|
+
'--xeno-canvas': theme.canvas,
|
|
180
|
+
'--xeno-surface': theme.surface,
|
|
181
|
+
'--xeno-panel-header': theme.surface,
|
|
182
|
+
'--xeno-viewport': theme.viewport,
|
|
183
|
+
'--xeno-elevated': theme.elevated,
|
|
184
|
+
'--xeno-control': theme.control,
|
|
185
|
+
'--xeno-field': theme.spec.mode === 'light' ? '#ffffff' : theme.control,
|
|
186
|
+
'--xeno-raised': theme.spec.mode === 'light' ? '#ffffff' : theme.control,
|
|
187
|
+
'--xeno-border': theme.border,
|
|
188
|
+
'--xeno-border-subtle': theme.borderSubtle,
|
|
189
|
+
'--xeno-text': theme.text,
|
|
190
|
+
'--xeno-active': theme.active,
|
|
191
|
+
'--xeno-muted-text': theme.mutedText,
|
|
192
|
+
'--xeno-muted': theme.muted,
|
|
193
|
+
'--xeno-on-accent': theme.onAccent,
|
|
194
|
+
'--xeno-ok': theme.ok,
|
|
195
|
+
'--xeno-warn': theme.warn,
|
|
196
|
+
'--xeno-danger': theme.danger,
|
|
197
|
+
'--xeno-info': theme.info,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
export const OKLCH_PRESETS = Object.freeze({
|
|
201
|
+
warmDark: generateOklchTheme({ mode: 'dark', warmthHue: 65, chroma: 0.008, contrast: 'standard' }),
|
|
202
|
+
warmLight: generateOklchTheme({ mode: 'light', warmthHue: 65, chroma: 0.008, contrast: 'standard' }),
|
|
203
|
+
highContrastDark: generateOklchTheme({ mode: 'dark', warmthHue: 65, chroma: 0.004, contrast: 'high' }),
|
|
204
|
+
highContrastLight: generateOklchTheme({ mode: 'light', warmthHue: 65, chroma: 0.004, contrast: 'high' }),
|
|
205
|
+
oledDark: generateOklchTheme({ mode: 'dark', warmthHue: 65, chroma: 0.005, contrast: 'oled' }),
|
|
206
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical XENO Platform 21-Stop Brightness Theme Engine & Mode Palette.
|
|
3
|
+
*
|
|
4
|
+
* Lifted directly from `xeno-platform`'s proven brightness line (`0` Dark → `50` Dim → `100` Light
|
|
5
|
+
* in 5% steps) into Rung 1 (`@xenosystem/elements/tokens`) so every XENO console (`compute`,
|
|
6
|
+
* `chat`, `storage`, `spawn`, `workflow`, `research`, and `xeno-platform` itself) shares ONE
|
|
7
|
+
* continuous theme engine with mathematically verified WCAG 2.2 AA contrast at every stop.
|
|
8
|
+
*/
|
|
9
|
+
export type PlatformThemePreference = 'system' | 'custom' | 'dark' | 'dim' | 'light';
|
|
10
|
+
export type ResolvedPlatformTheme = 'dark' | 'dim' | 'light';
|
|
11
|
+
/** Five-percent slider step producing 21 discrete semantic palettes (0..100). */
|
|
12
|
+
export declare const PLATFORM_BRIGHTNESS_STEP = 5;
|
|
13
|
+
export declare const PLATFORM_THEME_OPTIONS: readonly [{
|
|
14
|
+
readonly id: "dark";
|
|
15
|
+
readonly label: "Dark";
|
|
16
|
+
readonly position: 0;
|
|
17
|
+
}, {
|
|
18
|
+
readonly id: "dim";
|
|
19
|
+
readonly label: "Dim";
|
|
20
|
+
readonly position: 50;
|
|
21
|
+
}, {
|
|
22
|
+
readonly id: "light";
|
|
23
|
+
readonly label: "Light";
|
|
24
|
+
readonly position: 100;
|
|
25
|
+
}];
|
|
26
|
+
export interface PlatformSurfacePalette {
|
|
27
|
+
readonly canvas: string;
|
|
28
|
+
readonly surface: string;
|
|
29
|
+
readonly elevated: string;
|
|
30
|
+
readonly control: string;
|
|
31
|
+
readonly controlStrong: string;
|
|
32
|
+
readonly text: string;
|
|
33
|
+
readonly muted: string;
|
|
34
|
+
readonly border: string;
|
|
35
|
+
readonly hover: string;
|
|
36
|
+
readonly overlay: string;
|
|
37
|
+
}
|
|
38
|
+
export interface PlatformRuntimeTokens extends PlatformSurfacePalette {
|
|
39
|
+
readonly position: number;
|
|
40
|
+
readonly closestTheme: ResolvedPlatformTheme;
|
|
41
|
+
readonly isLight: boolean;
|
|
42
|
+
readonly plate: string;
|
|
43
|
+
readonly rail: string;
|
|
44
|
+
readonly surfaceText: string;
|
|
45
|
+
readonly surfaceMuted: string;
|
|
46
|
+
}
|
|
47
|
+
/** All 21 semantic palettes along the XENO Platform brightness line (0 = Dark, 50 = Dim, 100 = Light). */
|
|
48
|
+
export declare const PLATFORM_BRIGHTNESS_PALETTES: readonly PlatformSurfacePalette[];
|
|
49
|
+
export declare function platformContrastRatio(hexA: string, hexB: string): number;
|
|
50
|
+
export declare function normalizePlatformBrightness(position: number): number;
|
|
51
|
+
export declare function getPlatformThemePosition(theme: ResolvedPlatformTheme): number;
|
|
52
|
+
export declare function getClosestPlatformTheme(position: number): ResolvedPlatformTheme;
|
|
53
|
+
export declare function getPlatformThemeTokens(position: number): PlatformRuntimeTokens;
|
|
54
|
+
/**
|
|
55
|
+
* Emit the complete `--xeno-*` CSS custom-property map for any position (`0..100`) on
|
|
56
|
+
* the XENO Platform brightness line. Apply directly as `style={buildPlatformThemeCssVars(brightness)}`
|
|
57
|
+
* on any `.xeno[data-layout="platform"]` container.
|
|
58
|
+
*/
|
|
59
|
+
export declare function buildPlatformThemeCssVars(position: number): Record<string, string>;
|
|
60
|
+
export type PlatformModeId = 'xeno' | 'dev' | 'studio' | 'office' | 'social' | 'corpo' | 'tools' | 'research';
|
|
61
|
+
export interface PlatformModeSpec {
|
|
62
|
+
readonly id: PlatformModeId;
|
|
63
|
+
readonly name: string;
|
|
64
|
+
readonly color: string;
|
|
65
|
+
readonly summary: string;
|
|
66
|
+
readonly productCount: number;
|
|
67
|
+
readonly shortcut: string;
|
|
68
|
+
}
|
|
69
|
+
/** The 8 canonical XENO Platform modes and their locked brand accent hues. */
|
|
70
|
+
export declare const PLATFORM_MODES: readonly PlatformModeSpec[];
|
|
71
|
+
export declare function getPlatformMode(id: PlatformModeId): PlatformModeSpec;
|