@jztack/tokens 0.0.0-stage → 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/dist/index.d.ts +11 -0
- package/dist/index.js +11 -0
- package/dist/locale/my.d.ts +16 -0
- package/dist/locale/my.js +22 -0
- package/dist/palette/colors.d.ts +130 -0
- package/dist/palette/colors.js +129 -0
- package/dist/restyle.d.ts +38 -0
- package/dist/restyle.js +140 -0
- package/dist/semantic/contract.d.ts +118 -0
- package/dist/semantic/contract.js +148 -0
- package/dist/themes/commonboard.d.ts +13 -0
- package/dist/themes/commonboard.js +47 -0
- package/dist/themes/index.d.ts +10 -0
- package/dist/themes/index.js +15 -0
- package/dist/themes/rentproof.d.ts +2 -0
- package/dist/themes/rentproof.js +50 -0
- package/dist/themes/status-defaults.d.ts +11 -0
- package/dist/themes/status-defaults.js +29 -0
- package/dist/themes/tabbie.d.ts +2 -0
- package/dist/themes/tabbie.js +65 -0
- package/dist/themes/twjs.d.ts +19 -0
- package/dist/themes/twjs.js +78 -0
- package/dist/themes/wedding-ops.d.ts +18 -0
- package/dist/themes/wedding-ops.js +50 -0
- package/dist/tokens.css +472 -0
- package/package.json +29 -3
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jztack/tokens — one source of truth for design tokens across all apps.
|
|
3
|
+
* This entry point exports the token DATA (palette, contract, themes,
|
|
4
|
+
* locale layers). Web consumers normally import the emitted stylesheet
|
|
5
|
+
* (`@jztack/tokens/css`); restyle consumers use `@jztack/tokens/restyle`.
|
|
6
|
+
*/
|
|
7
|
+
export { type LocaleOverride, localeOverrides, my } from './locale/my.js';
|
|
8
|
+
export { type Palette, palette } from './palette/colors.js';
|
|
9
|
+
export { type BreakpointScale, breakpoints, type ColorSet, type ColorSlot, type ContainerKey, type ContainerScale, colorSlots, container, fontFamily, type RadiiScale, radii, type SpacingKey, type SpacingScale, spacing, type ThemeDefinition, type ThemeMode, type TypeColorRole, type TypeRole, type TypeRoleName, type TypeRoles, typeRoleNames, typeRoles, } from './semantic/contract.js';
|
|
10
|
+
export { commonboard, rentproof, tabbie, themeNames, themes, twjs, weddingOps, } from './themes/index.js';
|
|
11
|
+
export { darkStatus, lightStatus, type StatusSlots } from './themes/status-defaults.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jztack/tokens — one source of truth for design tokens across all apps.
|
|
3
|
+
* This entry point exports the token DATA (palette, contract, themes,
|
|
4
|
+
* locale layers). Web consumers normally import the emitted stylesheet
|
|
5
|
+
* (`@jztack/tokens/css`); restyle consumers use `@jztack/tokens/restyle`.
|
|
6
|
+
*/
|
|
7
|
+
export { localeOverrides, my } from './locale/my.js';
|
|
8
|
+
export { palette } from './palette/colors.js';
|
|
9
|
+
export { breakpoints, colorSlots, container, fontFamily, radii, spacing, typeRoleNames, typeRoles, } from './semantic/contract.js';
|
|
10
|
+
export { commonboard, rentproof, tabbie, themeNames, themes, twjs, weddingOps, } from './themes/index.js';
|
|
11
|
+
export { darkStatus, lightStatus } from './themes/status-defaults.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { TypeRole, TypeRoleName } from '../semantic/contract.js';
|
|
2
|
+
/**
|
|
3
|
+
* Locale override layers: partial theme-shaped objects applied on top of a
|
|
4
|
+
* theme. A layer may only override keys that exist in the contract
|
|
5
|
+
* (enforced by type and by test).
|
|
6
|
+
*/
|
|
7
|
+
export interface LocaleOverride {
|
|
8
|
+
textVariants?: Partial<Record<TypeRoleName, Partial<TypeRole>>>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Burmese (`my`) — verbatim from TWJS themeTypography.ts. Myanmar glyphs
|
|
12
|
+
* stack above and below the baseline, so every role gets a smaller size and
|
|
13
|
+
* a ~1.7–2.0× line height, or glyphs clip inside fixed-height rows.
|
|
14
|
+
*/
|
|
15
|
+
export declare const my: LocaleOverride;
|
|
16
|
+
export declare const localeOverrides: Record<string, LocaleOverride>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Burmese (`my`) — verbatim from TWJS themeTypography.ts. Myanmar glyphs
|
|
3
|
+
* stack above and below the baseline, so every role gets a smaller size and
|
|
4
|
+
* a ~1.7–2.0× line height, or glyphs clip inside fixed-height rows.
|
|
5
|
+
*/
|
|
6
|
+
export const my = {
|
|
7
|
+
textVariants: {
|
|
8
|
+
header: { fontSize: 24, lineHeight: 38 },
|
|
9
|
+
title: { fontSize: 18, lineHeight: 28 },
|
|
10
|
+
subtitle: { fontSize: 15, lineHeight: 24 },
|
|
11
|
+
body: { fontSize: 14, lineHeight: 24 },
|
|
12
|
+
'body-strong': { fontSize: 14, lineHeight: 24 },
|
|
13
|
+
'body-secondary': { fontSize: 12, lineHeight: 24 },
|
|
14
|
+
button: { fontSize: 14, lineHeight: 28 },
|
|
15
|
+
badge: { fontSize: 11, lineHeight: 20 },
|
|
16
|
+
error: { fontSize: 11, lineHeight: 18 },
|
|
17
|
+
kpi: { fontSize: 24, lineHeight: 38 },
|
|
18
|
+
caption: { fontSize: 11, lineHeight: 20 },
|
|
19
|
+
defaults: { fontSize: 14, lineHeight: 24 },
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
export const localeOverrides = { my };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Palette layer — raw, app-agnostic color scales.
|
|
3
|
+
*
|
|
4
|
+
* Values are Tailwind's published ramps: TWJS's palette already is Tailwind's
|
|
5
|
+
* and the web apps already use Tailwind utilities, so one ramp set serves both
|
|
6
|
+
* emitters. Themes reference these values; components never do.
|
|
7
|
+
*/
|
|
8
|
+
export declare const palette: {
|
|
9
|
+
readonly slate: {
|
|
10
|
+
readonly 50: '#f8fafc';
|
|
11
|
+
readonly 100: '#f1f5f9';
|
|
12
|
+
readonly 200: '#e2e8f0';
|
|
13
|
+
readonly 300: '#cbd5e1';
|
|
14
|
+
readonly 400: '#94a3b8';
|
|
15
|
+
readonly 500: '#64748b';
|
|
16
|
+
readonly 600: '#475569';
|
|
17
|
+
readonly 700: '#334155';
|
|
18
|
+
readonly 800: '#1e293b';
|
|
19
|
+
readonly 900: '#0f172a';
|
|
20
|
+
readonly 950: '#020617';
|
|
21
|
+
};
|
|
22
|
+
readonly stone: {
|
|
23
|
+
readonly 50: '#fafaf9';
|
|
24
|
+
readonly 100: '#f5f5f4';
|
|
25
|
+
readonly 200: '#e7e5e4';
|
|
26
|
+
readonly 300: '#d6d3d1';
|
|
27
|
+
readonly 400: '#a8a29e';
|
|
28
|
+
readonly 500: '#78716c';
|
|
29
|
+
readonly 600: '#57534e';
|
|
30
|
+
readonly 700: '#44403c';
|
|
31
|
+
readonly 800: '#292524';
|
|
32
|
+
readonly 900: '#1c1917';
|
|
33
|
+
readonly 950: '#0c0a09';
|
|
34
|
+
};
|
|
35
|
+
readonly blue: {
|
|
36
|
+
readonly 50: '#eff6ff';
|
|
37
|
+
readonly 100: '#dbeafe';
|
|
38
|
+
readonly 200: '#bfdbfe';
|
|
39
|
+
readonly 300: '#93c5fd';
|
|
40
|
+
readonly 400: '#60a5fa';
|
|
41
|
+
readonly 500: '#3b82f6';
|
|
42
|
+
readonly 600: '#2563eb';
|
|
43
|
+
readonly 700: '#1d4ed8';
|
|
44
|
+
readonly 800: '#1e40af';
|
|
45
|
+
readonly 900: '#1e3a8a';
|
|
46
|
+
readonly 950: '#172554';
|
|
47
|
+
};
|
|
48
|
+
readonly teal: {
|
|
49
|
+
readonly 50: '#f0fdfa';
|
|
50
|
+
readonly 100: '#ccfbf1';
|
|
51
|
+
readonly 200: '#99f6e4';
|
|
52
|
+
readonly 300: '#5eead4';
|
|
53
|
+
readonly 400: '#2dd4bf';
|
|
54
|
+
readonly 500: '#14b8a6';
|
|
55
|
+
readonly 600: '#0d9488';
|
|
56
|
+
readonly 700: '#0f766e';
|
|
57
|
+
readonly 800: '#115e59';
|
|
58
|
+
readonly 900: '#134e4a';
|
|
59
|
+
readonly 950: '#042f2e';
|
|
60
|
+
};
|
|
61
|
+
readonly indigo: {
|
|
62
|
+
readonly 50: '#eef2ff';
|
|
63
|
+
readonly 100: '#e0e7ff';
|
|
64
|
+
readonly 200: '#c7d2fe';
|
|
65
|
+
readonly 300: '#a5b4fc';
|
|
66
|
+
readonly 400: '#818cf8';
|
|
67
|
+
readonly 500: '#6366f1';
|
|
68
|
+
readonly 600: '#4f46e5';
|
|
69
|
+
readonly 700: '#4338ca';
|
|
70
|
+
readonly 800: '#3730a3';
|
|
71
|
+
readonly 900: '#312e81';
|
|
72
|
+
readonly 950: '#1e1b4b';
|
|
73
|
+
};
|
|
74
|
+
readonly emerald: {
|
|
75
|
+
readonly 50: '#ecfdf5';
|
|
76
|
+
readonly 100: '#d1fae5';
|
|
77
|
+
readonly 200: '#a7f3d0';
|
|
78
|
+
readonly 300: '#6ee7b7';
|
|
79
|
+
readonly 400: '#34d399';
|
|
80
|
+
readonly 500: '#10b981';
|
|
81
|
+
readonly 600: '#059669';
|
|
82
|
+
readonly 700: '#047857';
|
|
83
|
+
readonly 800: '#065f46';
|
|
84
|
+
readonly 900: '#064e3b';
|
|
85
|
+
readonly 950: '#022c22';
|
|
86
|
+
};
|
|
87
|
+
readonly amber: {
|
|
88
|
+
readonly 50: '#fffbeb';
|
|
89
|
+
readonly 100: '#fef3c7';
|
|
90
|
+
readonly 200: '#fde68a';
|
|
91
|
+
readonly 300: '#fcd34d';
|
|
92
|
+
readonly 400: '#fbbf24';
|
|
93
|
+
readonly 500: '#f59e0b';
|
|
94
|
+
readonly 600: '#d97706';
|
|
95
|
+
readonly 700: '#b45309';
|
|
96
|
+
readonly 800: '#92400e';
|
|
97
|
+
readonly 900: '#78350f';
|
|
98
|
+
readonly 950: '#451a03';
|
|
99
|
+
};
|
|
100
|
+
readonly red: {
|
|
101
|
+
readonly 50: '#fef2f2';
|
|
102
|
+
readonly 100: '#fee2e2';
|
|
103
|
+
readonly 200: '#fecaca';
|
|
104
|
+
readonly 300: '#fca5a5';
|
|
105
|
+
readonly 400: '#f87171';
|
|
106
|
+
readonly 500: '#ef4444';
|
|
107
|
+
readonly 600: '#dc2626';
|
|
108
|
+
readonly 700: '#b91c1c';
|
|
109
|
+
readonly 800: '#991b1b';
|
|
110
|
+
readonly 900: '#7f1d1d';
|
|
111
|
+
readonly 950: '#450a0a';
|
|
112
|
+
};
|
|
113
|
+
readonly sky: {
|
|
114
|
+
readonly 50: '#f0f9ff';
|
|
115
|
+
readonly 100: '#e0f2fe';
|
|
116
|
+
readonly 200: '#bae6fd';
|
|
117
|
+
readonly 300: '#7dd3fc';
|
|
118
|
+
readonly 400: '#38bdf8';
|
|
119
|
+
readonly 500: '#0ea5e9';
|
|
120
|
+
readonly 600: '#0284c7';
|
|
121
|
+
readonly 700: '#0369a1';
|
|
122
|
+
readonly 800: '#075985';
|
|
123
|
+
readonly 900: '#0c4a6e';
|
|
124
|
+
readonly 950: '#082f49';
|
|
125
|
+
};
|
|
126
|
+
readonly white: '#ffffff';
|
|
127
|
+
readonly black: '#000000';
|
|
128
|
+
readonly transparent: 'transparent';
|
|
129
|
+
};
|
|
130
|
+
export type Palette = typeof palette;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Palette layer — raw, app-agnostic color scales.
|
|
3
|
+
*
|
|
4
|
+
* Values are Tailwind's published ramps: TWJS's palette already is Tailwind's
|
|
5
|
+
* and the web apps already use Tailwind utilities, so one ramp set serves both
|
|
6
|
+
* emitters. Themes reference these values; components never do.
|
|
7
|
+
*/
|
|
8
|
+
export const palette = {
|
|
9
|
+
slate: {
|
|
10
|
+
50: '#f8fafc',
|
|
11
|
+
100: '#f1f5f9',
|
|
12
|
+
200: '#e2e8f0',
|
|
13
|
+
300: '#cbd5e1',
|
|
14
|
+
400: '#94a3b8',
|
|
15
|
+
500: '#64748b',
|
|
16
|
+
600: '#475569',
|
|
17
|
+
700: '#334155',
|
|
18
|
+
800: '#1e293b',
|
|
19
|
+
900: '#0f172a',
|
|
20
|
+
950: '#020617',
|
|
21
|
+
},
|
|
22
|
+
stone: {
|
|
23
|
+
50: '#fafaf9',
|
|
24
|
+
100: '#f5f5f4',
|
|
25
|
+
200: '#e7e5e4',
|
|
26
|
+
300: '#d6d3d1',
|
|
27
|
+
400: '#a8a29e',
|
|
28
|
+
500: '#78716c',
|
|
29
|
+
600: '#57534e',
|
|
30
|
+
700: '#44403c',
|
|
31
|
+
800: '#292524',
|
|
32
|
+
900: '#1c1917',
|
|
33
|
+
950: '#0c0a09',
|
|
34
|
+
},
|
|
35
|
+
blue: {
|
|
36
|
+
50: '#eff6ff',
|
|
37
|
+
100: '#dbeafe',
|
|
38
|
+
200: '#bfdbfe',
|
|
39
|
+
300: '#93c5fd',
|
|
40
|
+
400: '#60a5fa',
|
|
41
|
+
500: '#3b82f6',
|
|
42
|
+
600: '#2563eb',
|
|
43
|
+
700: '#1d4ed8',
|
|
44
|
+
800: '#1e40af',
|
|
45
|
+
900: '#1e3a8a',
|
|
46
|
+
950: '#172554',
|
|
47
|
+
},
|
|
48
|
+
teal: {
|
|
49
|
+
50: '#f0fdfa',
|
|
50
|
+
100: '#ccfbf1',
|
|
51
|
+
200: '#99f6e4',
|
|
52
|
+
300: '#5eead4',
|
|
53
|
+
400: '#2dd4bf',
|
|
54
|
+
500: '#14b8a6',
|
|
55
|
+
600: '#0d9488',
|
|
56
|
+
700: '#0f766e',
|
|
57
|
+
800: '#115e59',
|
|
58
|
+
900: '#134e4a',
|
|
59
|
+
950: '#042f2e',
|
|
60
|
+
},
|
|
61
|
+
indigo: {
|
|
62
|
+
50: '#eef2ff',
|
|
63
|
+
100: '#e0e7ff',
|
|
64
|
+
200: '#c7d2fe',
|
|
65
|
+
300: '#a5b4fc',
|
|
66
|
+
400: '#818cf8',
|
|
67
|
+
500: '#6366f1',
|
|
68
|
+
600: '#4f46e5',
|
|
69
|
+
700: '#4338ca',
|
|
70
|
+
800: '#3730a3',
|
|
71
|
+
900: '#312e81',
|
|
72
|
+
950: '#1e1b4b',
|
|
73
|
+
},
|
|
74
|
+
emerald: {
|
|
75
|
+
50: '#ecfdf5',
|
|
76
|
+
100: '#d1fae5',
|
|
77
|
+
200: '#a7f3d0',
|
|
78
|
+
300: '#6ee7b7',
|
|
79
|
+
400: '#34d399',
|
|
80
|
+
500: '#10b981',
|
|
81
|
+
600: '#059669',
|
|
82
|
+
700: '#047857',
|
|
83
|
+
800: '#065f46',
|
|
84
|
+
900: '#064e3b',
|
|
85
|
+
950: '#022c22',
|
|
86
|
+
},
|
|
87
|
+
amber: {
|
|
88
|
+
50: '#fffbeb',
|
|
89
|
+
100: '#fef3c7',
|
|
90
|
+
200: '#fde68a',
|
|
91
|
+
300: '#fcd34d',
|
|
92
|
+
400: '#fbbf24',
|
|
93
|
+
500: '#f59e0b',
|
|
94
|
+
600: '#d97706',
|
|
95
|
+
700: '#b45309',
|
|
96
|
+
800: '#92400e',
|
|
97
|
+
900: '#78350f',
|
|
98
|
+
950: '#451a03',
|
|
99
|
+
},
|
|
100
|
+
red: {
|
|
101
|
+
50: '#fef2f2',
|
|
102
|
+
100: '#fee2e2',
|
|
103
|
+
200: '#fecaca',
|
|
104
|
+
300: '#fca5a5',
|
|
105
|
+
400: '#f87171',
|
|
106
|
+
500: '#ef4444',
|
|
107
|
+
600: '#dc2626',
|
|
108
|
+
700: '#b91c1c',
|
|
109
|
+
800: '#991b1b',
|
|
110
|
+
900: '#7f1d1d',
|
|
111
|
+
950: '#450a0a',
|
|
112
|
+
},
|
|
113
|
+
sky: {
|
|
114
|
+
50: '#f0f9ff',
|
|
115
|
+
100: '#e0f2fe',
|
|
116
|
+
200: '#bae6fd',
|
|
117
|
+
300: '#7dd3fc',
|
|
118
|
+
400: '#38bdf8',
|
|
119
|
+
500: '#0ea5e9',
|
|
120
|
+
600: '#0284c7',
|
|
121
|
+
700: '#0369a1',
|
|
122
|
+
800: '#075985',
|
|
123
|
+
900: '#0c4a6e',
|
|
124
|
+
950: '#082f49',
|
|
125
|
+
},
|
|
126
|
+
white: '#ffffff',
|
|
127
|
+
black: '#000000',
|
|
128
|
+
transparent: 'transparent',
|
|
129
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type ThemeMode } from './semantic/contract.js';
|
|
2
|
+
/**
|
|
3
|
+
* Restyle emitter: builds the `createTheme` input object for
|
|
4
|
+
* @shopify/restyle consumers (TWJS / @jztack/ui-native) from the same token
|
|
5
|
+
* data the CSS emitter uses.
|
|
6
|
+
*
|
|
7
|
+
* During the twin transition the colors object carries BOTH the canonical
|
|
8
|
+
* contract keys and TWJS's legacy key aliases (DESIGN.md §3), so mobile-web
|
|
9
|
+
* code is not forced into a flag-day rename. Dead TWJS keys
|
|
10
|
+
* (successLight/warningLight/dangerLight, raw slate200/slate300 semantic
|
|
11
|
+
* leaks) are NOT re-emitted — they were dropped at the contract boundary.
|
|
12
|
+
*/
|
|
13
|
+
export interface RestyleTextVariant {
|
|
14
|
+
fontSize: number;
|
|
15
|
+
lineHeight: number;
|
|
16
|
+
fontWeight?: string;
|
|
17
|
+
color?: string;
|
|
18
|
+
textAlign?: 'center';
|
|
19
|
+
}
|
|
20
|
+
export interface RestyleThemeData {
|
|
21
|
+
colors: Record<string, string>;
|
|
22
|
+
spacing: Record<string, number>;
|
|
23
|
+
borderRadii: Record<string, number>;
|
|
24
|
+
breakpoints: Record<string, number>;
|
|
25
|
+
textVariants: Record<string, RestyleTextVariant>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Build the restyle theme object for a theme. `mode` defaults to the first
|
|
29
|
+
* mode the theme declares. Throws for an unknown theme or a mode the theme
|
|
30
|
+
* does not declare (e.g. a light mode for dark-only Tabbie).
|
|
31
|
+
*/
|
|
32
|
+
export declare function createThemeData(themeName: string, mode?: ThemeMode): RestyleThemeData;
|
|
33
|
+
/**
|
|
34
|
+
* Compose a locale override layer into a restyle theme — the counterpart of
|
|
35
|
+
* mobile-web's existing getThemeForLanguage(theme, lang). Unknown locales
|
|
36
|
+
* return the theme unchanged.
|
|
37
|
+
*/
|
|
38
|
+
export declare function getThemeForLocale<T extends RestyleThemeData>(theme: T, locale: string): T;
|
package/dist/restyle.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { localeOverrides } from './locale/my.js';
|
|
2
|
+
import { breakpoints, radii, spacing, typeRoles, } from './semantic/contract.js';
|
|
3
|
+
import { themes } from './themes/index.js';
|
|
4
|
+
/** Canonical color slot -> TWJS legacy key (DESIGN.md §3). */
|
|
5
|
+
const legacyColorAliases = {
|
|
6
|
+
background: 'mainBackground',
|
|
7
|
+
'background-secondary': 'secondaryBackground',
|
|
8
|
+
foreground: 'primaryText',
|
|
9
|
+
'foreground-secondary': 'secondaryText',
|
|
10
|
+
card: 'cardBackground',
|
|
11
|
+
primary: 'primaryButton',
|
|
12
|
+
'primary-foreground': 'primaryButtonText',
|
|
13
|
+
secondary: 'secondaryButton',
|
|
14
|
+
'secondary-foreground': 'secondaryButtonText',
|
|
15
|
+
accent: 'brand',
|
|
16
|
+
'accent-bg': 'brandBg',
|
|
17
|
+
'accent-border': 'brandBorder',
|
|
18
|
+
border: 'borderColor',
|
|
19
|
+
'border-strong': 'borderStrong',
|
|
20
|
+
'success-bg': 'successBg',
|
|
21
|
+
'success-foreground': 'successText',
|
|
22
|
+
'warning-bg': 'warningBg',
|
|
23
|
+
'warning-foreground': 'warningText',
|
|
24
|
+
'danger-bg': 'dangerBg',
|
|
25
|
+
'danger-foreground': 'dangerText',
|
|
26
|
+
'info-bg': 'infoBg',
|
|
27
|
+
'info-foreground': 'infoText',
|
|
28
|
+
};
|
|
29
|
+
/** Type-role color references, expressed in legacy restyle color keys. */
|
|
30
|
+
const legacyTypeColor = {
|
|
31
|
+
foreground: 'primaryText',
|
|
32
|
+
'foreground-secondary': 'secondaryText',
|
|
33
|
+
// TWJS's error variant points at its errorText key (= danger-foreground).
|
|
34
|
+
'danger-foreground': 'errorText',
|
|
35
|
+
};
|
|
36
|
+
const toCamel = (name) => name.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
37
|
+
function buildColors(themeName, mode, colors) {
|
|
38
|
+
const out = { ...colors };
|
|
39
|
+
for (const [slot, legacy] of Object.entries(legacyColorAliases)) {
|
|
40
|
+
out[legacy] = colors[slot];
|
|
41
|
+
}
|
|
42
|
+
// Legacy keys TWJS code uses that sit outside the canonical alias table:
|
|
43
|
+
// errorText/errorBackground are its danger-foreground/danger-bg pair.
|
|
44
|
+
out.errorText = colors['danger-foreground'];
|
|
45
|
+
out.errorBackground = colors['danger-bg'];
|
|
46
|
+
out.transparent = 'transparent';
|
|
47
|
+
// TWJS's dark theme flips its `pureWhite` semantic to slate-100.
|
|
48
|
+
out.pureWhite = mode === 'dark' && themeName === 'twjs' ? '#f1f5f9' : '#ffffff';
|
|
49
|
+
const extras = themes[themeName]?.restyleExtras?.[mode];
|
|
50
|
+
if (extras)
|
|
51
|
+
Object.assign(out, extras);
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
function buildSpacing() {
|
|
55
|
+
const out = { ...spacing };
|
|
56
|
+
// Negatives are generated by the emitter, never stored (DESIGN.md §3).
|
|
57
|
+
for (const [key, value] of Object.entries(spacing)) {
|
|
58
|
+
if (value > 0)
|
|
59
|
+
out[`-${key}`] = -value;
|
|
60
|
+
}
|
|
61
|
+
// Legacy component tokens TWJS still references; `sm` (12) is the value
|
|
62
|
+
// inputAccessoryInset always held, inputVertical (10) has no scale step.
|
|
63
|
+
out.inputVertical = 10;
|
|
64
|
+
out.inputAccessoryInset = spacing.sm;
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
function buildRadii() {
|
|
68
|
+
return {
|
|
69
|
+
// Canonical keys
|
|
70
|
+
...radii,
|
|
71
|
+
// Legacy restyle keys (TWJS: s 4, m 8, l 12, xl 20, none 0)
|
|
72
|
+
none: 0,
|
|
73
|
+
s: radii.sm,
|
|
74
|
+
m: radii.md,
|
|
75
|
+
l: radii.lg,
|
|
76
|
+
xl: radii['2xl'],
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function buildTextVariants() {
|
|
80
|
+
const out = {};
|
|
81
|
+
for (const [name, role] of Object.entries(typeRoles)) {
|
|
82
|
+
const variant = {
|
|
83
|
+
fontSize: role.fontSize,
|
|
84
|
+
lineHeight: role.lineHeight,
|
|
85
|
+
};
|
|
86
|
+
if (role.fontWeight !== undefined)
|
|
87
|
+
variant.fontWeight = role.fontWeight;
|
|
88
|
+
if (role.color !== undefined)
|
|
89
|
+
variant.color = legacyTypeColor[role.color];
|
|
90
|
+
if (role.textAlign !== undefined)
|
|
91
|
+
variant.textAlign = role.textAlign;
|
|
92
|
+
out[toCamel(name)] = variant;
|
|
93
|
+
}
|
|
94
|
+
return out;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Build the restyle theme object for a theme. `mode` defaults to the first
|
|
98
|
+
* mode the theme declares. Throws for an unknown theme or a mode the theme
|
|
99
|
+
* does not declare (e.g. a light mode for dark-only Tabbie).
|
|
100
|
+
*/
|
|
101
|
+
export function createThemeData(themeName, mode) {
|
|
102
|
+
const theme = themes[themeName];
|
|
103
|
+
if (!theme)
|
|
104
|
+
throw new Error(`@jztack/tokens: unknown theme "${themeName}"`);
|
|
105
|
+
const resolvedMode = mode ?? Object.keys(theme.modes)[0];
|
|
106
|
+
const colors = theme.modes[resolvedMode];
|
|
107
|
+
if (!colors) {
|
|
108
|
+
throw new Error(`@jztack/tokens: theme "${themeName}" has no "${resolvedMode}" mode`);
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
colors: buildColors(themeName, resolvedMode, colors),
|
|
112
|
+
spacing: buildSpacing(),
|
|
113
|
+
borderRadii: buildRadii(),
|
|
114
|
+
breakpoints: { ...breakpoints },
|
|
115
|
+
textVariants: buildTextVariants(),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Compose a locale override layer into a restyle theme — the counterpart of
|
|
120
|
+
* mobile-web's existing getThemeForLanguage(theme, lang). Unknown locales
|
|
121
|
+
* return the theme unchanged.
|
|
122
|
+
*/
|
|
123
|
+
export function getThemeForLocale(theme, locale) {
|
|
124
|
+
const override = localeOverrides[locale];
|
|
125
|
+
if (!override?.textVariants)
|
|
126
|
+
return theme;
|
|
127
|
+
const textVariants = { ...theme.textVariants };
|
|
128
|
+
for (const [name, partial] of Object.entries(override.textVariants)) {
|
|
129
|
+
const key = toCamel(name);
|
|
130
|
+
const base = textVariants[key];
|
|
131
|
+
if (!base || !partial)
|
|
132
|
+
continue;
|
|
133
|
+
textVariants[key] = {
|
|
134
|
+
...base,
|
|
135
|
+
...(partial.fontSize !== undefined ? { fontSize: partial.fontSize } : {}),
|
|
136
|
+
...(partial.lineHeight !== undefined ? { lineHeight: partial.lineHeight } : {}),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
return { ...theme, textVariants };
|
|
140
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The semantic contract — the fixed set of role names every theme must fill.
|
|
3
|
+
* Components reference ONLY this layer. A theme missing a slot is a type
|
|
4
|
+
* error (see ThemeDefinition), not a runtime surprise.
|
|
5
|
+
*/
|
|
6
|
+
/** Canonical color slots (shadcn naming convention). */
|
|
7
|
+
export declare const colorSlots: readonly ['background', 'background-secondary', 'foreground', 'foreground-secondary', 'card', 'card-foreground', 'popover', 'popover-foreground', 'primary', 'primary-foreground', 'secondary', 'secondary-foreground', 'muted', 'muted-foreground', 'accent', 'accent-bg', 'accent-border', 'accent-foreground', 'destructive', 'destructive-foreground', 'border', 'border-strong', 'input', 'ring', 'success', 'success-bg', 'success-foreground', 'warning', 'warning-bg', 'warning-foreground', 'danger', 'danger-bg', 'danger-foreground', 'info', 'info-bg', 'info-foreground'];
|
|
8
|
+
export type ColorSlot = (typeof colorSlots)[number];
|
|
9
|
+
/** A complete assignment of every color slot. Alpha values are first-class. */
|
|
10
|
+
export type ColorSet = Record<ColorSlot, string>;
|
|
11
|
+
/**
|
|
12
|
+
* Named 4pt spacing scale. This is TWJS's scale plus the two steps it was
|
|
13
|
+
* missing: `sm` 12 (which TWJS smuggled in as a component token) and `lg` 32.
|
|
14
|
+
* Negative values are an emitter concern and are never stored here.
|
|
15
|
+
*/
|
|
16
|
+
export declare const spacing: {
|
|
17
|
+
readonly none: 0;
|
|
18
|
+
readonly hairline: 1;
|
|
19
|
+
readonly xxs: 2;
|
|
20
|
+
readonly xs: 4;
|
|
21
|
+
readonly s: 8;
|
|
22
|
+
readonly sm: 12;
|
|
23
|
+
readonly m: 16;
|
|
24
|
+
readonly l: 24;
|
|
25
|
+
readonly lg: 32;
|
|
26
|
+
readonly xl: 40;
|
|
27
|
+
};
|
|
28
|
+
export type SpacingScale = typeof spacing;
|
|
29
|
+
export type SpacingKey = keyof SpacingScale;
|
|
30
|
+
/**
|
|
31
|
+
* Container scale — Tailwind v4's default `--container-*` values, verbatim
|
|
32
|
+
* (tailwindcss 4.3.5 theme.css). These are the stock meanings of the named
|
|
33
|
+
* sizes for the width utilities: `max-w-sm` is 24rem, not a spacing step.
|
|
34
|
+
*
|
|
35
|
+
* D1 (see DESIGN.md §3): the spacing scale above reuses four container
|
|
36
|
+
* names (`xs`, `sm`, `lg`, `xl`), and Tailwind resolves `max-w-*` /
|
|
37
|
+
* `w-*` / `min-w-*` against `--spacing` BEFORE `--container` — so the
|
|
38
|
+
* spacing keys shadowed the container scale. The CSS emitter therefore
|
|
39
|
+
* also emits this scale under the `--width-*`, `--min-width-*`, and
|
|
40
|
+
* `--max-width-*` namespaces, which those utilities resolve FIRST
|
|
41
|
+
* (verified in the installed tailwindcss source), restoring stock
|
|
42
|
+
* semantics without renaming any spacing key. The restyle/JS side never
|
|
43
|
+
* sees this scale: it is a CSS-resolution concern only.
|
|
44
|
+
*/
|
|
45
|
+
export declare const container: {
|
|
46
|
+
readonly '3xs': '16rem';
|
|
47
|
+
readonly '2xs': '18rem';
|
|
48
|
+
readonly xs: '20rem';
|
|
49
|
+
readonly sm: '24rem';
|
|
50
|
+
readonly md: '28rem';
|
|
51
|
+
readonly lg: '32rem';
|
|
52
|
+
readonly xl: '36rem';
|
|
53
|
+
readonly '2xl': '42rem';
|
|
54
|
+
readonly '3xl': '48rem';
|
|
55
|
+
readonly '4xl': '56rem';
|
|
56
|
+
readonly '5xl': '64rem';
|
|
57
|
+
readonly '6xl': '72rem';
|
|
58
|
+
readonly '7xl': '80rem';
|
|
59
|
+
};
|
|
60
|
+
export type ContainerScale = typeof container;
|
|
61
|
+
export type ContainerKey = keyof ContainerScale;
|
|
62
|
+
/** Radius scale (px). `full` is the pill radius. */
|
|
63
|
+
export declare const radii: {
|
|
64
|
+
readonly sm: 4;
|
|
65
|
+
readonly md: 8;
|
|
66
|
+
readonly lg: 12;
|
|
67
|
+
readonly xl: 16;
|
|
68
|
+
readonly '2xl': 20;
|
|
69
|
+
readonly full: 9999;
|
|
70
|
+
};
|
|
71
|
+
export type RadiiScale = typeof radii;
|
|
72
|
+
/** Breakpoints (px). `wide` doubles as the max container width. */
|
|
73
|
+
export declare const breakpoints: {
|
|
74
|
+
readonly phone: 0;
|
|
75
|
+
readonly tablet: 768;
|
|
76
|
+
readonly desktop: 1024;
|
|
77
|
+
readonly wide: 1440;
|
|
78
|
+
};
|
|
79
|
+
export type BreakpointScale = typeof breakpoints;
|
|
80
|
+
/** Color roles a type role may point at (a subset of the color contract). */
|
|
81
|
+
export type TypeColorRole = 'foreground' | 'foreground-secondary' | 'danger-foreground';
|
|
82
|
+
/** A composite type token: size + line-height + weight + color role. */
|
|
83
|
+
export interface TypeRole {
|
|
84
|
+
fontSize: number;
|
|
85
|
+
lineHeight: number;
|
|
86
|
+
fontWeight?: string;
|
|
87
|
+
color?: TypeColorRole;
|
|
88
|
+
textAlign?: 'center';
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Type roles, named by role not by size. This is TWJS's textVariants set
|
|
92
|
+
* adopted as canonical (it is the more complete one) — including `defaults`,
|
|
93
|
+
* which restyle requires as its base variant.
|
|
94
|
+
*/
|
|
95
|
+
export declare const typeRoleNames: readonly ['header', 'title', 'subtitle', 'body', 'body-strong', 'body-secondary', 'button', 'badge', 'error', 'kpi', 'caption', 'defaults'];
|
|
96
|
+
export type TypeRoleName = (typeof typeRoleNames)[number];
|
|
97
|
+
export type TypeRoles = Record<TypeRoleName, TypeRole>;
|
|
98
|
+
/** Canonical type roles — verbatim from TWJS theme.ts textVariants. */
|
|
99
|
+
export declare const typeRoles: TypeRoles;
|
|
100
|
+
/**
|
|
101
|
+
* Font family — a web-only token. The restyle emitter omits it: RN uses the
|
|
102
|
+
* platform font (TWJS has no family token today).
|
|
103
|
+
*/
|
|
104
|
+
export declare const fontFamily: {
|
|
105
|
+
readonly sans: '"Geist Variable", sans-serif';
|
|
106
|
+
};
|
|
107
|
+
export type ThemeMode = 'light' | 'dark';
|
|
108
|
+
/**
|
|
109
|
+
* One app theme: explicit per-mode value sets over the contract. Dark values
|
|
110
|
+
* are never derived by transform. `restyleExtras` carries restyle-only color
|
|
111
|
+
* keys that have no canonical slot (e.g. TWJS's brandBg/brandBorder) so the
|
|
112
|
+
* restyle emitter can keep emitting them during the twin transition.
|
|
113
|
+
*/
|
|
114
|
+
export interface ThemeDefinition {
|
|
115
|
+
readonly name: string;
|
|
116
|
+
readonly modes: Partial<Record<ThemeMode, ColorSet>>;
|
|
117
|
+
readonly restyleExtras?: Partial<Record<ThemeMode, Record<string, string>>>;
|
|
118
|
+
}
|