@newtonedev/components 0.1.12 → 0.1.13
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/_COMPONENT_TEMPLATE/ComponentName.styles.d.ts +3 -2
- package/dist/_COMPONENT_TEMPLATE/ComponentName.styles.d.ts.map +1 -1
- package/dist/_COMPONENT_TEMPLATE/ComponentName.types.d.ts +1 -1
- package/dist/_COMPONENT_TEMPLATE/ComponentName.types.d.ts.map +1 -1
- package/dist/composites/actions/Button/Button.styles.d.ts +1 -1
- package/dist/composites/actions/Button/Button.styles.d.ts.map +1 -1
- package/dist/composites/form-controls/Select/Select.d.ts.map +1 -1
- package/dist/composites/form-controls/Select/Select.styles.d.ts +2 -2
- package/dist/composites/form-controls/Select/Select.styles.d.ts.map +1 -1
- package/dist/composites/form-controls/Select/SelectOption.d.ts.map +1 -1
- package/dist/composites/form-controls/TextInput/TextInput.d.ts.map +1 -1
- package/dist/composites/form-controls/TextInput/TextInput.styles.d.ts +2 -2
- package/dist/composites/form-controls/TextInput/TextInput.styles.d.ts.map +1 -1
- package/dist/composites/form-controls/Toggle/Toggle.styles.d.ts +2 -2
- package/dist/composites/form-controls/Toggle/Toggle.styles.d.ts.map +1 -1
- package/dist/composites/layout/AppShell/AppShell.styles.d.ts +2 -2
- package/dist/composites/layout/AppShell/AppShell.styles.d.ts.map +1 -1
- package/dist/composites/layout/Card/Card.styles.d.ts +2 -2
- package/dist/composites/layout/Card/Card.styles.d.ts.map +1 -1
- package/dist/composites/layout/Card/Card.types.d.ts +1 -1
- package/dist/composites/layout/Card/Card.types.d.ts.map +1 -1
- package/dist/composites/layout/Navbar/Navbar.styles.d.ts +3 -2
- package/dist/composites/layout/Navbar/Navbar.styles.d.ts.map +1 -1
- package/dist/composites/layout/Sidebar/Sidebar.styles.d.ts +3 -2
- package/dist/composites/layout/Sidebar/Sidebar.styles.d.ts.map +1 -1
- package/dist/composites/overlays/Popover/Popover.styles.d.ts +2 -2
- package/dist/composites/overlays/Popover/Popover.styles.d.ts.map +1 -1
- package/dist/composites/range-inputs/ColorScaleSlider/ColorScaleSlider.d.ts +1 -1
- package/dist/composites/range-inputs/ColorScaleSlider/ColorScaleSlider.d.ts.map +1 -1
- package/dist/composites/range-inputs/ColorScaleSlider/ColorScaleSlider.styles.d.ts +2 -2
- package/dist/composites/range-inputs/ColorScaleSlider/ColorScaleSlider.styles.d.ts.map +1 -1
- package/dist/composites/range-inputs/ColorScaleSlider/ColorScaleSlider.types.d.ts +2 -0
- package/dist/composites/range-inputs/ColorScaleSlider/ColorScaleSlider.types.d.ts.map +1 -1
- package/dist/composites/range-inputs/HueSlider/HueSlider.d.ts +3 -4
- package/dist/composites/range-inputs/HueSlider/HueSlider.d.ts.map +1 -1
- package/dist/composites/range-inputs/HueSlider/HueSlider.styles.d.ts +4 -4
- package/dist/composites/range-inputs/HueSlider/HueSlider.styles.d.ts.map +1 -1
- package/dist/composites/range-inputs/Slider/Slider.styles.d.ts +2 -2
- package/dist/composites/range-inputs/Slider/Slider.styles.d.ts.map +1 -1
- package/dist/index.cjs +1232 -1823
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +12 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1084 -1737
- package/dist/index.js.map +1 -1
- package/dist/primitives/Frame/Frame.d.ts.map +1 -1
- package/dist/primitives/Frame/Frame.styles.d.ts +3 -2
- package/dist/primitives/Frame/Frame.styles.d.ts.map +1 -1
- package/dist/primitives/Frame/Frame.types.d.ts +1 -1
- package/dist/primitives/Frame/Frame.types.d.ts.map +1 -1
- package/dist/primitives/Frame/Frame.utils.d.ts +1 -1
- package/dist/primitives/Frame/Frame.utils.d.ts.map +1 -1
- package/dist/primitives/Icon/Icon.d.ts.map +1 -1
- package/dist/primitives/Text/Text.d.ts +1 -1
- package/dist/primitives/Text/Text.d.ts.map +1 -1
- package/dist/primitives/Text/Text.types.d.ts +1 -1
- package/dist/primitives/Text/Text.types.d.ts.map +1 -1
- package/dist/primitives/Wrapper/Wrapper.styles.d.ts +1 -1
- package/dist/primitives/Wrapper/Wrapper.styles.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/_COMPONENT_TEMPLATE/ComponentName.styles.ts +4 -4
- package/src/_COMPONENT_TEMPLATE/ComponentName.tsx +2 -2
- package/src/_COMPONENT_TEMPLATE/ComponentName.types.ts +1 -1
- package/src/composites/actions/Button/Button.styles.ts +37 -36
- package/src/composites/actions/Button/Button.tsx +1 -1
- package/src/composites/form-controls/Select/Select.styles.ts +8 -8
- package/src/composites/form-controls/Select/Select.tsx +4 -5
- package/src/composites/form-controls/Select/SelectOption.tsx +7 -8
- package/src/composites/form-controls/TextInput/TextInput.styles.ts +7 -8
- package/src/composites/form-controls/TextInput/TextInput.tsx +3 -4
- package/src/composites/form-controls/Toggle/Toggle.styles.ts +6 -6
- package/src/composites/form-controls/Toggle/Toggle.tsx +2 -2
- package/src/composites/layout/AppShell/AppShell.styles.ts +3 -4
- package/src/composites/layout/AppShell/AppShell.tsx +2 -2
- package/src/composites/layout/Card/Card.styles.ts +4 -5
- package/src/composites/layout/Card/Card.tsx +2 -2
- package/src/composites/layout/Card/Card.types.ts +1 -1
- package/src/composites/layout/Navbar/Navbar.styles.ts +5 -5
- package/src/composites/layout/Navbar/Navbar.tsx +2 -2
- package/src/composites/layout/Sidebar/Sidebar.styles.ts +5 -5
- package/src/composites/layout/Sidebar/Sidebar.tsx +2 -2
- package/src/composites/overlays/Popover/Popover.styles.ts +4 -4
- package/src/composites/overlays/Popover/Popover.tsx +2 -2
- package/src/composites/range-inputs/ColorScaleSlider/ColorScaleSlider.styles.ts +5 -6
- package/src/composites/range-inputs/ColorScaleSlider/ColorScaleSlider.tsx +6 -3
- package/src/composites/range-inputs/ColorScaleSlider/ColorScaleSlider.types.ts +2 -0
- package/src/composites/range-inputs/HueSlider/HueSlider.styles.ts +14 -21
- package/src/composites/range-inputs/HueSlider/HueSlider.tsx +8 -9
- package/src/composites/range-inputs/Slider/Slider.styles.ts +9 -10
- package/src/composites/range-inputs/Slider/Slider.tsx +2 -2
- package/src/index.ts +73 -60
- package/src/primitives/Frame/Frame.styles.ts +8 -7
- package/src/primitives/Frame/Frame.tsx +9 -9
- package/src/primitives/Frame/Frame.types.ts +1 -1
- package/src/primitives/Frame/Frame.utils.ts +1 -1
- package/src/primitives/Icon/Icon.tsx +2 -3
- package/src/primitives/Text/Text.spans.ts +1 -1
- package/src/primitives/Text/Text.tsx +16 -16
- package/src/primitives/Text/Text.types.ts +1 -1
- package/src/primitives/Wrapper/Wrapper.styles.ts +1 -1
- package/src/primitives/Wrapper/Wrapper.tsx +1 -1
- package/dist/fonts/GoogleFontLoader.d.ts +0 -20
- package/dist/fonts/GoogleFontLoader.d.ts.map +0 -1
- package/dist/fonts/IconFontLoader.d.ts +0 -13
- package/dist/fonts/IconFontLoader.d.ts.map +0 -1
- package/dist/fonts/SelfHostedFontLoader.d.ts +0 -14
- package/dist/fonts/SelfHostedFontLoader.d.ts.map +0 -1
- package/dist/fonts/buildGoogleFontsUrl.d.ts +0 -2
- package/dist/fonts/buildGoogleFontsUrl.d.ts.map +0 -1
- package/dist/fonts/measureFont.d.ts +0 -19
- package/dist/fonts/measureFont.d.ts.map +0 -1
- package/dist/fonts/reportQueue.d.ts +0 -7
- package/dist/fonts/reportQueue.d.ts.map +0 -1
- package/dist/fonts/useLocalCalibration.d.ts +0 -19
- package/dist/fonts/useLocalCalibration.d.ts.map +0 -1
- package/dist/fonts/useTypographyCalibrations.d.ts +0 -11
- package/dist/fonts/useTypographyCalibrations.d.ts.map +0 -1
- package/dist/theme/FrameContext.d.ts +0 -26
- package/dist/theme/FrameContext.d.ts.map +0 -1
- package/dist/theme/NewtoneProvider.d.ts +0 -40
- package/dist/theme/NewtoneProvider.d.ts.map +0 -1
- package/dist/theme/defaults.d.ts +0 -8
- package/dist/theme/defaults.d.ts.map +0 -1
- package/dist/theme/types.d.ts +0 -156
- package/dist/theme/types.d.ts.map +0 -1
- package/dist/theme/useBreakpoint.d.ts +0 -9
- package/dist/theme/useBreakpoint.d.ts.map +0 -1
- package/dist/tokens/computeTokens.d.ts +0 -151
- package/dist/tokens/computeTokens.d.ts.map +0 -1
- package/dist/tokens/types.d.ts +0 -162
- package/dist/tokens/types.d.ts.map +0 -1
- package/dist/tokens/useTokens.d.ts +0 -26
- package/dist/tokens/useTokens.d.ts.map +0 -1
- package/src/fonts/GoogleFontLoader.tsx +0 -80
- package/src/fonts/IconFontLoader.tsx +0 -51
- package/src/fonts/SelfHostedFontLoader.tsx +0 -44
- package/src/fonts/buildGoogleFontsUrl.ts +0 -2
- package/src/fonts/measureFont.ts +0 -55
- package/src/fonts/reportQueue.ts +0 -54
- package/src/fonts/useLocalCalibration.ts +0 -97
- package/src/fonts/useTypographyCalibrations.ts +0 -15
- package/src/theme/FrameContext.tsx +0 -31
- package/src/theme/NewtoneProvider.tsx +0 -84
- package/src/theme/defaults.ts +0 -71
- package/src/theme/types.ts +0 -191
- package/src/theme/useBreakpoint.ts +0 -14
- package/src/tokens/computeTokens.ts +0 -516
- package/src/tokens/types.ts +0 -146
- package/src/tokens/useTokens.ts +0 -62
|
@@ -1,516 +0,0 @@
|
|
|
1
|
-
import { getColor } from 'newtone';
|
|
2
|
-
import type { PaletteConfig } from 'newtone';
|
|
3
|
-
import { fontConfigToFamily } from '@newtonedev/fonts';
|
|
4
|
-
import type { ColorSystemConfig, ColorMode, ElevationLevel, FontSlot, TokenOverrides } from '../theme/types';
|
|
5
|
-
import type { ResolvedTokens, PaletteTokens } from './types';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Per-mode fallback defaults shape shared by all palette defaults.
|
|
9
|
-
*/
|
|
10
|
-
export type PaletteDefaults = {
|
|
11
|
-
readonly light: {
|
|
12
|
-
readonly background: { readonly elevated: number; readonly ground: number; readonly sunken: number };
|
|
13
|
-
readonly text: { readonly primary: number; readonly secondary: number; readonly tertiary: number; readonly disabled: number };
|
|
14
|
-
readonly action: { readonly enabled: number; readonly hovered: number; readonly pressed: number };
|
|
15
|
-
readonly border: { readonly enabled: number; readonly focused: number; readonly filled: number };
|
|
16
|
-
};
|
|
17
|
-
readonly dark: {
|
|
18
|
-
readonly background: { readonly elevated: number; readonly ground: number; readonly sunken: number };
|
|
19
|
-
readonly text: { readonly primary: number; readonly secondary: number; readonly tertiary: number; readonly disabled: number };
|
|
20
|
-
readonly action: { readonly enabled: number; readonly hovered: number; readonly pressed: number };
|
|
21
|
-
readonly border: { readonly enabled: number; readonly focused: number; readonly filled: number };
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Per-mode fallback defaults for the neutral palette (normalized scale).
|
|
27
|
-
* Single source of truth — consumed by computeTokens and the admin Token Tuner.
|
|
28
|
-
*
|
|
29
|
-
* Light: 0 = lightest, 1 = darkest. Dark: 0 = darkest, 1 = lightest.
|
|
30
|
-
* Structured by token group so all per-palette defaults follow the same shape.
|
|
31
|
-
*/
|
|
32
|
-
export const NEUTRAL_DEFAULTS: PaletteDefaults = {
|
|
33
|
-
light: {
|
|
34
|
-
background: { elevated: 0, ground: 0.03, sunken: 0.06 },
|
|
35
|
-
text: { primary: 0.9, secondary: 0.7, tertiary: 0.5, disabled: 0.3 },
|
|
36
|
-
action: { enabled: 0.04, hovered: 0.06, pressed: 0.08 },
|
|
37
|
-
border: { enabled: 0.08, focused: 0.16, filled: 0.24 },
|
|
38
|
-
},
|
|
39
|
-
dark: {
|
|
40
|
-
background: { elevated: 0.24, ground: 0.20, sunken: 0.16 },
|
|
41
|
-
text: { primary: 1.0, secondary: 0.85, tertiary: 0.7, disabled: 0.55 },
|
|
42
|
-
action: { enabled: 0.04, hovered: 0.06, pressed: 0.08 },
|
|
43
|
-
border: { enabled: 0.08, focused: 0.16, filled: 0.24 },
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Accent palette defaults. Initial values match neutral — will be tuned per-palette later.
|
|
49
|
-
*/
|
|
50
|
-
export const ACCENT_DEFAULTS: PaletteDefaults = {
|
|
51
|
-
light: {
|
|
52
|
-
background: { elevated: 0, ground: 0.03, sunken: 0.06 },
|
|
53
|
-
text: { primary: 0.9, secondary: 0.7, tertiary: 0.5, disabled: 0.3 },
|
|
54
|
-
action: { enabled: 0.04, hovered: 0.06, pressed: 0.08 },
|
|
55
|
-
border: { enabled: 0.08, focused: 0.16, filled: 0.24 },
|
|
56
|
-
},
|
|
57
|
-
dark: {
|
|
58
|
-
background: { elevated: 0.24, ground: 0.20, sunken: 0.16 },
|
|
59
|
-
text: { primary: 1.0, secondary: 0.85, tertiary: 0.7, disabled: 0.55 },
|
|
60
|
-
action: { enabled: 0.04, hovered: 0.06, pressed: 0.08 },
|
|
61
|
-
border: { enabled: 0.08, focused: 0.16, filled: 0.24 },
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Success palette defaults. Initial values match neutral — will be tuned per-palette later.
|
|
67
|
-
*/
|
|
68
|
-
export const SUCCESS_DEFAULTS: PaletteDefaults = {
|
|
69
|
-
light: {
|
|
70
|
-
background: { elevated: 0, ground: 0.03, sunken: 0.06 },
|
|
71
|
-
text: { primary: 0.9, secondary: 0.7, tertiary: 0.5, disabled: 0.3 },
|
|
72
|
-
action: { enabled: 0.04, hovered: 0.06, pressed: 0.08 },
|
|
73
|
-
border: { enabled: 0.08, focused: 0.16, filled: 0.24 },
|
|
74
|
-
},
|
|
75
|
-
dark: {
|
|
76
|
-
background: { elevated: 0.24, ground: 0.20, sunken: 0.16 },
|
|
77
|
-
text: { primary: 1.0, secondary: 0.85, tertiary: 0.7, disabled: 0.55 },
|
|
78
|
-
action: { enabled: 0.04, hovered: 0.06, pressed: 0.08 },
|
|
79
|
-
border: { enabled: 0.08, focused: 0.16, filled: 0.24 },
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Warning palette defaults. Initial values match neutral — will be tuned per-palette later.
|
|
85
|
-
*/
|
|
86
|
-
export const WARNING_DEFAULTS: PaletteDefaults = {
|
|
87
|
-
light: {
|
|
88
|
-
background: { elevated: 0, ground: 0.03, sunken: 0.06 },
|
|
89
|
-
text: { primary: 0.9, secondary: 0.7, tertiary: 0.5, disabled: 0.3 },
|
|
90
|
-
action: { enabled: 0.04, hovered: 0.06, pressed: 0.08 },
|
|
91
|
-
border: { enabled: 0.08, focused: 0.16, filled: 0.24 },
|
|
92
|
-
},
|
|
93
|
-
dark: {
|
|
94
|
-
background: { elevated: 0.24, ground: 0.20, sunken: 0.16 },
|
|
95
|
-
text: { primary: 1.0, secondary: 0.85, tertiary: 0.7, disabled: 0.55 },
|
|
96
|
-
action: { enabled: 0.04, hovered: 0.06, pressed: 0.08 },
|
|
97
|
-
border: { enabled: 0.08, focused: 0.16, filled: 0.24 },
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Error palette defaults. Initial values match neutral — will be tuned per-palette later.
|
|
103
|
-
*/
|
|
104
|
-
export const ERROR_DEFAULTS: PaletteDefaults = {
|
|
105
|
-
light: {
|
|
106
|
-
background: { elevated: 0, ground: 0.03, sunken: 0.06 },
|
|
107
|
-
text: { primary: 0.9, secondary: 0.7, tertiary: 0.5, disabled: 0.3 },
|
|
108
|
-
action: { enabled: 0.04, hovered: 0.06, pressed: 0.08 },
|
|
109
|
-
border: { enabled: 0.08, focused: 0.16, filled: 0.24 },
|
|
110
|
-
},
|
|
111
|
-
dark: {
|
|
112
|
-
background: { elevated: 0.24, ground: 0.20, sunken: 0.16 },
|
|
113
|
-
text: { primary: 1.0, secondary: 0.85, tertiary: 0.7, disabled: 0.55 },
|
|
114
|
-
action: { enabled: 0.04, hovered: 0.06, pressed: 0.08 },
|
|
115
|
-
border: { enabled: 0.08, focused: 0.16, filled: 0.24 },
|
|
116
|
-
},
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
const clamp = (n: number) => Math.max(0, Math.min(1, n));
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Compute the complete PaletteTokens for a non-neutral palette.
|
|
123
|
-
*
|
|
124
|
-
* Uses the palette's hue/saturation with positions from the palette's defaults,
|
|
125
|
-
* plus fill tokens at the palette's key NV position.
|
|
126
|
-
*
|
|
127
|
-
* @param palette - The palette config (hue, saturation, key NV, etc.)
|
|
128
|
-
* @param defaults - Per-mode defaults for this palette (positions + offsets)
|
|
129
|
-
* @param mode - Current color mode
|
|
130
|
-
* @param elevation - Current elevation level
|
|
131
|
-
* @param dynamicRange - Global dynamic range
|
|
132
|
-
* @param elevationDelta - Compensation delta (current surface vs elevated reference)
|
|
133
|
-
* @param effectiveTextMode - Derived from actual background lightness
|
|
134
|
-
* @param autoAccentNv - Auto-derived key NV fallback
|
|
135
|
-
* @param neutralTextPrimary - Neutral textPrimary for onFill (dark text on light fills)
|
|
136
|
-
* @param neutralBgElevated - Neutral backgroundElevated for onFill (light text on dark fills)
|
|
137
|
-
*/
|
|
138
|
-
function computePaletteTokens(
|
|
139
|
-
palette: PaletteConfig,
|
|
140
|
-
defaults: PaletteDefaults,
|
|
141
|
-
mode: ColorMode,
|
|
142
|
-
elevation: ElevationLevel,
|
|
143
|
-
dynamicRange: { readonly lightest: number; readonly darkest: number },
|
|
144
|
-
elevationDelta: number,
|
|
145
|
-
effectiveTextMode: ColorMode,
|
|
146
|
-
autoAccentNv: number,
|
|
147
|
-
neutralTextPrimary: ReturnType<typeof getColor>,
|
|
148
|
-
neutralBgElevated: ReturnType<typeof getColor>,
|
|
149
|
-
): PaletteTokens {
|
|
150
|
-
const modeDefaults = defaults[mode];
|
|
151
|
-
const toEngineNv = (nv: number) => mode === 'light' ? 1 - nv : nv;
|
|
152
|
-
const textToEngineNv = (nv: number) => effectiveTextMode === 'light' ? 1 - nv : nv;
|
|
153
|
-
|
|
154
|
-
const colorAt = (engineNv: number) => getColor(
|
|
155
|
-
palette.hue, palette.saturation, dynamicRange,
|
|
156
|
-
clamp(engineNv), palette.desaturation, palette.paletteHueGrading
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
// --- Fill: key color (user-chosen or auto-derived), elevation-compensated ---
|
|
160
|
-
const resolveKeyNv = (p: PaletteConfig): number | undefined =>
|
|
161
|
-
mode === 'dark' ? p.keyNormalizedValueDark : p.keyNormalizedValue;
|
|
162
|
-
|
|
163
|
-
const keyNv = resolveKeyNv(palette);
|
|
164
|
-
const fillBaseNv = keyNv ?? autoAccentNv;
|
|
165
|
-
const fillNv = clamp(fillBaseNv + elevationDelta);
|
|
166
|
-
const fill = colorAt(fillNv);
|
|
167
|
-
|
|
168
|
-
const hoverDir = effectiveTextMode === 'light' ? -modeDefaults.action.hovered : modeDefaults.action.hovered;
|
|
169
|
-
const activeDir = effectiveTextMode === 'light' ? -modeDefaults.action.pressed : modeDefaults.action.pressed;
|
|
170
|
-
const fillHover = colorAt(clamp(fillNv + hoverDir));
|
|
171
|
-
const fillActive = colorAt(clamp(fillNv + activeDir));
|
|
172
|
-
|
|
173
|
-
// onFill: high-contrast text on the fill color
|
|
174
|
-
const onFill = fill.oklch.L > 0.6 ? neutralTextPrimary : neutralBgElevated;
|
|
175
|
-
|
|
176
|
-
// --- Surface: palette-tinted backgrounds at standard positions ---
|
|
177
|
-
const bgNormalized = elevation === 2
|
|
178
|
-
? modeDefaults.background.elevated
|
|
179
|
-
: elevation === 1
|
|
180
|
-
? modeDefaults.background.ground
|
|
181
|
-
: modeDefaults.background.sunken;
|
|
182
|
-
const bgNv = clamp(toEngineNv(bgNormalized));
|
|
183
|
-
const background = colorAt(bgNv);
|
|
184
|
-
const backgroundElevated = colorAt(clamp(toEngineNv(modeDefaults.background.elevated)));
|
|
185
|
-
const backgroundSunken = colorAt(clamp(toEngineNv(modeDefaults.background.sunken)));
|
|
186
|
-
|
|
187
|
-
// --- Interactive surface: offset from palette background ---
|
|
188
|
-
const interactiveOffset = modeDefaults.action.enabled;
|
|
189
|
-
const interactiveNv = clamp(bgNv + (effectiveTextMode === 'light' ? -interactiveOffset : interactiveOffset));
|
|
190
|
-
const backgroundInteractive = colorAt(interactiveNv);
|
|
191
|
-
|
|
192
|
-
const hoverShift = modeDefaults.action.hovered;
|
|
193
|
-
const activeShift = modeDefaults.action.pressed;
|
|
194
|
-
const backgroundInteractiveHover = colorAt(clamp(interactiveNv + (effectiveTextMode === 'light' ? -hoverShift : hoverShift)));
|
|
195
|
-
const backgroundInteractiveActive = colorAt(clamp(interactiveNv + (effectiveTextMode === 'light' ? -activeShift : activeShift)));
|
|
196
|
-
|
|
197
|
-
// --- Text: palette-hued text at standard positions, elevation-compensated ---
|
|
198
|
-
const textPrimary = colorAt(clamp(textToEngineNv(modeDefaults.text.primary) + elevationDelta));
|
|
199
|
-
const textSecondary = colorAt(clamp(textToEngineNv(modeDefaults.text.secondary) + elevationDelta));
|
|
200
|
-
const textTertiary = colorAt(clamp(textToEngineNv(modeDefaults.text.tertiary) + elevationDelta));
|
|
201
|
-
const textDisabled = colorAt(clamp(textToEngineNv(modeDefaults.text.disabled) + elevationDelta));
|
|
202
|
-
|
|
203
|
-
// --- Border: offset from palette background ---
|
|
204
|
-
const borderOffset = modeDefaults.border.enabled;
|
|
205
|
-
const borderNv = effectiveTextMode === 'light' ? bgNv - borderOffset : bgNv + borderOffset;
|
|
206
|
-
const border = colorAt(clamp(borderNv));
|
|
207
|
-
|
|
208
|
-
return {
|
|
209
|
-
fill, fillHover, fillActive, onFill,
|
|
210
|
-
background, backgroundElevated, backgroundSunken,
|
|
211
|
-
backgroundInteractive, backgroundInteractiveHover, backgroundInteractiveActive,
|
|
212
|
-
textPrimary, textSecondary, textTertiary, textDisabled,
|
|
213
|
-
border,
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Compute design tokens for a specific mode/theme/elevation combination.
|
|
219
|
-
*
|
|
220
|
-
* This function calls the Newtone engine to generate all necessary color tokens
|
|
221
|
-
* based on the current theme context. All colors are computed on-demand using
|
|
222
|
-
* the pure functions from the engine.
|
|
223
|
-
*
|
|
224
|
-
* Background surfaces use absolute positions from NEUTRAL_DEFAULTS (or tokenOverrides
|
|
225
|
-
* when present). Elevation compensation is derived from the difference between
|
|
226
|
-
* the current surface and the elevated reference surface.
|
|
227
|
-
*
|
|
228
|
-
* @param config - Complete color system configuration (dynamic range + palettes)
|
|
229
|
-
* @param mode - Current color mode ('light' or 'dark')
|
|
230
|
-
* @param elevation - Elevation level (0=sunken, 1=default, 2=elevated)
|
|
231
|
-
* @param spacing - Spacing scale for paddings, gaps, and margins
|
|
232
|
-
* @param radius - Border radius scale for component roundness
|
|
233
|
-
* @param typography - Typography configuration with fonts and scales
|
|
234
|
-
* @param icons - Icon configuration with variant, weight, and auto-grade setting
|
|
235
|
-
* @returns Resolved design tokens with all necessary colors
|
|
236
|
-
*
|
|
237
|
-
* @example
|
|
238
|
-
* ```typescript
|
|
239
|
-
* const tokens = computeTokens(
|
|
240
|
-
* config.colorSystem,
|
|
241
|
-
* 'light',
|
|
242
|
-
* 1,
|
|
243
|
-
* config.spacing,
|
|
244
|
-
* config.radius,
|
|
245
|
-
* config.typography,
|
|
246
|
-
* config.icons
|
|
247
|
-
* );
|
|
248
|
-
* console.log(tokens.background.srgb); // { r: 0.95, g: 0.95, b: 0.95 }
|
|
249
|
-
* ```
|
|
250
|
-
*/
|
|
251
|
-
export function computeTokens(
|
|
252
|
-
config: ColorSystemConfig,
|
|
253
|
-
mode: ColorMode,
|
|
254
|
-
elevation: ElevationLevel,
|
|
255
|
-
spacing: { readonly '00': number; readonly '02': number; readonly '04': number; readonly '06': number; readonly '08': number; readonly '10': number; readonly '12': number; readonly '16': number; readonly '20': number; readonly '24': number; readonly '32': number; readonly '40': number; readonly '48': number },
|
|
256
|
-
radius: { readonly none: number; readonly sm: number; readonly md: number; readonly lg: number; readonly xl: number; readonly pill: 999 },
|
|
257
|
-
typography: {
|
|
258
|
-
readonly fonts: { readonly main: FontSlot; readonly display: FontSlot; readonly mono: FontSlot; readonly currency: FontSlot };
|
|
259
|
-
readonly fontSizes: { readonly [key: string]: number };
|
|
260
|
-
readonly lineHeights: { readonly [key: string]: number };
|
|
261
|
-
},
|
|
262
|
-
icons: {
|
|
263
|
-
readonly variant: 'outlined' | 'rounded' | 'sharp';
|
|
264
|
-
readonly weight: 100 | 200 | 300 | 400 | 500 | 600 | 700;
|
|
265
|
-
readonly autoGrade: boolean;
|
|
266
|
-
},
|
|
267
|
-
tokenOverrides?: TokenOverrides
|
|
268
|
-
): ResolvedTokens {
|
|
269
|
-
const { dynamicRange, palettes } = config;
|
|
270
|
-
const palette = palettes[0]; // Always neutral palette for backgrounds
|
|
271
|
-
|
|
272
|
-
if (!palette) {
|
|
273
|
-
throw new Error('Neutral palette (index 0) not found');
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
const neutralDefaults = NEUTRAL_DEFAULTS[mode];
|
|
277
|
-
|
|
278
|
-
// --- Mode-specific normalized field resolution ---
|
|
279
|
-
const toEngineNv = (nv: number) => mode === 'light' ? 1 - nv : nv;
|
|
280
|
-
const bgElevatedNorm = mode === 'light' ? tokenOverrides?.backgroundElevated : tokenOverrides?.backgroundElevatedDark;
|
|
281
|
-
const bgDefaultNorm = mode === 'light' ? tokenOverrides?.backgroundDefault : tokenOverrides?.backgroundDefaultDark;
|
|
282
|
-
const bgSunkenNorm = mode === 'light' ? tokenOverrides?.backgroundSunken : tokenOverrides?.backgroundSunkenDark;
|
|
283
|
-
const textPrimaryNorm = mode === 'light' ? tokenOverrides?.textPrimaryNormalized : tokenOverrides?.textPrimaryNormalizedDark;
|
|
284
|
-
const textSecondaryNorm = mode === 'light' ? tokenOverrides?.textSecondaryNormalized : tokenOverrides?.textSecondaryNormalizedDark;
|
|
285
|
-
const textTertiaryNorm = mode === 'light' ? tokenOverrides?.textTertiaryNormalized : tokenOverrides?.textTertiaryNormalizedDark;
|
|
286
|
-
const textDisabledNorm = mode === 'light' ? tokenOverrides?.textDisabledNormalized : tokenOverrides?.textDisabledNormalizedDark;
|
|
287
|
-
|
|
288
|
-
// --- Background NV resolution ---
|
|
289
|
-
// Absolute positions from tokenOverrides or NEUTRAL_DEFAULTS.
|
|
290
|
-
// Ground = Background/01 (elevated). Everything diverges from there.
|
|
291
|
-
const bgNormalized = elevation === 2
|
|
292
|
-
? (bgElevatedNorm ?? neutralDefaults.background.elevated)
|
|
293
|
-
: elevation === 1
|
|
294
|
-
? (bgDefaultNorm ?? neutralDefaults.background.ground)
|
|
295
|
-
: (bgSunkenNorm ?? neutralDefaults.background.sunken);
|
|
296
|
-
const backgroundNv = clamp(toEngineNv(bgNormalized));
|
|
297
|
-
const elevatedNv = clamp(toEngineNv(bgElevatedNorm ?? neutralDefaults.background.elevated));
|
|
298
|
-
const sunkenNv = clamp(toEngineNv(bgSunkenNorm ?? neutralDefaults.background.sunken));
|
|
299
|
-
|
|
300
|
-
// Elevation compensation: how far the current surface is from the reference (bg01/elevated).
|
|
301
|
-
// Tokens designed at bg01 shift by this delta on deeper surfaces to preserve perceptual contrast.
|
|
302
|
-
// Always 0 on bg01. Negative on bg02/bg03 in both modes (surface is darker → tokens darken too).
|
|
303
|
-
const elevationDelta = backgroundNv - elevatedNv;
|
|
304
|
-
|
|
305
|
-
// Derive effective text mode from actual background lightness.
|
|
306
|
-
// This handles inverted themes (e.g., strong: dark bg in light mode)
|
|
307
|
-
// where the mode flag doesn't match the background's visual lightness.
|
|
308
|
-
const effectiveTextMode: ColorMode = backgroundNv >= 0.5 ? 'light' : 'dark';
|
|
309
|
-
|
|
310
|
-
// Compute background colors for current elevation
|
|
311
|
-
const background = getColor(
|
|
312
|
-
palette.hue,
|
|
313
|
-
palette.saturation,
|
|
314
|
-
dynamicRange,
|
|
315
|
-
backgroundNv,
|
|
316
|
-
palette.desaturation,
|
|
317
|
-
palette.paletteHueGrading
|
|
318
|
-
);
|
|
319
|
-
|
|
320
|
-
// Compute elevated surface
|
|
321
|
-
const backgroundElevated = getColor(
|
|
322
|
-
palette.hue,
|
|
323
|
-
palette.saturation,
|
|
324
|
-
dynamicRange,
|
|
325
|
-
elevatedNv,
|
|
326
|
-
palette.desaturation,
|
|
327
|
-
palette.paletteHueGrading
|
|
328
|
-
);
|
|
329
|
-
|
|
330
|
-
// Compute sunken surface
|
|
331
|
-
const backgroundSunken = getColor(
|
|
332
|
-
palette.hue,
|
|
333
|
-
palette.saturation,
|
|
334
|
-
dynamicRange,
|
|
335
|
-
sunkenNv,
|
|
336
|
-
palette.desaturation,
|
|
337
|
-
palette.paletteHueGrading
|
|
338
|
-
);
|
|
339
|
-
|
|
340
|
-
// --- Tunable constants (overridable via tokenOverrides, per-mode) ---
|
|
341
|
-
// All values are magnitudes — direction auto-inverts per effectiveTextMode
|
|
342
|
-
// (darker in light mode, lighter in dark mode)
|
|
343
|
-
const INTERACTIVE_COMPONENT_OFFSET = mode === 'light'
|
|
344
|
-
? (tokenOverrides?.interactiveComponentOffset ?? neutralDefaults.action.enabled)
|
|
345
|
-
: (tokenOverrides?.interactiveComponentOffsetDark ?? neutralDefaults.action.enabled);
|
|
346
|
-
const HOVER_SHIFT = mode === 'light'
|
|
347
|
-
? (tokenOverrides?.hoverShift ?? neutralDefaults.action.hovered)
|
|
348
|
-
: (tokenOverrides?.hoverShiftDark ?? neutralDefaults.action.hovered);
|
|
349
|
-
const ACTIVE_SHIFT = mode === 'light'
|
|
350
|
-
? (tokenOverrides?.activeShift ?? neutralDefaults.action.pressed)
|
|
351
|
-
: (tokenOverrides?.activeShiftDark ?? neutralDefaults.action.pressed);
|
|
352
|
-
const BORDER_OFFSET = mode === 'light'
|
|
353
|
-
? (tokenOverrides?.borderOffset ?? neutralDefaults.border.enabled)
|
|
354
|
-
: (tokenOverrides?.borderOffsetDark ?? neutralDefaults.border.enabled);
|
|
355
|
-
// Compute interactive component background (FIXED NV offset from current elevation)
|
|
356
|
-
// Unlike backgroundElevated/backgroundSunken which use discrete levels, this uses a fixed
|
|
357
|
-
// luminosity offset to ensure CONSISTENT visual contrast across all elevations (-2 to 2).
|
|
358
|
-
// Used by: Button (neutral primary variant) and future components with neutral filled backgrounds.
|
|
359
|
-
const interactiveComponentNv = clamp(backgroundNv + (effectiveTextMode === 'light' ? -INTERACTIVE_COMPONENT_OFFSET : INTERACTIVE_COMPONENT_OFFSET));
|
|
360
|
-
const backgroundInteractive = getColor(
|
|
361
|
-
palette.hue,
|
|
362
|
-
palette.saturation,
|
|
363
|
-
dynamicRange,
|
|
364
|
-
interactiveComponentNv,
|
|
365
|
-
palette.desaturation,
|
|
366
|
-
palette.paletteHueGrading
|
|
367
|
-
);
|
|
368
|
-
|
|
369
|
-
// Neutral hover/active: shift from interactive component base (same direction as accent hover/active)
|
|
370
|
-
const neutralHoverNv = clamp(interactiveComponentNv + (effectiveTextMode === 'light' ? -HOVER_SHIFT : HOVER_SHIFT));
|
|
371
|
-
const backgroundInteractiveHover = getColor(
|
|
372
|
-
palette.hue,
|
|
373
|
-
palette.saturation,
|
|
374
|
-
dynamicRange,
|
|
375
|
-
neutralHoverNv,
|
|
376
|
-
palette.desaturation,
|
|
377
|
-
palette.paletteHueGrading
|
|
378
|
-
);
|
|
379
|
-
|
|
380
|
-
const neutralActiveNv = clamp(interactiveComponentNv + (effectiveTextMode === 'light' ? -ACTIVE_SHIFT : ACTIVE_SHIFT));
|
|
381
|
-
const backgroundInteractiveActive = getColor(
|
|
382
|
-
palette.hue,
|
|
383
|
-
palette.saturation,
|
|
384
|
-
dynamicRange,
|
|
385
|
-
neutralActiveNv,
|
|
386
|
-
palette.desaturation,
|
|
387
|
-
palette.paletteHueGrading
|
|
388
|
-
);
|
|
389
|
-
|
|
390
|
-
// --- Text color resolution (elevation-compensated) ---
|
|
391
|
-
// Normalized positions define text contrast at bg01 (elevated). On deeper surfaces,
|
|
392
|
-
// elevationDelta shifts text toward the background to preserve the same contrast distance.
|
|
393
|
-
// Uses effectiveTextMode for NV conversion so inverted themes (e.g., strong: dark bg in
|
|
394
|
-
// light mode) auto-correct text direction — light text on dark bg, dark text on light bg.
|
|
395
|
-
const textToEngineNv = (nv: number) => effectiveTextMode === 'light' ? 1 - nv : nv;
|
|
396
|
-
|
|
397
|
-
const textPrimary = getColor(palette.hue, palette.saturation, dynamicRange,
|
|
398
|
-
clamp(textToEngineNv(textPrimaryNorm ?? neutralDefaults.text.primary) + elevationDelta),
|
|
399
|
-
palette.desaturation, palette.paletteHueGrading);
|
|
400
|
-
|
|
401
|
-
const textSecondary = getColor(palette.hue, palette.saturation, dynamicRange,
|
|
402
|
-
clamp(textToEngineNv(textSecondaryNorm ?? neutralDefaults.text.secondary) + elevationDelta),
|
|
403
|
-
palette.desaturation, palette.paletteHueGrading);
|
|
404
|
-
|
|
405
|
-
const textTertiary = getColor(palette.hue, palette.saturation, dynamicRange,
|
|
406
|
-
clamp(textToEngineNv(textTertiaryNorm ?? neutralDefaults.text.tertiary) + elevationDelta),
|
|
407
|
-
palette.desaturation, palette.paletteHueGrading);
|
|
408
|
-
|
|
409
|
-
const textDisabled = getColor(palette.hue, palette.saturation, dynamicRange,
|
|
410
|
-
clamp(textToEngineNv(textDisabledNorm ?? neutralDefaults.text.disabled) + elevationDelta),
|
|
411
|
-
palette.desaturation, palette.paletteHueGrading);
|
|
412
|
-
|
|
413
|
-
// Border: Subtle contrast from background
|
|
414
|
-
const borderNv = effectiveTextMode === 'light' ? backgroundNv - BORDER_OFFSET : backgroundNv + BORDER_OFFSET;
|
|
415
|
-
const border = getColor(
|
|
416
|
-
palette.hue,
|
|
417
|
-
palette.saturation,
|
|
418
|
-
dynamicRange,
|
|
419
|
-
clamp(borderNv),
|
|
420
|
-
palette.desaturation,
|
|
421
|
-
palette.paletteHueGrading
|
|
422
|
-
);
|
|
423
|
-
|
|
424
|
-
// --- Per-palette token computation ---
|
|
425
|
-
// Auto accent NV: derived from text primary position (used when no explicit key color is set)
|
|
426
|
-
const autoAccentNv = clamp(textToEngineNv(textPrimaryNorm ?? neutralDefaults.text.primary));
|
|
427
|
-
|
|
428
|
-
const accentPalette = palettes[1];
|
|
429
|
-
if (!accentPalette) {
|
|
430
|
-
throw new Error('Accent palette (index 1) not found');
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
const accent = computePaletteTokens(
|
|
434
|
-
accentPalette, ACCENT_DEFAULTS, mode, elevation, dynamicRange,
|
|
435
|
-
elevationDelta, effectiveTextMode, autoAccentNv,
|
|
436
|
-
textPrimary, backgroundElevated,
|
|
437
|
-
);
|
|
438
|
-
|
|
439
|
-
const successPalette = palettes[2];
|
|
440
|
-
const warningPalette = palettes[3];
|
|
441
|
-
const errorPalette = palettes[4];
|
|
442
|
-
|
|
443
|
-
// Semantic palettes: fall back to accent palette if not present
|
|
444
|
-
const success = successPalette
|
|
445
|
-
? computePaletteTokens(
|
|
446
|
-
successPalette, SUCCESS_DEFAULTS, mode, elevation, dynamicRange,
|
|
447
|
-
elevationDelta, effectiveTextMode, autoAccentNv,
|
|
448
|
-
textPrimary, backgroundElevated,
|
|
449
|
-
)
|
|
450
|
-
: accent;
|
|
451
|
-
|
|
452
|
-
const warning = warningPalette
|
|
453
|
-
? computePaletteTokens(
|
|
454
|
-
warningPalette, WARNING_DEFAULTS, mode, elevation, dynamicRange,
|
|
455
|
-
elevationDelta, effectiveTextMode, autoAccentNv,
|
|
456
|
-
textPrimary, backgroundElevated,
|
|
457
|
-
)
|
|
458
|
-
: accent;
|
|
459
|
-
|
|
460
|
-
const error = errorPalette
|
|
461
|
-
? computePaletteTokens(
|
|
462
|
-
errorPalette, ERROR_DEFAULTS, mode, elevation, dynamicRange,
|
|
463
|
-
elevationDelta, effectiveTextMode, autoAccentNv,
|
|
464
|
-
textPrimary, backgroundElevated,
|
|
465
|
-
)
|
|
466
|
-
: accent;
|
|
467
|
-
|
|
468
|
-
return {
|
|
469
|
-
background,
|
|
470
|
-
backgroundElevated,
|
|
471
|
-
backgroundSunken,
|
|
472
|
-
backgroundInteractive,
|
|
473
|
-
backgroundInteractiveHover,
|
|
474
|
-
backgroundInteractiveActive,
|
|
475
|
-
textPrimary,
|
|
476
|
-
textSecondary,
|
|
477
|
-
textTertiary,
|
|
478
|
-
textDisabled,
|
|
479
|
-
border,
|
|
480
|
-
accent,
|
|
481
|
-
success,
|
|
482
|
-
warning,
|
|
483
|
-
error,
|
|
484
|
-
spacing,
|
|
485
|
-
radius,
|
|
486
|
-
typography: {
|
|
487
|
-
fonts: {
|
|
488
|
-
main: {
|
|
489
|
-
family: fontConfigToFamily(typography.fonts.main.config),
|
|
490
|
-
weights: typography.fonts.main.weights,
|
|
491
|
-
},
|
|
492
|
-
display: {
|
|
493
|
-
family: fontConfigToFamily(typography.fonts.display.config),
|
|
494
|
-
weights: typography.fonts.display.weights,
|
|
495
|
-
},
|
|
496
|
-
mono: {
|
|
497
|
-
family: fontConfigToFamily(typography.fonts.mono.config),
|
|
498
|
-
weights: typography.fonts.mono.weights,
|
|
499
|
-
},
|
|
500
|
-
currency: {
|
|
501
|
-
family: fontConfigToFamily(typography.fonts.currency.config),
|
|
502
|
-
weights: typography.fonts.currency.weights,
|
|
503
|
-
},
|
|
504
|
-
},
|
|
505
|
-
fontSizes: typography.fontSizes,
|
|
506
|
-
lineHeights: typography.lineHeights,
|
|
507
|
-
},
|
|
508
|
-
icons: {
|
|
509
|
-
variant: icons.variant,
|
|
510
|
-
weight: icons.weight,
|
|
511
|
-
grade: icons.autoGrade
|
|
512
|
-
? (mode === 'light' ? -25 : 200)
|
|
513
|
-
: 0,
|
|
514
|
-
},
|
|
515
|
-
};
|
|
516
|
-
}
|
package/src/tokens/types.ts
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import type { ColorResult } from 'newtone';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Complete token set for a non-neutral palette (accent, success, warning, error).
|
|
5
|
-
*
|
|
6
|
-
* Fill tokens use the palette's key NV position (user-chosen or WCAG auto-derived).
|
|
7
|
-
* Surface tokens use standard positions from PaletteDefaults, rendered in the palette's hue/saturation.
|
|
8
|
-
*/
|
|
9
|
-
export interface PaletteTokens {
|
|
10
|
-
// --- Fill: the palette's key color for prominent surfaces ---
|
|
11
|
-
/** Key color at the palette's keyNormalizedValue (used for primary Button fills, badges, indicators) */
|
|
12
|
-
readonly fill: ColorResult;
|
|
13
|
-
/** Key color shifted for hover state */
|
|
14
|
-
readonly fillHover: ColorResult;
|
|
15
|
-
/** Key color shifted for pressed/active state */
|
|
16
|
-
readonly fillActive: ColorResult;
|
|
17
|
-
/** High-contrast color for text/icons on top of fill (auto: dark text on light fills, light on dark) */
|
|
18
|
-
readonly onFill: ColorResult;
|
|
19
|
-
|
|
20
|
-
// --- Surface: subtle palette-tinted backgrounds ---
|
|
21
|
-
/** Palette-tinted background at current elevation */
|
|
22
|
-
readonly background: ColorResult;
|
|
23
|
-
/** Palette-tinted elevated surface */
|
|
24
|
-
readonly backgroundElevated: ColorResult;
|
|
25
|
-
/** Palette-tinted sunken surface */
|
|
26
|
-
readonly backgroundSunken: ColorResult;
|
|
27
|
-
|
|
28
|
-
// --- Interactive surface: interactive elements on palette surfaces ---
|
|
29
|
-
/** Interactive element background within palette surface */
|
|
30
|
-
readonly backgroundInteractive: ColorResult;
|
|
31
|
-
/** Hover state for interactive elements within palette surface */
|
|
32
|
-
readonly backgroundInteractiveHover: ColorResult;
|
|
33
|
-
/** Pressed/active state for interactive elements within palette surface */
|
|
34
|
-
readonly backgroundInteractiveActive: ColorResult;
|
|
35
|
-
|
|
36
|
-
// --- Text: palette-hued text on neutral backgrounds ---
|
|
37
|
-
/** High-contrast palette-colored text */
|
|
38
|
-
readonly textPrimary: ColorResult;
|
|
39
|
-
/** Medium-contrast palette-colored text */
|
|
40
|
-
readonly textSecondary: ColorResult;
|
|
41
|
-
/** Low-contrast palette-colored text */
|
|
42
|
-
readonly textTertiary: ColorResult;
|
|
43
|
-
/** Disabled palette-colored text */
|
|
44
|
-
readonly textDisabled: ColorResult;
|
|
45
|
-
|
|
46
|
-
// --- Border ---
|
|
47
|
-
/** Palette-colored border */
|
|
48
|
-
readonly border: ColorResult;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Resolved design tokens for a specific mode/theme/elevation combination
|
|
53
|
-
*/
|
|
54
|
-
export interface ResolvedTokens {
|
|
55
|
-
// --- Neutral palette (top-level for convenience — most-used palette) ---
|
|
56
|
-
|
|
57
|
-
/** Background color for the current surface */
|
|
58
|
-
readonly background: ColorResult;
|
|
59
|
-
/** Background color for elevated surfaces (cards, modals) */
|
|
60
|
-
readonly backgroundElevated: ColorResult;
|
|
61
|
-
/** Background color for sunken surfaces (input fields, wells) */
|
|
62
|
-
readonly backgroundSunken: ColorResult;
|
|
63
|
-
/**
|
|
64
|
-
* Background color for interactive components with neutral backgrounds.
|
|
65
|
-
* Uses a fixed NV offset from current background to ensure
|
|
66
|
-
* consistent visual contrast across all elevations (-2 to 2).
|
|
67
|
-
*
|
|
68
|
-
* Use for: Button (neutral primary enabled), and future components with neutral filled backgrounds.
|
|
69
|
-
* Don't use for: Semantic variants (accent/success/error/warning), transparent backgrounds,
|
|
70
|
-
* or primitives (Frame/Wrapper/Text/Icon already handle elevation correctly).
|
|
71
|
-
*/
|
|
72
|
-
readonly backgroundInteractive: ColorResult;
|
|
73
|
-
/** Hover state for neutral interactive components (enabled + hoverShift) */
|
|
74
|
-
readonly backgroundInteractiveHover: ColorResult;
|
|
75
|
-
/** Pressed/active state for neutral interactive components (enabled + activeShift) */
|
|
76
|
-
readonly backgroundInteractiveActive: ColorResult;
|
|
77
|
-
/** Primary text color (high contrast for body text, 4.5:1 default) */
|
|
78
|
-
readonly textPrimary: ColorResult;
|
|
79
|
-
/** Secondary text color (lower contrast for captions, labels, 3.0:1 default) */
|
|
80
|
-
readonly textSecondary: ColorResult;
|
|
81
|
-
/** Tertiary text color (hints, placeholders, 2.0:1 default) */
|
|
82
|
-
readonly textTertiary: ColorResult;
|
|
83
|
-
/** Disabled text color (disabled elements, 1.5:1 default) */
|
|
84
|
-
readonly textDisabled: ColorResult;
|
|
85
|
-
/** Border color for subtle separators */
|
|
86
|
-
readonly border: ColorResult;
|
|
87
|
-
|
|
88
|
-
// --- Per-palette token sets ---
|
|
89
|
-
|
|
90
|
-
/** Accent palette tokens (palette index 1) — interactive elements, brand color */
|
|
91
|
-
readonly accent: PaletteTokens;
|
|
92
|
-
/** Success palette tokens (palette index 2) — positive state indicators */
|
|
93
|
-
readonly success: PaletteTokens;
|
|
94
|
-
/** Warning palette tokens (palette index 3) — caution state indicators */
|
|
95
|
-
readonly warning: PaletteTokens;
|
|
96
|
-
/** Error palette tokens (palette index 4) — destructive/error state indicators */
|
|
97
|
-
readonly error: PaletteTokens;
|
|
98
|
-
|
|
99
|
-
/** Spacing tokens for paddings, gaps, and margins.
|
|
100
|
-
* Token names represent pixel values at Medium (8px) spacing preset.
|
|
101
|
-
* Actual values scale based on the selected spacing preset. */
|
|
102
|
-
readonly spacing: {
|
|
103
|
-
readonly '00': number; // 0px (always 0)
|
|
104
|
-
readonly '02': number; // 2px at Medium (0.25x multiplier)
|
|
105
|
-
readonly '04': number; // 4px at Medium (0.5x multiplier)
|
|
106
|
-
readonly '06': number; // 6px at Medium (0.75x multiplier)
|
|
107
|
-
readonly '08': number; // 8px at Medium (1x multiplier, equals base)
|
|
108
|
-
readonly '10': number; // 10px at Medium (1.25x multiplier)
|
|
109
|
-
readonly '12': number; // 12px at Medium (1.5x multiplier)
|
|
110
|
-
readonly '16': number; // 16px at Medium (2x multiplier)
|
|
111
|
-
readonly '20': number; // 20px at Medium (2.5x multiplier)
|
|
112
|
-
readonly '24': number; // 24px at Medium (3x multiplier)
|
|
113
|
-
readonly '32': number; // 32px at Medium (4x multiplier)
|
|
114
|
-
readonly '40': number; // 40px at Medium (5x multiplier)
|
|
115
|
-
readonly '48': number; // 48px at Medium (6x multiplier)
|
|
116
|
-
};
|
|
117
|
-
/** Border radius tokens for component roundness */
|
|
118
|
-
readonly radius: {
|
|
119
|
-
readonly none: number;
|
|
120
|
-
readonly sm: number;
|
|
121
|
-
readonly md: number;
|
|
122
|
-
readonly lg: number;
|
|
123
|
-
readonly xl: number;
|
|
124
|
-
readonly pill: 999;
|
|
125
|
-
};
|
|
126
|
-
/** Typography tokens for fonts (per-scope) and primitive size/lineHeight scales */
|
|
127
|
-
readonly typography: {
|
|
128
|
-
/** Per-scope font family + weight mapping */
|
|
129
|
-
readonly fonts: {
|
|
130
|
-
readonly main: { readonly family: string; readonly weights: { readonly regular: number; readonly medium: number; readonly bold: number; } };
|
|
131
|
-
readonly display: { readonly family: string; readonly weights: { readonly regular: number; readonly medium: number; readonly bold: number; } };
|
|
132
|
-
readonly mono: { readonly family: string; readonly weights: { readonly regular: number; readonly medium: number; readonly bold: number; } };
|
|
133
|
-
readonly currency: { readonly family: string; readonly weights: { readonly regular: number; readonly medium: number; readonly bold: number; } };
|
|
134
|
-
};
|
|
135
|
-
/** Primitive font size scale — numbered tokens ('01'–'16'), values in px */
|
|
136
|
-
readonly fontSizes: { readonly [key: string]: number };
|
|
137
|
-
/** Primitive line height scale — numbered tokens ('01'–'16'), values in px */
|
|
138
|
-
readonly lineHeights: { readonly [key: string]: number };
|
|
139
|
-
};
|
|
140
|
-
/** Icon tokens for Material Symbols configuration */
|
|
141
|
-
readonly icons: {
|
|
142
|
-
readonly variant: 'outlined' | 'rounded' | 'sharp';
|
|
143
|
-
readonly weight: 100 | 200 | 300 | 400 | 500 | 600 | 700;
|
|
144
|
-
readonly grade: -25 | 0 | 200; // Mode-aware: light=-25, dark=200
|
|
145
|
-
};
|
|
146
|
-
}
|