@und-ui/tokens 0.2.0 → 0.3.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/README.md +100 -11
- package/dist/android/values/und_colors.xml +204 -73
- package/dist/android/values/und_dimens.xml +15 -4
- package/dist/android/values-night/und_colors.xml +207 -76
- package/dist/css/base.css +610 -35
- package/dist/css/motion.css +129 -1
- package/dist/css/themes/butter.css +278 -0
- package/dist/css/themes/chocolate.css +255 -0
- package/dist/css/themes/gothic.css +710 -0
- package/dist/css/themes/kesar.css +1 -1
- package/dist/css/themes/matcha.css +291 -0
- package/dist/css/themes/mitti.css +1 -1
- package/dist/css/themes/nabh.css +179 -0
- package/dist/css/themes/neem.css +1 -1
- package/dist/css/themes/neutral.css +255 -0
- package/dist/css/themes/raat.css +35 -1
- package/dist/css/themes/stone.css +275 -0
- package/dist/css/themes/sutra.css +1 -1
- package/dist/css/themes/ujala.css +1 -1
- package/dist/css/themes/y2k.css +289 -0
- package/dist/css/tokens.css +2998 -1
- package/dist/dart/und_tokens.dart +11414 -320
- package/dist/js/contexts.js +1 -1
- package/dist/js/index.d.ts +583 -1
- package/dist/js/index.js +850 -157
- package/dist/json/flat/butter.dark.json +945 -0
- package/dist/json/flat/butter.darkMore.json +945 -0
- package/dist/json/flat/butter.light.json +945 -0
- package/dist/json/flat/butter.lightMore.json +945 -0
- package/dist/json/flat/chocolate.dark.json +945 -0
- package/dist/json/flat/chocolate.darkMore.json +945 -0
- package/dist/json/flat/chocolate.light.json +945 -0
- package/dist/json/flat/chocolate.lightMore.json +945 -0
- package/dist/json/flat/gothic.dark.json +945 -0
- package/dist/json/flat/gothic.darkMore.json +945 -0
- package/dist/json/flat/kesar.dark.json +207 -0
- package/dist/json/flat/kesar.darkMore.json +207 -0
- package/dist/json/flat/kesar.light.json +207 -0
- package/dist/json/flat/kesar.lightMore.json +207 -0
- package/dist/json/flat/matcha.dark.json +945 -0
- package/dist/json/flat/matcha.darkMore.json +945 -0
- package/dist/json/flat/matcha.light.json +945 -0
- package/dist/json/flat/matcha.lightMore.json +945 -0
- package/dist/json/flat/mitti.dark.json +207 -0
- package/dist/json/flat/mitti.darkMore.json +207 -0
- package/dist/json/flat/mitti.light.json +207 -0
- package/dist/json/flat/mitti.lightMore.json +207 -0
- package/dist/json/flat/nabh.dark.json +945 -0
- package/dist/json/flat/nabh.darkMore.json +945 -0
- package/dist/json/flat/nabh.light.json +945 -0
- package/dist/json/flat/nabh.lightMore.json +945 -0
- package/dist/json/flat/neem.dark.json +207 -0
- package/dist/json/flat/neem.darkMore.json +207 -0
- package/dist/json/flat/neem.light.json +207 -0
- package/dist/json/flat/neem.lightMore.json +207 -0
- package/dist/json/flat/neutral.dark.json +945 -0
- package/dist/json/flat/neutral.darkMore.json +945 -0
- package/dist/json/flat/neutral.light.json +945 -0
- package/dist/json/flat/neutral.lightMore.json +945 -0
- package/dist/json/flat/raat.dark.json +207 -0
- package/dist/json/flat/raat.darkMore.json +207 -0
- package/dist/json/flat/stone.dark.json +945 -0
- package/dist/json/flat/stone.darkMore.json +945 -0
- package/dist/json/flat/stone.light.json +945 -0
- package/dist/json/flat/stone.lightMore.json +945 -0
- package/dist/json/flat/sutra.dark.json +207 -0
- package/dist/json/flat/sutra.darkMore.json +207 -0
- package/dist/json/flat/sutra.light.json +207 -0
- package/dist/json/flat/sutra.lightMore.json +207 -0
- package/dist/json/flat/ujala.dark.json +207 -0
- package/dist/json/flat/ujala.darkMore.json +207 -0
- package/dist/json/flat/ujala.light.json +207 -0
- package/dist/json/flat/ujala.lightMore.json +207 -0
- package/dist/json/flat/y2k.dark.json +945 -0
- package/dist/json/flat/y2k.darkMore.json +945 -0
- package/dist/json/flat/y2k.light.json +945 -0
- package/dist/json/flat/y2k.lightMore.json +945 -0
- package/dist/json/nested/butter.dark.json +1177 -0
- package/dist/json/nested/butter.darkMore.json +1177 -0
- package/dist/json/nested/butter.light.json +1177 -0
- package/dist/json/nested/butter.lightMore.json +1177 -0
- package/dist/json/nested/chocolate.dark.json +1177 -0
- package/dist/json/nested/chocolate.darkMore.json +1177 -0
- package/dist/json/nested/chocolate.light.json +1177 -0
- package/dist/json/nested/chocolate.lightMore.json +1177 -0
- package/dist/json/nested/gothic.dark.json +1177 -0
- package/dist/json/nested/gothic.darkMore.json +1177 -0
- package/dist/json/nested/kesar.dark.json +295 -4
- package/dist/json/nested/kesar.darkMore.json +295 -4
- package/dist/json/nested/kesar.light.json +295 -4
- package/dist/json/nested/kesar.lightMore.json +295 -4
- package/dist/json/nested/matcha.dark.json +1177 -0
- package/dist/json/nested/matcha.darkMore.json +1177 -0
- package/dist/json/nested/matcha.light.json +1177 -0
- package/dist/json/nested/matcha.lightMore.json +1177 -0
- package/dist/json/nested/mitti.dark.json +295 -4
- package/dist/json/nested/mitti.darkMore.json +295 -4
- package/dist/json/nested/mitti.light.json +295 -4
- package/dist/json/nested/mitti.lightMore.json +295 -4
- package/dist/json/nested/nabh.dark.json +1177 -0
- package/dist/json/nested/nabh.darkMore.json +1177 -0
- package/dist/json/nested/nabh.light.json +1177 -0
- package/dist/json/nested/nabh.lightMore.json +1177 -0
- package/dist/json/nested/neem.dark.json +295 -4
- package/dist/json/nested/neem.darkMore.json +295 -4
- package/dist/json/nested/neem.light.json +295 -4
- package/dist/json/nested/neem.lightMore.json +295 -4
- package/dist/json/nested/neutral.dark.json +1177 -0
- package/dist/json/nested/neutral.darkMore.json +1177 -0
- package/dist/json/nested/neutral.light.json +1177 -0
- package/dist/json/nested/neutral.lightMore.json +1177 -0
- package/dist/json/nested/raat.dark.json +295 -4
- package/dist/json/nested/raat.darkMore.json +295 -4
- package/dist/json/nested/stone.dark.json +1177 -0
- package/dist/json/nested/stone.darkMore.json +1177 -0
- package/dist/json/nested/stone.light.json +1177 -0
- package/dist/json/nested/stone.lightMore.json +1177 -0
- package/dist/json/nested/sutra.dark.json +295 -4
- package/dist/json/nested/sutra.darkMore.json +295 -4
- package/dist/json/nested/sutra.light.json +295 -4
- package/dist/json/nested/sutra.lightMore.json +295 -4
- package/dist/json/nested/ujala.dark.json +295 -4
- package/dist/json/nested/ujala.darkMore.json +295 -4
- package/dist/json/nested/ujala.light.json +295 -4
- package/dist/json/nested/ujala.lightMore.json +295 -4
- package/dist/json/nested/y2k.dark.json +1177 -0
- package/dist/json/nested/y2k.darkMore.json +1177 -0
- package/dist/json/nested/y2k.light.json +1177 -0
- package/dist/json/nested/y2k.lightMore.json +1177 -0
- package/dist/kotlin/UndTokens.kt +15338 -2190
- package/dist/lib/build/formats/css.d.ts +7 -0
- package/dist/lib/build/formats/css.js +113 -3
- package/dist/lib/build/formats/dart.d.ts +0 -7
- package/dist/lib/build/formats/dart.js +22 -4
- package/dist/lib/build/formats/js.d.ts +0 -6
- package/dist/lib/build/formats/js.js +8 -1
- package/dist/lib/build/formats/kotlin.d.ts +1 -1
- package/dist/lib/build/formats/kotlin.js +43 -14
- package/dist/lib/build/formats/react-native.js +2 -1
- package/dist/lib/build/formats/swift.d.ts +0 -6
- package/dist/lib/build/formats/swift.js +78 -15
- package/dist/lib/build/formats/tailwind.js +22 -2
- package/dist/lib/build/index.js +6 -5
- package/dist/lib/build/native-model.d.ts +16 -0
- package/dist/lib/build/native-model.js +33 -0
- package/dist/lib/color/pairs.js +2 -1
- package/dist/lib/dtcg/engine.d.ts +6 -0
- package/dist/lib/dtcg/engine.js +21 -1
- package/dist/lib/source/generate.d.ts +3 -1
- package/dist/lib/source/generate.js +56 -7
- package/dist/lib/themes/aa.d.ts +44 -0
- package/dist/lib/themes/aa.js +168 -0
- package/dist/lib/themes/definitions.d.ts +21 -10
- package/dist/lib/themes/definitions.js +181 -5
- package/dist/lib/themes/generate.d.ts +47 -0
- package/dist/lib/themes/generate.js +329 -0
- package/dist/lib/themes/ported-map.d.ts +59 -0
- package/dist/lib/themes/ported-map.js +618 -0
- package/dist/lib/themes/ported.d.ts +10 -0
- package/dist/lib/themes/ported.js +1764 -0
- package/dist/react-native/index.d.ts +132 -1
- package/dist/react-native/tokens.js +16487 -1656
- package/dist/scss/_variables.scss +346 -138
- package/dist/scss/_vars.scss +208 -1
- package/dist/scss/butter.dark.scss +946 -0
- package/dist/scss/butter.darkMore.scss +946 -0
- package/dist/scss/butter.light.scss +946 -0
- package/dist/scss/butter.lightMore.scss +946 -0
- package/dist/scss/chocolate.dark.scss +946 -0
- package/dist/scss/chocolate.darkMore.scss +946 -0
- package/dist/scss/chocolate.light.scss +946 -0
- package/dist/scss/chocolate.lightMore.scss +946 -0
- package/dist/scss/gothic.dark.scss +946 -0
- package/dist/scss/gothic.darkMore.scss +946 -0
- package/dist/scss/kesar.dark.scss +207 -0
- package/dist/scss/kesar.darkMore.scss +207 -0
- package/dist/scss/kesar.light.scss +207 -0
- package/dist/scss/kesar.lightMore.scss +207 -0
- package/dist/scss/matcha.dark.scss +946 -0
- package/dist/scss/matcha.darkMore.scss +946 -0
- package/dist/scss/matcha.light.scss +946 -0
- package/dist/scss/matcha.lightMore.scss +946 -0
- package/dist/scss/mitti.dark.scss +207 -0
- package/dist/scss/mitti.darkMore.scss +207 -0
- package/dist/scss/mitti.light.scss +207 -0
- package/dist/scss/mitti.lightMore.scss +207 -0
- package/dist/scss/nabh.dark.scss +946 -0
- package/dist/scss/nabh.darkMore.scss +946 -0
- package/dist/scss/nabh.light.scss +946 -0
- package/dist/scss/nabh.lightMore.scss +946 -0
- package/dist/scss/neem.dark.scss +207 -0
- package/dist/scss/neem.darkMore.scss +207 -0
- package/dist/scss/neem.light.scss +207 -0
- package/dist/scss/neem.lightMore.scss +207 -0
- package/dist/scss/neutral.dark.scss +946 -0
- package/dist/scss/neutral.darkMore.scss +946 -0
- package/dist/scss/neutral.light.scss +946 -0
- package/dist/scss/neutral.lightMore.scss +946 -0
- package/dist/scss/raat.dark.scss +207 -0
- package/dist/scss/raat.darkMore.scss +207 -0
- package/dist/scss/stone.dark.scss +946 -0
- package/dist/scss/stone.darkMore.scss +946 -0
- package/dist/scss/stone.light.scss +946 -0
- package/dist/scss/stone.lightMore.scss +946 -0
- package/dist/scss/sutra.dark.scss +207 -0
- package/dist/scss/sutra.darkMore.scss +207 -0
- package/dist/scss/sutra.light.scss +207 -0
- package/dist/scss/sutra.lightMore.scss +207 -0
- package/dist/scss/ujala.dark.scss +207 -0
- package/dist/scss/ujala.darkMore.scss +207 -0
- package/dist/scss/ujala.light.scss +207 -0
- package/dist/scss/ujala.lightMore.scss +207 -0
- package/dist/scss/y2k.dark.scss +946 -0
- package/dist/scss/y2k.darkMore.scss +946 -0
- package/dist/scss/y2k.light.scss +946 -0
- package/dist/scss/y2k.lightMore.scss +946 -0
- package/dist/swift/UndTokens.swift +6061 -3432
- package/dist/tailwind/und.css +198 -2
- package/package.json +5 -1
- package/tokens/modes/dark.tokens.json +241 -0
- package/tokens/modes/light.tokens.json +246 -0
- package/tokens/palettes/butter.dark.tokens.json +887 -0
- package/tokens/palettes/butter.light.tokens.json +872 -0
- package/tokens/palettes/chocolate.dark.tokens.json +917 -0
- package/tokens/palettes/chocolate.light.tokens.json +902 -0
- package/tokens/palettes/gothic.dark.tokens.json +831 -0
- package/tokens/palettes/matcha.dark.tokens.json +932 -0
- package/tokens/palettes/matcha.light.tokens.json +907 -0
- package/tokens/palettes/nabh.dark.tokens.json +498 -0
- package/tokens/palettes/nabh.light.tokens.json +498 -0
- package/tokens/palettes/neutral.dark.tokens.json +837 -0
- package/tokens/palettes/neutral.light.tokens.json +817 -0
- package/tokens/palettes/stone.dark.tokens.json +877 -0
- package/tokens/palettes/stone.light.tokens.json +877 -0
- package/tokens/palettes/y2k.dark.tokens.json +877 -0
- package/tokens/palettes/y2k.light.tokens.json +877 -0
- package/tokens/semantic/roles.tokens.json +521 -0
- package/tokens/themes/butter.tokens.json +254 -0
- package/tokens/themes/chocolate.tokens.json +214 -0
- package/tokens/themes/gothic.tokens.json +249 -0
- package/tokens/themes/matcha.tokens.json +258 -0
- package/tokens/themes/nabh.tokens.json +174 -0
- package/tokens/themes/neutral.tokens.json +234 -0
- package/tokens/themes/stone.tokens.json +254 -0
- package/tokens/themes/ujala.tokens.json +1 -1
- package/tokens/themes/y2k.tokens.json +264 -0
- package/tokens/und.resolver.json +40 -4
|
@@ -0,0 +1,618 @@
|
|
|
1
|
+
/* Visual design ported from Astryx (MIT, (c) Meta Platforms, Inc.); see THIRD_PARTY_NOTICES.md */
|
|
2
|
+
/**
|
|
3
|
+
* How the ported source values (src/themes/ported.ts, keyed by their original
|
|
4
|
+
* custom property names) land on UND token paths, plus the base definitions of
|
|
5
|
+
* the roles UND did not have before (bg.card, icon.*, tone.*, data.*, syntax.*,
|
|
6
|
+
* type.*, font-size.*, radius.element ...).
|
|
7
|
+
*
|
|
8
|
+
* - Roles UND already had take the ported value in palette themes (an alias):
|
|
9
|
+
* `background-body` is `bg.canvas`, `text-secondary` is `fg.muted`, and so on.
|
|
10
|
+
* - New roles are defined once in the base layer with the default theme's values
|
|
11
|
+
* (tokens/semantic/roles.tokens.json for mode-independent ones, tokens/modes/*
|
|
12
|
+
* for per-mode ones) and overridden by palette themes.
|
|
13
|
+
* - Roles UND has but the source has not (fg.subtle, border.control, accent.fg-strong,
|
|
14
|
+
* hover steps ...) keep their scale-based definition, or are derived here with the
|
|
15
|
+
* same arithmetic the source components use (`color-mix(... tint-hover 15%)`).
|
|
16
|
+
*/
|
|
17
|
+
import { hexToRgb, oklchToHex, rgbToHex } from '../color/convert.js';
|
|
18
|
+
import { contrast, mix, over, repairPalette } from './aa.js';
|
|
19
|
+
import { PORTED } from './ported.js';
|
|
20
|
+
const round4 = (n) => Math.round(n * 10000) / 10000;
|
|
21
|
+
/** Parses the colour syntaxes used by the source CSS: hex, rgb()/rgba(), oklch(), keywords. */
|
|
22
|
+
export function parseCssColor(input) {
|
|
23
|
+
const s = input.trim().toLowerCase();
|
|
24
|
+
if (s === 'transparent')
|
|
25
|
+
return { r: 0, g: 0, b: 0, a: 0 };
|
|
26
|
+
if (s === 'black')
|
|
27
|
+
return { r: 0, g: 0, b: 0, a: 1 };
|
|
28
|
+
if (s === 'white')
|
|
29
|
+
return { r: 1, g: 1, b: 1, a: 1 };
|
|
30
|
+
let m = /^#([0-9a-f]{3,8})$/.exec(s);
|
|
31
|
+
if (m) {
|
|
32
|
+
let h = m[1];
|
|
33
|
+
if (h.length <= 4)
|
|
34
|
+
h = h
|
|
35
|
+
.split('')
|
|
36
|
+
.map((c) => c + c)
|
|
37
|
+
.join('');
|
|
38
|
+
const a = h.length === 8 ? parseInt(h.slice(6, 8), 16) / 255 : 1;
|
|
39
|
+
const [r, g, b] = hexToRgb(`#${h.slice(0, 6)}`);
|
|
40
|
+
return { r, g, b, a };
|
|
41
|
+
}
|
|
42
|
+
m = /^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:\s*[,/]\s*([\d.]+%?))?\s*\)$/.exec(s);
|
|
43
|
+
if (m) {
|
|
44
|
+
const a = m[4] === undefined ? 1 : m[4].endsWith('%') ? parseFloat(m[4]) / 100 : +m[4];
|
|
45
|
+
return { r: +m[1] / 255, g: +m[2] / 255, b: +m[3] / 255, a };
|
|
46
|
+
}
|
|
47
|
+
m = /^oklch\(\s*([\d.]+%?)\s+([\d.]+)\s+([\d.]+)(?:\s*\/\s*([\d.]+%?))?\s*\)$/.exec(s);
|
|
48
|
+
if (m) {
|
|
49
|
+
const l = m[1].endsWith('%') ? parseFloat(m[1]) / 100 : +m[1];
|
|
50
|
+
const hex = oklchToHex({ l, c: +m[2], h: +m[3] });
|
|
51
|
+
const [r, g, b] = hexToRgb(hex);
|
|
52
|
+
const a = m[4] === undefined ? 1 : m[4].endsWith('%') ? parseFloat(m[4]) / 100 : +m[4];
|
|
53
|
+
return { r, g, b, a };
|
|
54
|
+
}
|
|
55
|
+
throw new Error(`Unsupported colour "${input}"`);
|
|
56
|
+
}
|
|
57
|
+
export const hexOfRgba = (c) => rgbToHex([c.r, c.g, c.b]);
|
|
58
|
+
/** DTCG sRGB colour value. */
|
|
59
|
+
export function colorValue(c) {
|
|
60
|
+
const hex = hexOfRgba(c);
|
|
61
|
+
const [r, g, b] = hexToRgb(hex);
|
|
62
|
+
const a = Math.round(c.a * 1000) / 1000;
|
|
63
|
+
return {
|
|
64
|
+
colorSpace: 'srgb',
|
|
65
|
+
components: [round4(r), round4(g), round4(b)],
|
|
66
|
+
...(a < 1 ? { alpha: a } : {}),
|
|
67
|
+
hex,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export { mix, over };
|
|
71
|
+
// ---------------------------------------------------------------- shadows
|
|
72
|
+
const px = (v) => ({ value: v, unit: 'px' });
|
|
73
|
+
function splitTop(s) {
|
|
74
|
+
const out = [];
|
|
75
|
+
let depth = 0;
|
|
76
|
+
let cur = '';
|
|
77
|
+
for (const ch of s) {
|
|
78
|
+
if (ch === '(')
|
|
79
|
+
depth++;
|
|
80
|
+
if (ch === ')')
|
|
81
|
+
depth--;
|
|
82
|
+
if (ch === ',' && depth === 0) {
|
|
83
|
+
out.push(cur.trim());
|
|
84
|
+
cur = '';
|
|
85
|
+
}
|
|
86
|
+
else
|
|
87
|
+
cur += ch;
|
|
88
|
+
}
|
|
89
|
+
if (cur.trim())
|
|
90
|
+
out.push(cur.trim());
|
|
91
|
+
return out;
|
|
92
|
+
}
|
|
93
|
+
/** Parses a CSS box-shadow list into DTCG shadow layers. */
|
|
94
|
+
export function parseShadow(css) {
|
|
95
|
+
return splitTop(css).map((layer) => {
|
|
96
|
+
let rest = layer.trim();
|
|
97
|
+
const inset = rest.startsWith('inset ');
|
|
98
|
+
if (inset)
|
|
99
|
+
rest = rest.slice(6).trim();
|
|
100
|
+
const lengths = [];
|
|
101
|
+
while (true) {
|
|
102
|
+
const m = /^(-?[\d.]+)(px)?(\s+|$)/.exec(rest);
|
|
103
|
+
if (!m)
|
|
104
|
+
break;
|
|
105
|
+
lengths.push(+m[1]);
|
|
106
|
+
rest = rest.slice(m[0].length);
|
|
107
|
+
}
|
|
108
|
+
const [x = 0, y = 0, blur = 0, spread = 0] = lengths;
|
|
109
|
+
return {
|
|
110
|
+
color: colorValue(parseCssColor(rest)),
|
|
111
|
+
offsetX: px(x),
|
|
112
|
+
offsetY: px(y),
|
|
113
|
+
blur: px(blur),
|
|
114
|
+
spread: px(spread),
|
|
115
|
+
...(inset ? { inset: true } : {}),
|
|
116
|
+
};
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
// ---------------------------------------------------------------- mapping tables
|
|
120
|
+
export const STATUS_MAP = { info: 'info', success: 'success', warning: 'warning', error: 'danger' };
|
|
121
|
+
export const TONES = [
|
|
122
|
+
'blue',
|
|
123
|
+
'cyan',
|
|
124
|
+
'gray',
|
|
125
|
+
'green',
|
|
126
|
+
'orange',
|
|
127
|
+
'pink',
|
|
128
|
+
'purple',
|
|
129
|
+
'red',
|
|
130
|
+
'teal',
|
|
131
|
+
'yellow',
|
|
132
|
+
];
|
|
133
|
+
export const DATA_CATEGORICAL = [
|
|
134
|
+
'blue',
|
|
135
|
+
'orange',
|
|
136
|
+
'purple',
|
|
137
|
+
'green',
|
|
138
|
+
'pink',
|
|
139
|
+
'cyan',
|
|
140
|
+
'red',
|
|
141
|
+
'teal',
|
|
142
|
+
'brown',
|
|
143
|
+
'indigo',
|
|
144
|
+
];
|
|
145
|
+
export const DATA_RAMPS = [
|
|
146
|
+
'blue',
|
|
147
|
+
'shamrock',
|
|
148
|
+
'orange',
|
|
149
|
+
'pink',
|
|
150
|
+
'purple',
|
|
151
|
+
'red',
|
|
152
|
+
'teal',
|
|
153
|
+
'yellow',
|
|
154
|
+
'gray',
|
|
155
|
+
];
|
|
156
|
+
export const SYNTAX_ROLES = [
|
|
157
|
+
'keyword',
|
|
158
|
+
'string',
|
|
159
|
+
'comment',
|
|
160
|
+
'number',
|
|
161
|
+
'function',
|
|
162
|
+
'type',
|
|
163
|
+
'variable',
|
|
164
|
+
'operator',
|
|
165
|
+
'constant',
|
|
166
|
+
'tag',
|
|
167
|
+
'attribute',
|
|
168
|
+
'property',
|
|
169
|
+
'punctuation',
|
|
170
|
+
'background',
|
|
171
|
+
];
|
|
172
|
+
export const FONT_SIZES = [
|
|
173
|
+
'4xs',
|
|
174
|
+
'3xs',
|
|
175
|
+
'2xs',
|
|
176
|
+
'xs',
|
|
177
|
+
'sm',
|
|
178
|
+
'base',
|
|
179
|
+
'lg',
|
|
180
|
+
'xl',
|
|
181
|
+
'2xl',
|
|
182
|
+
'3xl',
|
|
183
|
+
'4xl',
|
|
184
|
+
'5xl',
|
|
185
|
+
];
|
|
186
|
+
export const TYPE_ROLES = [
|
|
187
|
+
'heading-1',
|
|
188
|
+
'heading-2',
|
|
189
|
+
'heading-3',
|
|
190
|
+
'heading-4',
|
|
191
|
+
'heading-5',
|
|
192
|
+
'heading-6',
|
|
193
|
+
'display-1',
|
|
194
|
+
'display-2',
|
|
195
|
+
'display-3',
|
|
196
|
+
'body',
|
|
197
|
+
'large',
|
|
198
|
+
'label',
|
|
199
|
+
'code',
|
|
200
|
+
'supporting',
|
|
201
|
+
];
|
|
202
|
+
export const SPACING = [
|
|
203
|
+
'0',
|
|
204
|
+
'0-5',
|
|
205
|
+
'1',
|
|
206
|
+
'1-5',
|
|
207
|
+
'2',
|
|
208
|
+
'3',
|
|
209
|
+
'4',
|
|
210
|
+
'5',
|
|
211
|
+
'6',
|
|
212
|
+
'7',
|
|
213
|
+
'8',
|
|
214
|
+
'9',
|
|
215
|
+
'10',
|
|
216
|
+
'11',
|
|
217
|
+
'12',
|
|
218
|
+
];
|
|
219
|
+
const DURATIONS = [
|
|
220
|
+
'fast-min',
|
|
221
|
+
'fast',
|
|
222
|
+
'fast-max',
|
|
223
|
+
'medium-min',
|
|
224
|
+
'medium',
|
|
225
|
+
'medium-max',
|
|
226
|
+
'slow-min',
|
|
227
|
+
'slow',
|
|
228
|
+
'slow-max',
|
|
229
|
+
];
|
|
230
|
+
/** Source colour key -> UND paths. Roles UND already had are aliases; the rest are new. */
|
|
231
|
+
export const COLOR_MAP = [
|
|
232
|
+
['color-background-body', ['bg.canvas']],
|
|
233
|
+
['color-background-surface', ['bg.surface']],
|
|
234
|
+
['color-background-card', ['bg.card']],
|
|
235
|
+
['color-background-popover', ['bg.raised']],
|
|
236
|
+
['color-background-muted', ['bg.subtle']],
|
|
237
|
+
['color-neutral', ['bg.muted']],
|
|
238
|
+
['color-overlay', ['bg.overlay']],
|
|
239
|
+
['color-overlay-hover', ['bg.hover']],
|
|
240
|
+
['color-overlay-pressed', ['bg.pressed']],
|
|
241
|
+
['color-background-inverted', ['bg.inverse']],
|
|
242
|
+
['color-background-error-inverted', ['bg.inverse-danger']],
|
|
243
|
+
['color-skeleton', ['bg.skeleton']],
|
|
244
|
+
['color-track', ['bg.track']],
|
|
245
|
+
['color-text-primary', ['fg.default']],
|
|
246
|
+
['color-text-secondary', ['fg.muted']],
|
|
247
|
+
['color-text-disabled', ['fg.disabled']],
|
|
248
|
+
['color-on-accent', ['fg.on-accent']],
|
|
249
|
+
['color-on-dark', ['fg.on-dark']],
|
|
250
|
+
['color-on-light', ['fg.on-light']],
|
|
251
|
+
['color-icon-primary', ['icon.default']],
|
|
252
|
+
['color-icon-secondary', ['icon.muted']],
|
|
253
|
+
['color-icon-disabled', ['icon.disabled']],
|
|
254
|
+
['color-icon-accent', ['icon.accent']],
|
|
255
|
+
['color-border', ['border.subtle']],
|
|
256
|
+
['color-border-emphasized', ['border.default']],
|
|
257
|
+
['color-accent', ['accent.solid']],
|
|
258
|
+
['color-accent-muted', ['accent.bg']],
|
|
259
|
+
['color-text-accent', ['accent.fg', 'link.default']],
|
|
260
|
+
['color-tint-hover', ['tint.hover']],
|
|
261
|
+
['color-shadow', ['elevation.shadow-color']],
|
|
262
|
+
...Object.entries(STATUS_MAP).flatMap(([src, s]) => [
|
|
263
|
+
[`color-${src}`, [`status.${s}.solid`]],
|
|
264
|
+
[`color-${src}-muted`, [`status.${s}.bg`]],
|
|
265
|
+
[`color-on-${src}`, [`status.${s}.on-solid`]],
|
|
266
|
+
[`color-text-${src}`, [`status.${s}.fg`]],
|
|
267
|
+
[`color-on-${src}-muted`, [`status.${s}.fg-strong`]],
|
|
268
|
+
[`color-icon-${src}`, [`status.${s}.icon`]],
|
|
269
|
+
[`color-border-${src}`, [`status.${s}.border`]],
|
|
270
|
+
]),
|
|
271
|
+
...TONES.flatMap((h) => [
|
|
272
|
+
[`color-background-${h}`, [`tone.${h}.bg`]],
|
|
273
|
+
[`color-border-${h}`, [`tone.${h}.border`]],
|
|
274
|
+
[`color-icon-${h}`, [`tone.${h}.icon`]],
|
|
275
|
+
[`color-text-${h}`, [`tone.${h}.fg`]],
|
|
276
|
+
]),
|
|
277
|
+
...DATA_CATEGORICAL.map((h) => [`color-data-categorical-${h}`, [`data.categorical.${h}`]]),
|
|
278
|
+
['color-data-neutral', ['data.neutral']],
|
|
279
|
+
...DATA_RAMPS.flatMap((r) => [1, 2, 3, 4, 5].map((n) => [`color-data-${r}-${n}`, [`data.${r}.${n}`]])),
|
|
280
|
+
...SYNTAX_ROLES.map((r) => [`color-syntax-${r}`, [`syntax.${r}`]]),
|
|
281
|
+
];
|
|
282
|
+
/** Shadow source key -> UND path. Elevations 4 and 5 reuse `high`. */
|
|
283
|
+
export const SHADOW_MAP = [
|
|
284
|
+
['shadow-low', ['shadow.1']],
|
|
285
|
+
['shadow-med', ['shadow.2']],
|
|
286
|
+
['shadow-high', ['shadow.3', 'shadow.4', 'shadow.5']],
|
|
287
|
+
['shadow-inset-hover', ['shadow.inset-hover']],
|
|
288
|
+
['shadow-inset-selected', ['shadow.inset-selected']],
|
|
289
|
+
['shadow-inset-success', ['shadow.inset-success']],
|
|
290
|
+
['shadow-inset-warning', ['shadow.inset-warning']],
|
|
291
|
+
['shadow-inset-error', ['shadow.inset-error']],
|
|
292
|
+
];
|
|
293
|
+
/** Paths that are new in this release (their base value is the default theme's value). */
|
|
294
|
+
export function isNewRole(path) {
|
|
295
|
+
return (/^(icon|tone|data|syntax|tint)\./.test(path) ||
|
|
296
|
+
/^status\.[a-z]+\.icon$/.test(path) ||
|
|
297
|
+
[
|
|
298
|
+
'bg.card',
|
|
299
|
+
'bg.hover',
|
|
300
|
+
'bg.pressed',
|
|
301
|
+
'bg.inverse-danger',
|
|
302
|
+
'bg.skeleton',
|
|
303
|
+
'bg.track',
|
|
304
|
+
'fg.on-dark',
|
|
305
|
+
'fg.on-light',
|
|
306
|
+
'elevation.shadow-color',
|
|
307
|
+
].includes(path) ||
|
|
308
|
+
/^shadow\.inset-/.test(path));
|
|
309
|
+
}
|
|
310
|
+
// ---------------------------------------------------------------- value access
|
|
311
|
+
export function sideOf(v, mode) {
|
|
312
|
+
return typeof v === 'string' ? v : mode === 'light' ? v[0] : v[1];
|
|
313
|
+
}
|
|
314
|
+
/** A theme's own value, falling back to the default look (as the source themes do). */
|
|
315
|
+
export function portedValue(theme, key, mode) {
|
|
316
|
+
const own = PORTED[theme]?.[key];
|
|
317
|
+
const v = own ?? PORTED.default[key];
|
|
318
|
+
return v === undefined ? undefined : sideOf(v, mode);
|
|
319
|
+
}
|
|
320
|
+
export function ownsKey(theme, key) {
|
|
321
|
+
return theme === 'default' || PORTED[theme]?.[key] !== undefined;
|
|
322
|
+
}
|
|
323
|
+
// ---------------------------------------------------------------- base layer (new roles)
|
|
324
|
+
const ref = (p) => `{${p}}`;
|
|
325
|
+
const tok = (type, value, description) => ({
|
|
326
|
+
$type: type,
|
|
327
|
+
$value: value,
|
|
328
|
+
...(description ? { $description: description } : {}),
|
|
329
|
+
});
|
|
330
|
+
function setPath(target, path, value) {
|
|
331
|
+
const parts = path.split('.');
|
|
332
|
+
let node = target;
|
|
333
|
+
for (const p of parts.slice(0, -1)) {
|
|
334
|
+
node[p] ??= {};
|
|
335
|
+
node = node[p];
|
|
336
|
+
}
|
|
337
|
+
node[parts.at(-1)] = value;
|
|
338
|
+
}
|
|
339
|
+
function remDim(css) {
|
|
340
|
+
const m = /^(-?[\d.]+)(rem|px)$/.exec(css.trim());
|
|
341
|
+
if (!m)
|
|
342
|
+
throw new Error(`Bad dimension ${css}`);
|
|
343
|
+
return { value: +m[1], unit: m[2] };
|
|
344
|
+
}
|
|
345
|
+
function msDur(css) {
|
|
346
|
+
const m = /^([\d.]+)ms$/.exec(css.trim());
|
|
347
|
+
if (!m)
|
|
348
|
+
throw new Error(`Bad duration ${css}`);
|
|
349
|
+
return { value: +m[1], unit: 'ms' };
|
|
350
|
+
}
|
|
351
|
+
/** A type-role size: a step of the font-size scale, or a literal rem size. */
|
|
352
|
+
function typeSize(v) {
|
|
353
|
+
return /rem$/.test(v) ? remDim(v) : `{font-size.${v}}`;
|
|
354
|
+
}
|
|
355
|
+
const RADIUS_EXT = { 'com.urnextdoor.und': { radiusScale: true } };
|
|
356
|
+
/** Mode-independent base definitions of the new roles: tokens/semantic/roles.tokens.json. */
|
|
357
|
+
export function rolesFile(literalConstants) {
|
|
358
|
+
const doc = {
|
|
359
|
+
$description: 'Roles added with the default theme (Nabh): cards, hover tints, icons, categorical tones, data colours, syntax, the element type scale, element radii and sizes. Themes with a palette override them; the original themes derive them from their scales.',
|
|
360
|
+
};
|
|
361
|
+
const c = (p, v, d) => setPath(doc, p, tok('color', v, d));
|
|
362
|
+
c('bg.card', ref('bg.surface'), 'Cards on the page body.');
|
|
363
|
+
c('bg.hover', ref('scale.neutral.a3'), 'Hover tint laid over any surface.');
|
|
364
|
+
c('bg.pressed', ref('scale.neutral.a4'), 'Pressed tint laid over any surface.');
|
|
365
|
+
c('bg.inverse-danger', ref('status.danger.solid'), 'Inverted error surface (error toasts).');
|
|
366
|
+
c('bg.skeleton', ref('scale.neutral.5'), 'Loading placeholders.');
|
|
367
|
+
c('bg.track', ref('scale.neutral.6'), 'Progress, slider and switch tracks.');
|
|
368
|
+
c('fg.on-dark', ref('color.white'), 'Text on dark media.');
|
|
369
|
+
c('fg.on-light', ref('color.black'), 'Text on light media.');
|
|
370
|
+
c('icon.default', ref('fg.default'));
|
|
371
|
+
c('icon.muted', ref('fg.muted'));
|
|
372
|
+
c('icon.disabled', ref('fg.disabled'));
|
|
373
|
+
c('icon.accent', ref('accent.fg'));
|
|
374
|
+
for (const s of Object.values(STATUS_MAP))
|
|
375
|
+
c(`status.${s}.icon`, ref(`status.${s}.fg`));
|
|
376
|
+
for (const h of TONES)
|
|
377
|
+
c(`tone.${h}.icon`, ref(`tone.${h}.fg`));
|
|
378
|
+
const syntax = {
|
|
379
|
+
keyword: 'accent.fg',
|
|
380
|
+
string: 'tone.green.fg',
|
|
381
|
+
comment: 'fg.muted',
|
|
382
|
+
number: 'tone.orange.fg',
|
|
383
|
+
function: 'tone.blue.fg',
|
|
384
|
+
type: 'tone.purple.fg',
|
|
385
|
+
variable: 'fg.default',
|
|
386
|
+
operator: 'tone.cyan.fg',
|
|
387
|
+
constant: 'tone.orange.fg',
|
|
388
|
+
tag: 'tone.red.fg',
|
|
389
|
+
attribute: 'tone.teal.fg',
|
|
390
|
+
property: 'tone.cyan.fg',
|
|
391
|
+
punctuation: 'fg.muted',
|
|
392
|
+
background: 'bg.subtle',
|
|
393
|
+
};
|
|
394
|
+
for (const [k, v] of Object.entries(syntax))
|
|
395
|
+
c(`syntax.${k}`, ref(v));
|
|
396
|
+
c('syntax.diff-header', ref('bg.subtle'));
|
|
397
|
+
c('syntax.added-marker', ref('tone.green.fg'));
|
|
398
|
+
c('syntax.removed-marker', ref('tone.red.fg'));
|
|
399
|
+
for (const [p, v] of literalConstants)
|
|
400
|
+
setPath(doc, p, { $type: 'color', $value: v });
|
|
401
|
+
for (const [k, n] of [
|
|
402
|
+
['low', 1],
|
|
403
|
+
['med', 2],
|
|
404
|
+
['high', 3],
|
|
405
|
+
])
|
|
406
|
+
setPath(doc, `shadow.${k}`, tok('shadow', ref(`shadow.${n}`)));
|
|
407
|
+
const d = portedValue.bind(null, 'default');
|
|
408
|
+
setPath(doc, 'radius.inner', {
|
|
409
|
+
...tok('dimension', ref('radius.sm')),
|
|
410
|
+
$description: 'Nested elements (4px).',
|
|
411
|
+
});
|
|
412
|
+
setPath(doc, 'radius.element', {
|
|
413
|
+
...tok('dimension', ref('radius.lg')),
|
|
414
|
+
$description: 'Buttons, inputs, list items (8px).',
|
|
415
|
+
});
|
|
416
|
+
setPath(doc, 'radius.container', {
|
|
417
|
+
...tok('dimension', ref('radius.xl')),
|
|
418
|
+
$description: 'Cards, popovers, dialogs (12px).',
|
|
419
|
+
});
|
|
420
|
+
setPath(doc, 'radius.page', {
|
|
421
|
+
...tok('dimension', remDim(d('radius-page', 'light'))),
|
|
422
|
+
$description: 'Page-level sheets (28px).',
|
|
423
|
+
$extensions: RADIUS_EXT,
|
|
424
|
+
});
|
|
425
|
+
setPath(doc, 'radius.chat', {
|
|
426
|
+
...tok('dimension', ref('radius.container')),
|
|
427
|
+
$description: 'Chat bubbles and composers.',
|
|
428
|
+
});
|
|
429
|
+
for (const s of ['sm', 'md', 'lg'])
|
|
430
|
+
setPath(doc, `size.element.${s}`, tok('dimension', remDim(d(`size-element-${s}`, 'light'))));
|
|
431
|
+
for (const s of ['7', '9', '11'])
|
|
432
|
+
setPath(doc, `space.${s}`, tok('dimension', remDim(d(`spacing-${s}`, 'light'))));
|
|
433
|
+
for (const s of FONT_SIZES)
|
|
434
|
+
setPath(doc, `font-size.${s}`, tok('dimension', remDim(d(`font-size-${s}`, 'light'))));
|
|
435
|
+
setPath(doc, 'font-weight.normal', tok('fontWeight', ref('font-weight.regular')));
|
|
436
|
+
for (const r of TYPE_ROLES) {
|
|
437
|
+
setPath(doc, `type.${r}.size`, tok('dimension', ref(`font-size.${d(`text-${r}-size`, 'light')}`)));
|
|
438
|
+
setPath(doc, `type.${r}.weight`, tok('fontWeight', +d(`text-${r}-weight`, 'light')));
|
|
439
|
+
setPath(doc, `type.${r}.leading`, tok('number', +d(`text-${r}-leading`, 'light')));
|
|
440
|
+
}
|
|
441
|
+
setPath(doc, 'duration.exit', tok('duration', ref('duration.fast'), 'Standard dismissal.'));
|
|
442
|
+
setPath(doc, 'ease.standard', tok('cubicBezier', ref('ease.enter'), 'Decelerating standard curve.'));
|
|
443
|
+
return doc;
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* New colour and shadow roles with literal default values, split into
|
|
447
|
+
* mode-independent constants (for the roles file) and per-mode values (for the
|
|
448
|
+
* mode files).
|
|
449
|
+
*/
|
|
450
|
+
export function newLiteralRoles() {
|
|
451
|
+
const constants = [];
|
|
452
|
+
const perMode = { light: [], dark: [] };
|
|
453
|
+
for (const [key, paths] of COLOR_MAP) {
|
|
454
|
+
for (const path of paths) {
|
|
455
|
+
if (!isNewRole(path) || /^(icon|syntax)\./.test(path) || /\.icon$/.test(path))
|
|
456
|
+
continue;
|
|
457
|
+
if ([
|
|
458
|
+
'bg.card',
|
|
459
|
+
'bg.hover',
|
|
460
|
+
'bg.pressed',
|
|
461
|
+
'bg.inverse-danger',
|
|
462
|
+
'bg.skeleton',
|
|
463
|
+
'bg.track',
|
|
464
|
+
'fg.on-dark',
|
|
465
|
+
'fg.on-light',
|
|
466
|
+
].includes(path))
|
|
467
|
+
continue;
|
|
468
|
+
const l = portedValue('default', key, 'light');
|
|
469
|
+
const dk = portedValue('default', key, 'dark');
|
|
470
|
+
const lv = colorValue(parseCssColor(l));
|
|
471
|
+
const dv = colorValue(parseCssColor(dk));
|
|
472
|
+
if (JSON.stringify(lv) === JSON.stringify(dv))
|
|
473
|
+
constants.push([path, lv]);
|
|
474
|
+
else {
|
|
475
|
+
perMode.light.push([path, lv, 'color']);
|
|
476
|
+
perMode.dark.push([path, dv, 'color']);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
for (const [key, paths] of SHADOW_MAP) {
|
|
481
|
+
for (const path of paths) {
|
|
482
|
+
if (!isNewRole(path))
|
|
483
|
+
continue;
|
|
484
|
+
for (const mode of ['light', 'dark'])
|
|
485
|
+
perMode[mode].push([
|
|
486
|
+
path,
|
|
487
|
+
parseShadow(portedValue('default', key, mode)),
|
|
488
|
+
'shadow',
|
|
489
|
+
]);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
return { constants, perMode };
|
|
493
|
+
}
|
|
494
|
+
// ---------------------------------------------------------------- palette files
|
|
495
|
+
/** New roles whose base value already is the default look (literal or equivalent reference). */
|
|
496
|
+
function baseHoldsDefault(path) {
|
|
497
|
+
return /^(tone|data|syntax|tint)\./.test(path) || path === 'elevation.shadow-color';
|
|
498
|
+
}
|
|
499
|
+
/** Roles the AA repair (src/themes/aa.ts) sets or may change; always written as literals. */
|
|
500
|
+
const REPAIRED = [
|
|
501
|
+
'bg.muted-hover',
|
|
502
|
+
'bg.muted-active',
|
|
503
|
+
'fg.default',
|
|
504
|
+
'fg.muted',
|
|
505
|
+
'fg.subtle',
|
|
506
|
+
'fg.inverse',
|
|
507
|
+
'accent.solid',
|
|
508
|
+
'accent.solid-hover',
|
|
509
|
+
'accent.bg-hover',
|
|
510
|
+
'accent.bg-active',
|
|
511
|
+
'accent.fg',
|
|
512
|
+
'accent.fg-strong',
|
|
513
|
+
'link.default',
|
|
514
|
+
'border.control',
|
|
515
|
+
'focus.ring',
|
|
516
|
+
...Object.values(STATUS_MAP).flatMap((s) => ['solid', 'solid-hover', 'bg', 'bg-hover', 'fg', 'fg-strong'].map((r) => `status.${s}.${r}`)),
|
|
517
|
+
];
|
|
518
|
+
/**
|
|
519
|
+
* The literal colour roles of a palette (per theme, per mode) after WCAG 2.2 AA
|
|
520
|
+
* repair: source values where they pass, the nearest passing lightness where not.
|
|
521
|
+
*/
|
|
522
|
+
export function paletteColors(theme, mode) {
|
|
523
|
+
const get = (key) => parseCssColor(portedValue(theme, key, mode));
|
|
524
|
+
const c = new Map();
|
|
525
|
+
for (const [key, paths] of COLOR_MAP)
|
|
526
|
+
for (const path of paths)
|
|
527
|
+
c.set(path, get(key));
|
|
528
|
+
c.set('accent.fg-strong', get('color-text-accent'));
|
|
529
|
+
// Text on the inverted surface: whichever of the surface and the primary text reads better.
|
|
530
|
+
const inv = get('color-background-inverted');
|
|
531
|
+
const candidates = [get('color-background-surface'), get('color-text-primary')];
|
|
532
|
+
c.set('fg.inverse', candidates.reduce((a, b) => (contrast(b, inv) > contrast(a, inv) ? b : a)));
|
|
533
|
+
repairPalette(c, mode, get('color-overlay-hover'), get('color-overlay-pressed'));
|
|
534
|
+
return c;
|
|
535
|
+
}
|
|
536
|
+
/** One palette file (per theme, per mode): literal colours and shadows. */
|
|
537
|
+
export function paletteEntries(theme, mode) {
|
|
538
|
+
const out = [];
|
|
539
|
+
const isDefault = theme === 'default';
|
|
540
|
+
const colors = paletteColors(theme, mode);
|
|
541
|
+
const written = new Set();
|
|
542
|
+
for (const [key, paths] of COLOR_MAP) {
|
|
543
|
+
for (const path of paths) {
|
|
544
|
+
// New roles already hold the default look in the base layer; restate only real overrides.
|
|
545
|
+
if (!REPAIRED.includes(path) &&
|
|
546
|
+
isNewRole(path) &&
|
|
547
|
+
(isDefault ? baseHoldsDefault(path) : !ownsKey(theme, key)))
|
|
548
|
+
continue;
|
|
549
|
+
out.push([path, 'color', colorValue(colors.get(path))]);
|
|
550
|
+
written.add(path);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
for (const path of REPAIRED)
|
|
554
|
+
if (!written.has(path))
|
|
555
|
+
out.push([path, 'color', colorValue(colors.get(path))]);
|
|
556
|
+
// References: the on-solid scale band, visited links and the v0 bridge follow the repaired roles.
|
|
557
|
+
out.push(['scale.accent.9', 'color', '{accent.solid}']);
|
|
558
|
+
out.push(['scale.accent.10', 'color', '{accent.solid-hover}']);
|
|
559
|
+
out.push(['scale.accent.contrast', 'color', '{fg.on-accent}']);
|
|
560
|
+
out.push(['link.visited', 'color', '{link.default}']);
|
|
561
|
+
out.push(['color.accent', 'color', '{accent.fg}']);
|
|
562
|
+
DATA_CATEGORICAL.slice(0, 8).forEach((h, i) => out.push([`dataviz.${i + 1}`, 'color', `{data.categorical.${h}}`]));
|
|
563
|
+
for (const [key, paths] of SHADOW_MAP) {
|
|
564
|
+
for (const path of paths) {
|
|
565
|
+
if (isNewRole(path) && (isDefault || !ownsKey(theme, key)))
|
|
566
|
+
continue;
|
|
567
|
+
out.push([path, 'shadow', parseShadow(portedValue(theme, key, mode))]);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
return out;
|
|
571
|
+
}
|
|
572
|
+
// ---------------------------------------------------------------- theme file (mode-independent)
|
|
573
|
+
/** Non-colour overrides of a palette theme: radii, shapes, spacing, sizes, motion, type scale. */
|
|
574
|
+
export function portedThemeOverrides(theme) {
|
|
575
|
+
const out = [];
|
|
576
|
+
const v = (key) => portedValue(theme, key, 'light');
|
|
577
|
+
const differs = (key) => v(key) !== portedValue('default', key, 'light');
|
|
578
|
+
const dim = (path, key, radius = false) => out.push([
|
|
579
|
+
path,
|
|
580
|
+
{
|
|
581
|
+
$type: 'dimension',
|
|
582
|
+
$value: remDim(v(key)),
|
|
583
|
+
...(radius ? { $extensions: RADIUS_EXT } : {}),
|
|
584
|
+
},
|
|
585
|
+
]);
|
|
586
|
+
if (theme !== 'default')
|
|
587
|
+
for (const r of ['inner', 'element', 'container', 'page', 'chat'])
|
|
588
|
+
dim(`radius.${r}`, `radius-${r}`, true);
|
|
589
|
+
if (differs('radius-full'))
|
|
590
|
+
dim('radius.full', 'radius-full');
|
|
591
|
+
out.push(['shape.control', { $type: 'dimension', $value: '{radius.element}' }]);
|
|
592
|
+
out.push(['shape.card', { $type: 'dimension', $value: '{radius.container}' }]);
|
|
593
|
+
out.push(['shape.dialog', { $type: 'dimension', $value: '{radius.container}' }]);
|
|
594
|
+
out.push(['shape.popover', { $type: 'dimension', $value: '{radius.container}' }]);
|
|
595
|
+
for (const s of SPACING)
|
|
596
|
+
if (differs(`spacing-${s}`))
|
|
597
|
+
dim(`space.${s.replace('-', '_')}`, `spacing-${s}`);
|
|
598
|
+
for (const s of ['sm', 'md', 'lg'])
|
|
599
|
+
if (differs(`size-element-${s}`))
|
|
600
|
+
dim(`size.element.${s}`, `size-element-${s}`);
|
|
601
|
+
for (const s of FONT_SIZES)
|
|
602
|
+
if (differs(`font-size-${s}`))
|
|
603
|
+
dim(`font-size.${s}`, `font-size-${s}`);
|
|
604
|
+
for (const r of TYPE_ROLES) {
|
|
605
|
+
if (differs(`text-${r}-size`))
|
|
606
|
+
out.push([`type.${r}.size`, { $type: 'dimension', $value: typeSize(v(`text-${r}-size`)) }]);
|
|
607
|
+
if (differs(`text-${r}-weight`))
|
|
608
|
+
out.push([`type.${r}.weight`, { $type: 'fontWeight', $value: +v(`text-${r}-weight`) }]);
|
|
609
|
+
if (differs(`text-${r}-leading`))
|
|
610
|
+
out.push([`type.${r}.leading`, { $type: 'number', $value: +v(`text-${r}-leading`) }]);
|
|
611
|
+
}
|
|
612
|
+
for (const k of DURATIONS)
|
|
613
|
+
if (differs(`duration-${k}`))
|
|
614
|
+
out.push([`duration.${k}`, { $type: 'duration', $value: msDur(v(`duration-${k}`)) }]);
|
|
615
|
+
out.push(['focus.offset', { $type: 'dimension', $value: px(3) }]);
|
|
616
|
+
return out;
|
|
617
|
+
}
|
|
618
|
+
export { DURATIONS };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source values of the ported themes, as CSS strings keyed by the original custom
|
|
3
|
+
* property name (without the leading `--`). A string applies to both modes; a
|
|
4
|
+
* `[light, dark]` pair differs per mode. Extracted from the published theme CSS
|
|
5
|
+
* (theme packages 0.7.17) and the core token defaults; src/themes/ported-map.ts
|
|
6
|
+
* maps them onto UND token paths. Data only: regenerate rather than hand-edit.
|
|
7
|
+
*/
|
|
8
|
+
export type PortedValue = string | readonly [light: string, dark: string];
|
|
9
|
+
export type PortedTheme = Readonly<Record<string, PortedValue>>;
|
|
10
|
+
export declare const PORTED: Readonly<Record<string, PortedTheme>>;
|