@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
|
@@ -38,6 +38,13 @@ export interface CssBlock {
|
|
|
38
38
|
motionOnly?: boolean;
|
|
39
39
|
}
|
|
40
40
|
export declare function buildCssBlocks(files: TokenFiles, resolver: ResolverDoc, typeOf: (p: string) => DtcgType | undefined): CssBlock[];
|
|
41
|
+
/**
|
|
42
|
+
* One declaration for both modes. light-dark() only takes colours, so shadow
|
|
43
|
+
* lists are merged layer by layer (both modes must share the layer geometry).
|
|
44
|
+
*/
|
|
45
|
+
export declare function mergeLightDark(light: string, dark: string): string;
|
|
46
|
+
/** Picks one side of every light-dark() in a value (what the browser does per color-scheme). */
|
|
47
|
+
export declare function pickLightDark(value: string, mode: 'light' | 'dark'): string;
|
|
41
48
|
export declare function renderBlocks(blocks: CssBlock[], header: string): string;
|
|
42
49
|
export declare function filterMotion(blocks: CssBlock[]): CssBlock[];
|
|
43
50
|
export type { FlatToken };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { flattenFile } from '../../dtcg/engine.js';
|
|
2
|
-
import { THEMES } from '../../themes/definitions.js';
|
|
2
|
+
import { DEFAULT_THEME, THEMES } from '../../themes/definitions.js';
|
|
3
3
|
import { PREFIX, colorP3Css, cssName, tokenDeclarations } from '../css-values.js';
|
|
4
4
|
export const SCOPE_ATTRS = ['data-und-theme', 'data-und-mode', 'data-und-contrast'];
|
|
5
5
|
const S_LIST = [':root', ...SCOPE_ATTRS.map((a) => `[${a}]`)];
|
|
@@ -156,13 +156,48 @@ export function buildCssBlocks(files, resolver, typeOf) {
|
|
|
156
156
|
}, p3);
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
|
-
// 3. Themes
|
|
159
|
+
// 3. Themes (with their palette: per-mode literals merged through light-dark(),
|
|
160
|
+
// which follows the color-scheme every mode block sets).
|
|
160
161
|
const theme = resolver.modifiers.theme;
|
|
162
|
+
const palette = resolver.modifiers.palette;
|
|
161
163
|
for (const [name, list] of Object.entries(theme.contexts)) {
|
|
162
164
|
const { decls, p3 } = declsForSources(ctx, refs(list));
|
|
163
165
|
const def = THEMES.find((t) => t.name === name);
|
|
164
166
|
if (def && def.modes.length === 1)
|
|
165
167
|
decls.set('color-scheme', def.modes[0]);
|
|
168
|
+
if (palette) {
|
|
169
|
+
const per = ['light', 'dark']
|
|
170
|
+
.map((m) => palette.contexts[`${name}-${m}`])
|
|
171
|
+
.filter((c) => c !== undefined)
|
|
172
|
+
.map((c) => declsForSources(ctx, refs(c)).decls);
|
|
173
|
+
if (per.length === 1)
|
|
174
|
+
for (const [k, v] of per[0]) {
|
|
175
|
+
decls.delete(k);
|
|
176
|
+
decls.set(k, v);
|
|
177
|
+
}
|
|
178
|
+
if (per.length === 2) {
|
|
179
|
+
const [light, dark] = per;
|
|
180
|
+
for (const [k, l] of light) {
|
|
181
|
+
const d = dark.get(k);
|
|
182
|
+
if (d === undefined)
|
|
183
|
+
throw new Error(`Palette ${name}: ${k} has no dark value`);
|
|
184
|
+
decls.delete(k);
|
|
185
|
+
decls.set(k, mergeLightDark(l, d));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (name === DEFAULT_THEME) {
|
|
190
|
+
// Un-themed scopes (no explicit other theme on them or above them) get the default theme.
|
|
191
|
+
const other = `[data-und-theme]:not([data-und-theme="${name}"])`;
|
|
192
|
+
pushWithP3(blocks, {
|
|
193
|
+
id: `theme:${name}:default`,
|
|
194
|
+
condition: { theme: name },
|
|
195
|
+
selector: `:where(:is(${S}):not(${other}):not(${other} *))`,
|
|
196
|
+
wrappers: [],
|
|
197
|
+
decls,
|
|
198
|
+
group: 'theme',
|
|
199
|
+
}, p3);
|
|
200
|
+
}
|
|
166
201
|
pushWithP3(blocks, {
|
|
167
202
|
id: `theme:${name}`,
|
|
168
203
|
condition: { theme: name },
|
|
@@ -295,12 +330,86 @@ export function buildCssBlocks(files, resolver, typeOf) {
|
|
|
295
330
|
});
|
|
296
331
|
return blocks;
|
|
297
332
|
}
|
|
333
|
+
/** Splits at top-level commas (not inside parentheses). */
|
|
334
|
+
function splitTop(v) {
|
|
335
|
+
const out = [];
|
|
336
|
+
let depth = 0;
|
|
337
|
+
let cur = '';
|
|
338
|
+
for (const ch of v) {
|
|
339
|
+
if (ch === '(')
|
|
340
|
+
depth++;
|
|
341
|
+
if (ch === ')')
|
|
342
|
+
depth--;
|
|
343
|
+
if (ch === ',' && depth === 0) {
|
|
344
|
+
out.push(cur.trim());
|
|
345
|
+
cur = '';
|
|
346
|
+
}
|
|
347
|
+
else
|
|
348
|
+
cur += ch;
|
|
349
|
+
}
|
|
350
|
+
out.push(cur.trim());
|
|
351
|
+
return out;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* One declaration for both modes. light-dark() only takes colours, so shadow
|
|
355
|
+
* lists are merged layer by layer (both modes must share the layer geometry).
|
|
356
|
+
*/
|
|
357
|
+
export function mergeLightDark(light, dark) {
|
|
358
|
+
if (light === dark)
|
|
359
|
+
return light;
|
|
360
|
+
const single = (v) => !/\s/.test(v) || /^var\([^)]*\)$/.test(v);
|
|
361
|
+
if (single(light) && single(dark))
|
|
362
|
+
return `light-dark(${light}, ${dark})`;
|
|
363
|
+
const ls = splitTop(light);
|
|
364
|
+
const ds = splitTop(dark);
|
|
365
|
+
if (ls.length !== ds.length)
|
|
366
|
+
throw new Error(`Cannot merge "${light}" and "${dark}"`);
|
|
367
|
+
return ls
|
|
368
|
+
.map((l, i) => {
|
|
369
|
+
const d = ds[i];
|
|
370
|
+
const li = l.lastIndexOf(' ');
|
|
371
|
+
const di = d.lastIndexOf(' ');
|
|
372
|
+
if (l.slice(0, li) !== d.slice(0, di))
|
|
373
|
+
throw new Error(`Shadow layers differ in geometry: "${l}" vs "${d}"`);
|
|
374
|
+
const lc = l.slice(li + 1);
|
|
375
|
+
const dc = d.slice(di + 1);
|
|
376
|
+
return `${l.slice(0, li)} ${lc === dc ? lc : `light-dark(${lc}, ${dc})`}`;
|
|
377
|
+
})
|
|
378
|
+
.join(', ');
|
|
379
|
+
}
|
|
380
|
+
/** Picks one side of every light-dark() in a value (what the browser does per color-scheme). */
|
|
381
|
+
export function pickLightDark(value, mode) {
|
|
382
|
+
let v = value;
|
|
383
|
+
for (let i = v.indexOf('light-dark('); i !== -1; i = v.indexOf('light-dark(')) {
|
|
384
|
+
const start = i + 'light-dark('.length;
|
|
385
|
+
let depth = 1;
|
|
386
|
+
let j = start;
|
|
387
|
+
for (; depth > 0; j++) {
|
|
388
|
+
if (v[j] === '(')
|
|
389
|
+
depth++;
|
|
390
|
+
else if (v[j] === ')')
|
|
391
|
+
depth--;
|
|
392
|
+
}
|
|
393
|
+
const [l, d] = splitTop(v.slice(start, j - 1));
|
|
394
|
+
v = v.slice(0, i) + (mode === 'light' ? l : d) + v.slice(j);
|
|
395
|
+
}
|
|
396
|
+
return v;
|
|
397
|
+
}
|
|
298
398
|
function forcedColors(baseDecls) {
|
|
299
399
|
const map = new Map();
|
|
300
400
|
const set = (k, v) => map.set(k, v);
|
|
301
401
|
for (const k of ['canvas', 'surface', 'raised', 'subtle', 'muted', 'muted-hover', 'muted-active'])
|
|
302
402
|
set(`--und-bg-${k}`, 'Canvas');
|
|
303
403
|
set('--und-bg-inverse', 'CanvasText');
|
|
404
|
+
set('--und-bg-card', 'Canvas');
|
|
405
|
+
for (const k of ['hover', 'pressed', 'skeleton', 'track'])
|
|
406
|
+
set(`--und-bg-${k}`, 'GrayText');
|
|
407
|
+
set('--und-bg-hover', 'transparent');
|
|
408
|
+
set('--und-bg-pressed', 'transparent');
|
|
409
|
+
for (const k of ['default', 'muted'])
|
|
410
|
+
set(`--und-icon-${k}`, 'CanvasText');
|
|
411
|
+
set('--und-icon-disabled', 'GrayText');
|
|
412
|
+
set('--und-icon-accent', 'LinkText');
|
|
304
413
|
set('--und-bg-overlay', 'transparent');
|
|
305
414
|
for (const k of ['default', 'muted', 'subtle'])
|
|
306
415
|
set(`--und-fg-${k}`, 'CanvasText');
|
|
@@ -330,6 +439,7 @@ function forcedColors(baseDecls) {
|
|
|
330
439
|
for (const k of ['solid', 'solid-hover'])
|
|
331
440
|
set(`--und-status-${s}-${k}`, 'Highlight');
|
|
332
441
|
set(`--und-status-${s}-on-solid`, 'HighlightText');
|
|
442
|
+
set(`--und-status-${s}-icon`, 'CanvasText');
|
|
333
443
|
}
|
|
334
444
|
for (const m of ['thin', 'regular', 'thick', 'chrome']) {
|
|
335
445
|
set(`--und-material-${m}-bg`, 'Canvas');
|
|
@@ -338,7 +448,7 @@ function forcedColors(baseDecls) {
|
|
|
338
448
|
}
|
|
339
449
|
set('--und-material-chrome-highlight', 'transparent');
|
|
340
450
|
for (const [k] of baseDecls)
|
|
341
|
-
if (/^--und-shadow
|
|
451
|
+
if (/^--und-shadow-(\d|inset-[a-z]+)$/.test(k))
|
|
342
452
|
set(k, 'none');
|
|
343
453
|
for (let i = 0; i <= 5; i++)
|
|
344
454
|
set(`--und-shadow-${i}`, 'none');
|
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flutter output: und_tokens.dart. No Material dependency: dart:ui types,
|
|
3
|
-
* flutter/animation (Cubic), flutter/physics (SpringDescription),
|
|
4
|
-
* flutter/painting (TextStyle, BoxShadow) and flutter/widgets (InheritedWidget).
|
|
5
|
-
* UndThemeData has ==, hashCode and lerp so it works with InheritedWidget and
|
|
6
|
-
* implicit animations.
|
|
7
|
-
*/
|
|
8
1
|
import type { NativeModel } from '../native-model.js';
|
|
9
2
|
export declare function renderDart(model: NativeModel): string;
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flutter output: und_tokens.dart. No Material dependency: dart:ui types,
|
|
3
|
+
* flutter/animation (Cubic), flutter/physics (SpringDescription),
|
|
4
|
+
* flutter/painting (TextStyle, BoxShadow) and flutter/widgets (InheritedWidget).
|
|
5
|
+
* UndThemeData has ==, hashCode and lerp so it works with InheritedWidget and
|
|
6
|
+
* implicit animations.
|
|
7
|
+
*/
|
|
8
|
+
import { DEFAULT_THEME } from '../../themes/definitions.js';
|
|
1
9
|
import { VARIANTS, camel, stepName } from '../native-model.js';
|
|
2
10
|
const d = (v) => {
|
|
3
11
|
const r = Math.round(v * 10000) / 10000;
|
|
@@ -13,6 +21,13 @@ function color(c) {
|
|
|
13
21
|
.toUpperCase();
|
|
14
22
|
return `Color(0x${a}${c.hex.slice(1).toUpperCase()})`;
|
|
15
23
|
}
|
|
24
|
+
/** Identifier part for a shadow key: numeric levels stay, `inset-hover` becomes `InsetHover`. */
|
|
25
|
+
function shadowId(k) {
|
|
26
|
+
if (/^[0-9]+$/.test(k))
|
|
27
|
+
return k;
|
|
28
|
+
const c = camel(k);
|
|
29
|
+
return c.charAt(0).toUpperCase() + c.slice(1);
|
|
30
|
+
}
|
|
16
31
|
function shadow(s) {
|
|
17
32
|
const layers = s.layers
|
|
18
33
|
.filter((l) => !l.inset)
|
|
@@ -138,7 +153,7 @@ class UndRadii {
|
|
|
138
153
|
${radiusKeys.map((k) => ` final double ${stepName(k)};`).join('\n')}
|
|
139
154
|
|
|
140
155
|
/// Concentric inner radius: outer - padding, at least 2.
|
|
141
|
-
double
|
|
156
|
+
double concentricInner(double outer, double padding) => (outer - padding) < 2 ? 2 : outer - padding;
|
|
142
157
|
|
|
143
158
|
UndRadii lerp(UndRadii other, double t) => UndRadii(
|
|
144
159
|
factor: lerpDouble(factor, other.factor, t)!,
|
|
@@ -240,12 +255,15 @@ ${[...model.typography].map(([k, t]) => ` ${str(camel(k))}: ${d(t.lineHeightI
|
|
|
240
255
|
|
|
241
256
|
/// Elevation shadows per brightness (BoxShadow lists).
|
|
242
257
|
abstract final class UndShadows {
|
|
243
|
-
${model.themes[0].shadows.light.size ? [...model.themes[0].shadows.light.keys()].map((k) => ` static const List<BoxShadow> light${k} = ${shadow(model.themes[0].shadows.light.get(k))};\n static const List<BoxShadow> dark${k} = ${shadow(model.themes[0].shadows.dark.get(k))};`).join('\n') : ''}
|
|
258
|
+
${model.themes[0].shadows.light.size ? [...model.themes[0].shadows.light.keys()].map((k) => ` static const List<BoxShadow> light${shadowId(k)} = ${shadow(model.themes[0].shadows.light.get(k))};\n static const List<BoxShadow> dark${shadowId(k)} = ${shadow(model.themes[0].shadows.dark.get(k))};`).join('\n') : ''}
|
|
244
259
|
|
|
245
260
|
static List<BoxShadow> of(int level, Brightness brightness) {
|
|
246
261
|
final dark = brightness == Brightness.dark;
|
|
247
262
|
switch (level) {
|
|
248
|
-
${[...model.themes[0].shadows.light.keys()]
|
|
263
|
+
${[...model.themes[0].shadows.light.keys()]
|
|
264
|
+
.filter((k) => /^[0-9]+$/.test(k))
|
|
265
|
+
.map((k) => ` case ${k}:\n return dark ? dark${k} : light${k};`)
|
|
266
|
+
.join('\n')}
|
|
249
267
|
default:
|
|
250
268
|
return const <BoxShadow>[];
|
|
251
269
|
}
|
|
@@ -329,7 +347,7 @@ class UndTheme extends InheritedWidget {
|
|
|
329
347
|
final UndThemeData data;
|
|
330
348
|
|
|
331
349
|
static UndThemeData of(BuildContext context) =>
|
|
332
|
-
context.dependOnInheritedWidgetOfExactType<UndTheme>()?.data ?? UndThemeData.of(UndThemeName
|
|
350
|
+
context.dependOnInheritedWidgetOfExactType<UndTheme>()?.data ?? UndThemeData.of(UndThemeName.${DEFAULT_THEME});
|
|
333
351
|
|
|
334
352
|
@override
|
|
335
353
|
bool updateShouldNotify(UndTheme oldWidget) => data != oldWidget.data;
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ESM + .d.ts output.
|
|
3
|
-
* tokens default context (Ujala, light, standard contrast), CSS-ready values
|
|
4
|
-
* vars same shape, every leaf is var(--und-...) for runtime theming
|
|
5
|
-
* getTokens() any resolver input; built from per-context diffs
|
|
6
|
-
*/
|
|
7
1
|
import type { Context } from '../../dtcg/engine.js';
|
|
8
2
|
import type { MatValue } from '../materialize.js';
|
|
9
3
|
type Json = string | number | boolean | null | Json[] | {
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ESM + .d.ts output.
|
|
3
|
+
* tokens default context (Ujala, light, standard contrast), CSS-ready values
|
|
4
|
+
* vars same shape, every leaf is var(--und-...) for runtime theming
|
|
5
|
+
* getTokens() any resolver input; built from per-context diffs
|
|
6
|
+
*/
|
|
7
|
+
import { DEFAULT_THEME } from '../../themes/definitions.js';
|
|
1
8
|
import { cssName } from '../css-values.js';
|
|
2
9
|
import { fluidClamp, hex8 } from '../css-values.js';
|
|
3
10
|
import { materialize } from '../materialize.js';
|
|
@@ -198,7 +205,7 @@ function apply(tree, diff) {
|
|
|
198
205
|
* Values match the CSS output for the same attributes (radius and tempo applied).
|
|
199
206
|
*/
|
|
200
207
|
export function getTokens(input = {}) {
|
|
201
|
-
const theme = input.theme ??
|
|
208
|
+
const theme = input.theme ?? ${JSON.stringify(DEFAULT_THEME)};
|
|
202
209
|
const meta = themes.find((t) => t.name === theme);
|
|
203
210
|
if (!meta) throw new Error('Unknown UND theme: ' + theme);
|
|
204
211
|
const mode = meta.modes.includes(input.mode ?? 'light') ? (input.mode ?? 'light') : meta.modes[0];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Jetpack Compose output: UndTokens.kt (package dev.undui.tokens).
|
|
3
|
-
* UndColors (data
|
|
3
|
+
* UndColors (grouped role data classes, one lazy scheme per theme x variant), UndTypography, UndSpacing,
|
|
4
4
|
* UndRadii, UndMotion and UndControl objects. Wide-gamut colours use
|
|
5
5
|
* ColorSpaces.DisplayP3.
|
|
6
6
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VARIANTS, camel, stepName } from '../native-model.js';
|
|
1
|
+
import { VARIANTS, camel, colorRoleGroups, stepName } from '../native-model.js';
|
|
2
2
|
const f = (v) => {
|
|
3
3
|
const r = Math.round(v * 10000) / 10000;
|
|
4
4
|
return `${Number.isInteger(r) ? `${r}.0` : `${r}`}f`;
|
|
@@ -15,11 +15,16 @@ function color(c) {
|
|
|
15
15
|
.toUpperCase();
|
|
16
16
|
return `Color(0x${a}${c.hex.slice(1).toUpperCase()})`;
|
|
17
17
|
}
|
|
18
|
+
// Kotlin hard keywords need backticks when used as identifiers.
|
|
19
|
+
const KOTLIN_KEYWORDS = new Set('as break class continue do else false for fun if in interface is null object package return super this throw true try typealias typeof val var when while'.split(' '));
|
|
20
|
+
const kid = (name) => (KOTLIN_KEYWORDS.has(name) ? `\`${name}\`` : name);
|
|
18
21
|
function cap(s) {
|
|
19
22
|
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
20
23
|
}
|
|
21
24
|
export function renderKotlin(model) {
|
|
22
|
-
const
|
|
25
|
+
const groups = colorRoleGroups(model.colorRoles);
|
|
26
|
+
const groupClass = (g) => `Und${cap(g)}Colors`;
|
|
27
|
+
const themeObject = (name) => `Und${cap(name)}Colors`;
|
|
23
28
|
const L = [];
|
|
24
29
|
L.push(`// Generated by @und-ui/tokens ${model.version}. Do not edit.
|
|
25
30
|
// Source: DTCG 2025.10 tokens. Semantic roles only (no hue names).
|
|
@@ -49,34 +54,58 @@ enum class UndCharacter { Crisp, Standard, Expressive }
|
|
|
49
54
|
|
|
50
55
|
enum class UndDensity { Comfortable, Compact, Touch }
|
|
51
56
|
|
|
52
|
-
/** Semantic colour roles for one theme and appearance. */
|
|
57
|
+
/** Semantic colour roles for one theme and appearance, stored per group (bg, fg, status, ...). */
|
|
53
58
|
@Immutable
|
|
54
59
|
data class UndColors(
|
|
55
|
-
${
|
|
60
|
+
${groups.map(([g]) => ` val ${kid(g)}: ${groupClass(g)},`).join('\n')}
|
|
56
61
|
) {
|
|
62
|
+
// Flat role accessors: colors.bgSurface == colors.bg.surface.
|
|
63
|
+
${groups.flatMap(([g, rs]) => rs.map((r) => ` val ${kid(r.flat)}: Color get() = ${kid(g)}.${kid(r.member)}`)).join('\n')}
|
|
64
|
+
|
|
57
65
|
companion object {
|
|
58
66
|
${model.themes
|
|
59
|
-
.flatMap((t) => VARIANTS.map((v) => ` val ${t.def.name}${cap(v)}: UndColors =
|
|
60
|
-
|
|
61
|
-
)`))
|
|
62
|
-
.join('\n\n')}
|
|
67
|
+
.flatMap((t) => VARIANTS.map((v) => ` val ${t.def.name}${cap(v)}: UndColors get() = ${themeObject(t.def.name)}.${v}`))
|
|
68
|
+
.join('\n')}
|
|
63
69
|
|
|
64
70
|
/** Pick a scheme. Dark-only themes (Raat) ignore [dark]. */
|
|
65
71
|
fun of(theme: UndThemeName, dark: Boolean, highContrast: Boolean = false): UndColors = when (theme) {
|
|
66
72
|
${model.themes
|
|
67
73
|
.map((t) => {
|
|
68
|
-
const
|
|
69
|
-
return ` UndThemeName.${cap(name)} -> when {
|
|
70
|
-
dark && highContrast -> ${
|
|
71
|
-
dark -> ${
|
|
72
|
-
highContrast -> ${
|
|
73
|
-
else -> ${
|
|
74
|
+
const o = themeObject(t.def.name);
|
|
75
|
+
return ` UndThemeName.${cap(t.def.name)} -> when {
|
|
76
|
+
dark && highContrast -> ${o}.darkMore
|
|
77
|
+
dark -> ${o}.dark
|
|
78
|
+
highContrast -> ${o}.lightMore
|
|
79
|
+
else -> ${o}.light
|
|
74
80
|
}`;
|
|
75
81
|
})
|
|
76
82
|
.join('\n')}
|
|
77
83
|
}
|
|
78
84
|
}
|
|
79
85
|
}
|
|
86
|
+
|
|
87
|
+
${groups
|
|
88
|
+
.map(([g, rs]) => `/** Colour roles in the ${g} group. */
|
|
89
|
+
@Immutable
|
|
90
|
+
data class ${groupClass(g)}(
|
|
91
|
+
${rs.map((r) => ` val ${kid(r.member)}: Color,`).join('\n')}
|
|
92
|
+
)`)
|
|
93
|
+
.join('\n\n')}
|
|
94
|
+
|
|
95
|
+
${model.themes
|
|
96
|
+
.map((t) => `/** ${t.def.label} schemes. One object per theme, one lazy method per variant: every class and method stays far below JVM limits. */
|
|
97
|
+
private object ${themeObject(t.def.name)} {
|
|
98
|
+
${VARIANTS.map((v) => ` val ${v}: UndColors by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
|
99
|
+
UndColors(
|
|
100
|
+
${groups
|
|
101
|
+
.map(([g, rs]) => ` ${kid(g)} = ${groupClass(g)}(
|
|
102
|
+
${rs.map((r) => ` ${kid(r.member)} = ${color(t.colors[v].get(r.flat))},`).join('\n')}
|
|
103
|
+
),`)
|
|
104
|
+
.join('\n')}
|
|
105
|
+
)
|
|
106
|
+
}`).join('\n\n')}
|
|
107
|
+
}`)
|
|
108
|
+
.join('\n\n')}
|
|
80
109
|
`);
|
|
81
110
|
const dpObject = (name, entries, doc, prefix = 's') => `/** ${doc} */\nobject ${name} {\n${[...entries].map(([k, v]) => ` val ${stepName(k, prefix)}: Dp = ${dp(v)}`).join('\n')}\n}\n`;
|
|
82
111
|
L.push(dpObject('UndSpacing', model.spacing, '4dp spacing scale (report 3.1). Density never changes these.'));
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* index.js Platform-aware entry: resolves shadows, hit targets, hairlines and
|
|
5
5
|
* monospace families with Platform.select / StyleSheet.hairlineWidth.
|
|
6
6
|
*/
|
|
7
|
+
import { DEFAULT_THEME } from '../../themes/definitions.js';
|
|
7
8
|
import { hex8 } from '../css-values.js';
|
|
8
9
|
import { VARIANTS, camel, stepName } from '../native-model.js';
|
|
9
10
|
const HEADER = '// Generated by @und-ui/tokens. Do not edit.\n';
|
|
@@ -107,7 +108,7 @@ const MONO = { ios: 'Menlo', android: 'monospace', web: 'ui-monospace, monospace
|
|
|
107
108
|
* @param {{ theme?: string, scheme?: 'light' | 'dark', highContrast?: boolean, hairlineWidth?: number }} [options]
|
|
108
109
|
*/
|
|
109
110
|
export function createTheme(os, options = {}) {
|
|
110
|
-
const t = data.themes[options.theme ??
|
|
111
|
+
const t = data.themes[options.theme ?? ${JSON.stringify(DEFAULT_THEME)}];
|
|
111
112
|
if (!t) throw new Error('Unknown UND theme: ' + options.theme);
|
|
112
113
|
const dark = t.darkOnly || options.scheme === 'dark';
|
|
113
114
|
const variant = (dark ? 'dark' : 'light') + (options.highContrast ? 'More' : '');
|
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SwiftUI output: UndTokens.swift.
|
|
3
|
-
* Foundation-only value types (compile on Linux) plus `#if canImport(SwiftUI)`
|
|
4
|
-
* extensions that produce dynamic Colors (light/dark x Increase Contrast),
|
|
5
|
-
* Fonts (Dynamic Type relative) and spring Animations.
|
|
6
|
-
*/
|
|
7
1
|
import type { NativeModel } from '../native-model.js';
|
|
8
2
|
export declare function renderSwift(model: NativeModel): string;
|
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* SwiftUI output: UndTokens.swift.
|
|
3
|
+
* Foundation-only value types (compile on Linux) plus `#if canImport(SwiftUI)`
|
|
4
|
+
* extensions that produce dynamic Colors (light/dark x Increase Contrast),
|
|
5
|
+
* Fonts (Dynamic Type relative) and spring Animations.
|
|
6
|
+
*/
|
|
7
|
+
import { DEFAULT_THEME } from '../../themes/definitions.js';
|
|
8
|
+
import { VARIANTS, camel, colorRoleGroups, stepName } from '../native-model.js';
|
|
2
9
|
const n = (v) => {
|
|
3
10
|
const r = Math.round(v * 10000) / 10000;
|
|
4
11
|
return Number.isInteger(r) ? `${r}` : `${r}`;
|
|
5
12
|
};
|
|
6
13
|
const str = (s) => JSON.stringify(s);
|
|
14
|
+
const cap = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
15
|
+
// Swift keywords need backticks when declared as identifiers (argument labels do not).
|
|
16
|
+
const SWIFT_KEYWORDS = new Set('as associatedtype break case catch class continue default defer deinit do else enum extension fallthrough false fileprivate for func guard if import in init inout internal is let nil operator private protocol public repeat rethrows return self Self static struct subscript super switch throw throws true try typealias var where while'.split(' '));
|
|
17
|
+
const sid = (name) => (SWIFT_KEYWORDS.has(name) ? `\`${name}\`` : name);
|
|
7
18
|
function rgba(c) {
|
|
8
19
|
if (c.p3)
|
|
9
20
|
return `UndRGBA(${n(c.p3[0])}, ${n(c.p3[1])}, ${n(c.p3[2])}, ${n(c.alpha)}, space: .displayP3)`;
|
|
@@ -93,24 +104,76 @@ public enum UndCharacter: String, Sendable { case crisp, standard, expressive }
|
|
|
93
104
|
public enum UndDensity: String, Sendable { case comfortable, compact, touch }
|
|
94
105
|
public enum UndGlass: String, Sendable { case chrome, on, off }
|
|
95
106
|
`);
|
|
96
|
-
// Colour roles struct
|
|
97
|
-
|
|
107
|
+
// Colour roles: one nested struct per group, stored behind a single reference so UndColorRoles
|
|
108
|
+
// (and UndTheme, which embeds it) stays pointer-sized. A flat struct with hundreds of roles made a
|
|
109
|
+
// memberwise initialiser with hundreds of parameters and multi-kilobyte value copies.
|
|
110
|
+
const groups = colorRoleGroups(model.colorRoles);
|
|
111
|
+
const groupType = (g) => `${cap(g)}Roles`;
|
|
112
|
+
const groupLines = [];
|
|
113
|
+
for (const [g, rs] of groups) {
|
|
114
|
+
groupLines.push(` /// Colour roles in the ${g} group.
|
|
115
|
+
public struct ${groupType(g)}: Sendable, Equatable {
|
|
116
|
+
${rs.map((r) => ` public let ${sid(r.member)}: UndDynamicColor`).join('\n')}
|
|
117
|
+
|
|
118
|
+
public init(
|
|
119
|
+
${rs.map((r, i) => ` ${sid(r.member)}: UndDynamicColor${i === rs.length - 1 ? '' : ','}`).join('\n')}
|
|
120
|
+
) {
|
|
121
|
+
${rs.map((r) => ` self.${sid(r.member)} = ${sid(r.member)}`).join('\n')}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
`);
|
|
125
|
+
}
|
|
126
|
+
L.push(`/// Semantic colour roles, grouped by token path (bg.surface -> colors.bg.surface, also colors.bgSurface).
|
|
98
127
|
public struct UndColorRoles: Sendable, Equatable {
|
|
99
|
-
${
|
|
128
|
+
${groupLines.join('\n')}
|
|
129
|
+
private final class Storage: Sendable {
|
|
130
|
+
${groups.map(([g]) => ` let ${sid(g)}: ${groupType(g)}`).join('\n')}
|
|
131
|
+
|
|
132
|
+
init(${groups.map(([g]) => `${sid(g)}: ${groupType(g)}`).join(', ')}) {
|
|
133
|
+
${groups.map(([g]) => ` self.${sid(g)} = ${sid(g)}`).join('\n')}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
private let storage: Storage
|
|
138
|
+
|
|
139
|
+
public init(${groups.map(([g]) => `${sid(g)}: ${groupType(g)}`).join(', ')}) {
|
|
140
|
+
storage = Storage(${groups.map(([g]) => `${sid(g)}: ${sid(g)}`).join(', ')})
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
${groups.map(([g]) => ` public var ${sid(g)}: ${groupType(g)} { storage.${sid(g)} }`).join('\n')}
|
|
144
|
+
|
|
145
|
+
public static func == (lhs: UndColorRoles, rhs: UndColorRoles) -> Bool {
|
|
146
|
+
if lhs.storage === rhs.storage { return true }
|
|
147
|
+
${groups.map(([g]) => ` guard lhs.${sid(g)} == rhs.${sid(g)} else { return false }`).join('\n')}
|
|
148
|
+
return true
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/// Flat role accessors: bgSurface == bg.surface.
|
|
153
|
+
extension UndColorRoles {
|
|
154
|
+
${groups.flatMap(([g, rs]) => rs.map((r) => ` public var ${sid(r.flat)}: UndDynamicColor { storage.${sid(g)}.${sid(r.member)} }`)).join('\n')}
|
|
100
155
|
}
|
|
101
156
|
`);
|
|
102
|
-
L.push('extension UndColorRoles {');
|
|
103
157
|
for (const t of model.themes) {
|
|
104
|
-
|
|
105
|
-
L.push(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
158
|
+
const ns = `Und${cap(t.def.name)}ColorRoles`;
|
|
159
|
+
L.push(`extension UndColorRoles {
|
|
160
|
+
public static let ${t.def.name}: UndColorRoles = ${ns}.roles
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/// ${t.def.label} roles: one lazily initialised static per group keeps every initialiser small.
|
|
164
|
+
private enum ${ns} {`);
|
|
165
|
+
for (const [g, rs] of groups) {
|
|
166
|
+
L.push(` static let ${sid(g)}: UndColorRoles.${groupType(g)} = {`);
|
|
167
|
+
rs.forEach((r, i) => {
|
|
168
|
+
const parts = VARIANTS.map((v) => `${v}: ${rgba(t.colors[v].get(r.flat))}`).join(', ');
|
|
169
|
+
L.push(` let c${i}: UndDynamicColor = UndDynamicColor(${parts})`);
|
|
170
|
+
});
|
|
171
|
+
L.push(` return UndColorRoles.${groupType(g)}(${rs.map((r, i) => `${r.member}: c${i}`).join(', ')})`);
|
|
172
|
+
L.push(' }()');
|
|
173
|
+
}
|
|
174
|
+
L.push(` static let roles: UndColorRoles = UndColorRoles(${groups.map(([g]) => `${g}: ${sid(g)}`).join(', ')})`);
|
|
175
|
+
L.push('}\n');
|
|
112
176
|
}
|
|
113
|
-
L.push('}\n');
|
|
114
177
|
// Spacing / sizes
|
|
115
178
|
const cg = (name, entries, doc, prefix = 's') => `/// ${doc}\npublic enum ${name} {\n${[...entries].map(([k, v]) => ` public static let ${stepName(k, prefix)}: CGFloat = ${n(v)}`).join('\n')}\n}\n`;
|
|
116
179
|
L.push(cg('UndSpacing', model.spacing, '4pt spacing scale (report 3.1). Density never changes these.'));
|
|
@@ -371,7 +434,7 @@ ${Object.entries(IOS_WEIGHT)
|
|
|
371
434
|
}
|
|
372
435
|
|
|
373
436
|
private struct UndThemeKey: EnvironmentKey {
|
|
374
|
-
static let defaultValue: UndTheme =
|
|
437
|
+
static let defaultValue: UndTheme = .${DEFAULT_THEME}
|
|
375
438
|
}
|
|
376
439
|
|
|
377
440
|
extension EnvironmentValues {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isBridge } from '../../dtcg/types.js';
|
|
2
|
+
import { THEMES } from '../../themes/definitions.js';
|
|
2
3
|
import { cssName } from '../css-values.js';
|
|
3
4
|
import { materialize } from '../materialize.js';
|
|
4
5
|
export function renderTailwind(ctx, themes, version) {
|
|
@@ -14,6 +15,11 @@ export function renderTailwind(ctx, themes, version) {
|
|
|
14
15
|
'link',
|
|
15
16
|
'dataviz',
|
|
16
17
|
'selection',
|
|
18
|
+
'icon',
|
|
19
|
+
'tone',
|
|
20
|
+
'data',
|
|
21
|
+
'syntax',
|
|
22
|
+
'tint',
|
|
17
23
|
];
|
|
18
24
|
const add = (k, v) => lines.push(` ${k}: ${v};`);
|
|
19
25
|
lines.push(' /* Colours: semantic roles (theme-aware) */');
|
|
@@ -41,8 +47,11 @@ export function renderTailwind(ctx, themes, version) {
|
|
|
41
47
|
add(`--radius-${p.slice(6)}`, `var(${cssName(p)})`);
|
|
42
48
|
lines.push(' /* Elevation */');
|
|
43
49
|
for (const p of paths)
|
|
44
|
-
if (/^shadow
|
|
50
|
+
if (/^shadow\.(\d|low|med|high)$/.test(p))
|
|
45
51
|
add(`--shadow-${p.slice(7)}`, `var(${cssName(p)})`);
|
|
52
|
+
for (const p of paths)
|
|
53
|
+
if (/^shadow\.inset-/.test(p))
|
|
54
|
+
add(`--inset-shadow-${p.slice(13)}`, `var(${cssName(p)})`);
|
|
46
55
|
lines.push(' /* Fonts */');
|
|
47
56
|
add('--font-sans', 'var(--und-typeface-body)');
|
|
48
57
|
add('--font-heading', 'var(--und-typeface-heading)');
|
|
@@ -62,6 +71,15 @@ export function renderTailwind(ctx, themes, version) {
|
|
|
62
71
|
add(`--text-${n}--letter-spacing`, `var(${v}-tracking)`);
|
|
63
72
|
add(`--text-${n}--font-weight`, `var(${v}-weight)`);
|
|
64
73
|
}
|
|
74
|
+
lines.push(' /* Element type scale (text-heading-1 ... text-supporting; follows the theme) */');
|
|
75
|
+
for (const p of paths) {
|
|
76
|
+
const m = /^type\.([a-z0-9-]+)\.size$/.exec(p);
|
|
77
|
+
if (!m)
|
|
78
|
+
continue;
|
|
79
|
+
add(`--text-${m[1]}`, `var(--und-type-${m[1]}-size)`);
|
|
80
|
+
add(`--text-${m[1]}--line-height`, `var(--und-type-${m[1]}-leading)`);
|
|
81
|
+
add(`--text-${m[1]}--font-weight`, `var(--und-type-${m[1]}-weight)`);
|
|
82
|
+
}
|
|
65
83
|
lines.push(' /* Motion */');
|
|
66
84
|
for (const e of ['enter', 'exit', 'move', 'emphasized'])
|
|
67
85
|
add(`--ease-${e}`, `var(--und-motion-ease-${e})`);
|
|
@@ -79,7 +97,9 @@ export function renderTailwind(ctx, themes, version) {
|
|
|
79
97
|
bp.push(` --breakpoint-${p.slice(11)}: ${m.css};`);
|
|
80
98
|
}
|
|
81
99
|
const variants = [
|
|
82
|
-
|
|
100
|
+
`@custom-variant und-dark (&:where([data-und-mode="dark"], [data-und-mode="dark"] *${THEMES.filter((t) => t.modes.length === 1 && t.modes[0] === 'dark')
|
|
101
|
+
.map((t) => `, [data-und-theme="${t.name}"], [data-und-theme="${t.name}"] *`)
|
|
102
|
+
.join('')}));`,
|
|
83
103
|
'@custom-variant und-more (&:where([data-und-contrast="more"], [data-und-contrast="more"] *));',
|
|
84
104
|
'@custom-variant und-compact (&:where([data-und-density="compact"], [data-und-density="compact"] *));',
|
|
85
105
|
...themes.map((t) => `@custom-variant theme-${t} (&:where([data-und-theme="${t}"], [data-und-theme="${t}"] *));`),
|
package/dist/lib/build/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { readFileSync } from 'node:fs';
|
|
7
7
|
import { join } from 'node:path';
|
|
8
8
|
import { TokenFiles, resolveContext } from '../dtcg/engine.js';
|
|
9
|
-
import { THEMES } from '../themes/definitions.js';
|
|
9
|
+
import { DEFAULT_THEME, THEMES } from '../themes/definitions.js';
|
|
10
10
|
import { colorContextKeys, variantName } from './contexts.js';
|
|
11
11
|
import { buildCssBlocks, filterMotion, renderBlocks } from './formats/css.js';
|
|
12
12
|
import { renderDart } from './formats/dart.js';
|
|
@@ -38,10 +38,11 @@ export async function buildAll(root) {
|
|
|
38
38
|
const blocks = buildCssBlocks(files, resolver, typeOf);
|
|
39
39
|
const cssHeader = (what) => header(version, what);
|
|
40
40
|
out['css/tokens.css'] = renderBlocks(blocks, cssHeader('All themes, modes, contrast, density, transparency and motion contexts. Attributes on <html> (or any scope element): data-und-theme, data-und-mode, data-und-contrast, data-und-density, data-und-transparency, data-und-motion.'));
|
|
41
|
-
const
|
|
41
|
+
const themeOf = (b) => (b.group === 'theme' ? b.id.split(':')[1] : undefined);
|
|
42
|
+
const nonDefaultTheme = (b) => b.group === 'theme' && themeOf(b) !== DEFAULT_THEME;
|
|
42
43
|
out['css/base.css'] = renderBlocks(blocks.filter((b) => !nonDefaultTheme(b)), cssHeader('Everything except the non-default themes. Add css/themes/<name>.css for the themes you use.'));
|
|
43
44
|
for (const t of THEMES) {
|
|
44
|
-
out[`css/themes/${t.name}.css`] = renderBlocks(blocks.filter((b) => b
|
|
45
|
+
out[`css/themes/${t.name}.css`] = renderBlocks(blocks.filter((b) => themeOf(b) === t.name && !b.id.endsWith(':default') && !b.id.endsWith(':default:p3')), cssHeader(`${t.label} theme. Load after css/base.css; activate with data-und-theme="${t.name}".`));
|
|
45
46
|
}
|
|
46
47
|
out['css/motion.css'] = renderBlocks(filterMotion(blocks), cssHeader('Motion only: durations x tempo (--und-motion-tempo), easings, spring linear() curves with cubic-bezier fallback, and reduced-motion rules. Included in tokens.css.'));
|
|
47
48
|
const cssProperties = new Set();
|
|
@@ -101,7 +102,7 @@ export async function buildAll(root) {
|
|
|
101
102
|
for (const [f, content] of Object.entries(sd))
|
|
102
103
|
out[f] = content;
|
|
103
104
|
}
|
|
104
|
-
out['scss/_variables.scss'] = out[
|
|
105
|
+
out['scss/_variables.scss'] = out[`scss/${DEFAULT_THEME}.light.scss`];
|
|
105
106
|
out['scss/_vars.scss'] =
|
|
106
107
|
`// Generated by @und-ui/tokens ${version}. Do not edit.\n// Runtime-themable Sass variables: each one is the CSS custom property.\n${[
|
|
107
108
|
...cssProperties,
|
|
@@ -110,7 +111,7 @@ export async function buildAll(root) {
|
|
|
110
111
|
.sort()
|
|
111
112
|
.map((p) => `$${p.slice(2)}: var(${p});`)
|
|
112
113
|
.join('\n')}\n`;
|
|
113
|
-
Object.assign(out, await buildAndroid(ctxByKey.get(
|
|
114
|
+
Object.assign(out, await buildAndroid(ctxByKey.get(`${DEFAULT_THEME}/light`), ctxByKey.get(`${DEFAULT_THEME}/dark`)));
|
|
114
115
|
// Tailwind
|
|
115
116
|
out['tailwind/und.css'] = renderTailwind(defaultCtx, THEMES.map((t) => t.name), version);
|
|
116
117
|
// Native
|
|
@@ -7,6 +7,22 @@ export declare const VARIANTS: readonly Variant[];
|
|
|
7
7
|
export declare function camel(path: string): string;
|
|
8
8
|
/** Identifier-safe key for scale steps: `2xl` -> `xxl`, `3xl` -> `xxxl`, `0_5` -> `s0p5`. */
|
|
9
9
|
export declare function stepName(key: string, numericPrefix?: string): string;
|
|
10
|
+
/** One colour role inside a role group: `bg.surface` -> group `bg`, member `surface`, flat `bgSurface`. */
|
|
11
|
+
export interface GroupedRole {
|
|
12
|
+
flat: string;
|
|
13
|
+
member: string;
|
|
14
|
+
path: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Most roles one group may hold. Kotlin `Color` is a `long` (2 JVM parameter slots) and a JVM method
|
|
18
|
+
* takes at most 255 slots, so a data class constructor must stay well below 127 colour parameters.
|
|
19
|
+
*/
|
|
20
|
+
export declare const MAX_ROLES_PER_GROUP = 100;
|
|
21
|
+
/**
|
|
22
|
+
* Colour roles grouped by the first token path segment (bg, fg, status, data, ...). Native outputs
|
|
23
|
+
* store roles per group so no generated class or method grows with the total role count.
|
|
24
|
+
*/
|
|
25
|
+
export declare function colorRoleGroups(roles: [string, string][]): [string, GroupedRole[]][];
|
|
10
26
|
export interface NativeTheme {
|
|
11
27
|
def: ThemeDefinition;
|
|
12
28
|
colors: Record<Variant, Map<string, MatColor>>;
|