@und-ui/tokens 0.2.0 → 0.3.1

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.
Files changed (247) hide show
  1. package/README.md +100 -11
  2. package/dist/android/values/und_colors.xml +204 -73
  3. package/dist/android/values/und_dimens.xml +15 -4
  4. package/dist/android/values-night/und_colors.xml +207 -76
  5. package/dist/css/base.css +610 -35
  6. package/dist/css/motion.css +129 -1
  7. package/dist/css/themes/butter.css +278 -0
  8. package/dist/css/themes/chocolate.css +255 -0
  9. package/dist/css/themes/gothic.css +710 -0
  10. package/dist/css/themes/kesar.css +1 -1
  11. package/dist/css/themes/matcha.css +291 -0
  12. package/dist/css/themes/mitti.css +1 -1
  13. package/dist/css/themes/nabh.css +179 -0
  14. package/dist/css/themes/neem.css +1 -1
  15. package/dist/css/themes/neutral.css +255 -0
  16. package/dist/css/themes/raat.css +35 -1
  17. package/dist/css/themes/stone.css +275 -0
  18. package/dist/css/themes/sutra.css +1 -1
  19. package/dist/css/themes/ujala.css +1 -1
  20. package/dist/css/themes/y2k.css +289 -0
  21. package/dist/css/tokens.css +2998 -1
  22. package/dist/dart/und_tokens.dart +11414 -320
  23. package/dist/js/contexts.js +1 -1
  24. package/dist/js/index.d.ts +583 -1
  25. package/dist/js/index.js +850 -157
  26. package/dist/json/flat/butter.dark.json +945 -0
  27. package/dist/json/flat/butter.darkMore.json +945 -0
  28. package/dist/json/flat/butter.light.json +945 -0
  29. package/dist/json/flat/butter.lightMore.json +945 -0
  30. package/dist/json/flat/chocolate.dark.json +945 -0
  31. package/dist/json/flat/chocolate.darkMore.json +945 -0
  32. package/dist/json/flat/chocolate.light.json +945 -0
  33. package/dist/json/flat/chocolate.lightMore.json +945 -0
  34. package/dist/json/flat/gothic.dark.json +945 -0
  35. package/dist/json/flat/gothic.darkMore.json +945 -0
  36. package/dist/json/flat/kesar.dark.json +207 -0
  37. package/dist/json/flat/kesar.darkMore.json +207 -0
  38. package/dist/json/flat/kesar.light.json +207 -0
  39. package/dist/json/flat/kesar.lightMore.json +207 -0
  40. package/dist/json/flat/matcha.dark.json +945 -0
  41. package/dist/json/flat/matcha.darkMore.json +945 -0
  42. package/dist/json/flat/matcha.light.json +945 -0
  43. package/dist/json/flat/matcha.lightMore.json +945 -0
  44. package/dist/json/flat/mitti.dark.json +207 -0
  45. package/dist/json/flat/mitti.darkMore.json +207 -0
  46. package/dist/json/flat/mitti.light.json +207 -0
  47. package/dist/json/flat/mitti.lightMore.json +207 -0
  48. package/dist/json/flat/nabh.dark.json +945 -0
  49. package/dist/json/flat/nabh.darkMore.json +945 -0
  50. package/dist/json/flat/nabh.light.json +945 -0
  51. package/dist/json/flat/nabh.lightMore.json +945 -0
  52. package/dist/json/flat/neem.dark.json +207 -0
  53. package/dist/json/flat/neem.darkMore.json +207 -0
  54. package/dist/json/flat/neem.light.json +207 -0
  55. package/dist/json/flat/neem.lightMore.json +207 -0
  56. package/dist/json/flat/neutral.dark.json +945 -0
  57. package/dist/json/flat/neutral.darkMore.json +945 -0
  58. package/dist/json/flat/neutral.light.json +945 -0
  59. package/dist/json/flat/neutral.lightMore.json +945 -0
  60. package/dist/json/flat/raat.dark.json +207 -0
  61. package/dist/json/flat/raat.darkMore.json +207 -0
  62. package/dist/json/flat/stone.dark.json +945 -0
  63. package/dist/json/flat/stone.darkMore.json +945 -0
  64. package/dist/json/flat/stone.light.json +945 -0
  65. package/dist/json/flat/stone.lightMore.json +945 -0
  66. package/dist/json/flat/sutra.dark.json +207 -0
  67. package/dist/json/flat/sutra.darkMore.json +207 -0
  68. package/dist/json/flat/sutra.light.json +207 -0
  69. package/dist/json/flat/sutra.lightMore.json +207 -0
  70. package/dist/json/flat/ujala.dark.json +207 -0
  71. package/dist/json/flat/ujala.darkMore.json +207 -0
  72. package/dist/json/flat/ujala.light.json +207 -0
  73. package/dist/json/flat/ujala.lightMore.json +207 -0
  74. package/dist/json/flat/y2k.dark.json +945 -0
  75. package/dist/json/flat/y2k.darkMore.json +945 -0
  76. package/dist/json/flat/y2k.light.json +945 -0
  77. package/dist/json/flat/y2k.lightMore.json +945 -0
  78. package/dist/json/nested/butter.dark.json +1177 -0
  79. package/dist/json/nested/butter.darkMore.json +1177 -0
  80. package/dist/json/nested/butter.light.json +1177 -0
  81. package/dist/json/nested/butter.lightMore.json +1177 -0
  82. package/dist/json/nested/chocolate.dark.json +1177 -0
  83. package/dist/json/nested/chocolate.darkMore.json +1177 -0
  84. package/dist/json/nested/chocolate.light.json +1177 -0
  85. package/dist/json/nested/chocolate.lightMore.json +1177 -0
  86. package/dist/json/nested/gothic.dark.json +1177 -0
  87. package/dist/json/nested/gothic.darkMore.json +1177 -0
  88. package/dist/json/nested/kesar.dark.json +295 -4
  89. package/dist/json/nested/kesar.darkMore.json +295 -4
  90. package/dist/json/nested/kesar.light.json +295 -4
  91. package/dist/json/nested/kesar.lightMore.json +295 -4
  92. package/dist/json/nested/matcha.dark.json +1177 -0
  93. package/dist/json/nested/matcha.darkMore.json +1177 -0
  94. package/dist/json/nested/matcha.light.json +1177 -0
  95. package/dist/json/nested/matcha.lightMore.json +1177 -0
  96. package/dist/json/nested/mitti.dark.json +295 -4
  97. package/dist/json/nested/mitti.darkMore.json +295 -4
  98. package/dist/json/nested/mitti.light.json +295 -4
  99. package/dist/json/nested/mitti.lightMore.json +295 -4
  100. package/dist/json/nested/nabh.dark.json +1177 -0
  101. package/dist/json/nested/nabh.darkMore.json +1177 -0
  102. package/dist/json/nested/nabh.light.json +1177 -0
  103. package/dist/json/nested/nabh.lightMore.json +1177 -0
  104. package/dist/json/nested/neem.dark.json +295 -4
  105. package/dist/json/nested/neem.darkMore.json +295 -4
  106. package/dist/json/nested/neem.light.json +295 -4
  107. package/dist/json/nested/neem.lightMore.json +295 -4
  108. package/dist/json/nested/neutral.dark.json +1177 -0
  109. package/dist/json/nested/neutral.darkMore.json +1177 -0
  110. package/dist/json/nested/neutral.light.json +1177 -0
  111. package/dist/json/nested/neutral.lightMore.json +1177 -0
  112. package/dist/json/nested/raat.dark.json +295 -4
  113. package/dist/json/nested/raat.darkMore.json +295 -4
  114. package/dist/json/nested/stone.dark.json +1177 -0
  115. package/dist/json/nested/stone.darkMore.json +1177 -0
  116. package/dist/json/nested/stone.light.json +1177 -0
  117. package/dist/json/nested/stone.lightMore.json +1177 -0
  118. package/dist/json/nested/sutra.dark.json +295 -4
  119. package/dist/json/nested/sutra.darkMore.json +295 -4
  120. package/dist/json/nested/sutra.light.json +295 -4
  121. package/dist/json/nested/sutra.lightMore.json +295 -4
  122. package/dist/json/nested/ujala.dark.json +295 -4
  123. package/dist/json/nested/ujala.darkMore.json +295 -4
  124. package/dist/json/nested/ujala.light.json +295 -4
  125. package/dist/json/nested/ujala.lightMore.json +295 -4
  126. package/dist/json/nested/y2k.dark.json +1177 -0
  127. package/dist/json/nested/y2k.darkMore.json +1177 -0
  128. package/dist/json/nested/y2k.light.json +1177 -0
  129. package/dist/json/nested/y2k.lightMore.json +1177 -0
  130. package/dist/kotlin/UndTokens.kt +15338 -2190
  131. package/dist/lib/build/formats/css.d.ts +7 -0
  132. package/dist/lib/build/formats/css.js +113 -3
  133. package/dist/lib/build/formats/dart.d.ts +0 -7
  134. package/dist/lib/build/formats/dart.js +22 -4
  135. package/dist/lib/build/formats/js.d.ts +0 -6
  136. package/dist/lib/build/formats/js.js +8 -1
  137. package/dist/lib/build/formats/kotlin.d.ts +1 -1
  138. package/dist/lib/build/formats/kotlin.js +43 -14
  139. package/dist/lib/build/formats/react-native.js +2 -1
  140. package/dist/lib/build/formats/swift.d.ts +0 -6
  141. package/dist/lib/build/formats/swift.js +78 -15
  142. package/dist/lib/build/formats/tailwind.js +22 -2
  143. package/dist/lib/build/index.js +6 -5
  144. package/dist/lib/build/native-model.d.ts +16 -0
  145. package/dist/lib/build/native-model.js +33 -0
  146. package/dist/lib/color/pairs.js +2 -1
  147. package/dist/lib/dtcg/engine.d.ts +6 -0
  148. package/dist/lib/dtcg/engine.js +21 -1
  149. package/dist/lib/source/generate.d.ts +3 -1
  150. package/dist/lib/source/generate.js +56 -7
  151. package/dist/lib/themes/aa.d.ts +44 -0
  152. package/dist/lib/themes/aa.js +168 -0
  153. package/dist/lib/themes/definitions.d.ts +21 -10
  154. package/dist/lib/themes/definitions.js +181 -5
  155. package/dist/lib/themes/generate.d.ts +47 -0
  156. package/dist/lib/themes/generate.js +329 -0
  157. package/dist/lib/themes/ported-map.d.ts +59 -0
  158. package/dist/lib/themes/ported-map.js +618 -0
  159. package/dist/lib/themes/ported.d.ts +10 -0
  160. package/dist/lib/themes/ported.js +1764 -0
  161. package/dist/react-native/index.d.ts +132 -1
  162. package/dist/react-native/tokens.js +16487 -1656
  163. package/dist/scss/_variables.scss +346 -138
  164. package/dist/scss/_vars.scss +208 -1
  165. package/dist/scss/butter.dark.scss +946 -0
  166. package/dist/scss/butter.darkMore.scss +946 -0
  167. package/dist/scss/butter.light.scss +946 -0
  168. package/dist/scss/butter.lightMore.scss +946 -0
  169. package/dist/scss/chocolate.dark.scss +946 -0
  170. package/dist/scss/chocolate.darkMore.scss +946 -0
  171. package/dist/scss/chocolate.light.scss +946 -0
  172. package/dist/scss/chocolate.lightMore.scss +946 -0
  173. package/dist/scss/gothic.dark.scss +946 -0
  174. package/dist/scss/gothic.darkMore.scss +946 -0
  175. package/dist/scss/kesar.dark.scss +207 -0
  176. package/dist/scss/kesar.darkMore.scss +207 -0
  177. package/dist/scss/kesar.light.scss +207 -0
  178. package/dist/scss/kesar.lightMore.scss +207 -0
  179. package/dist/scss/matcha.dark.scss +946 -0
  180. package/dist/scss/matcha.darkMore.scss +946 -0
  181. package/dist/scss/matcha.light.scss +946 -0
  182. package/dist/scss/matcha.lightMore.scss +946 -0
  183. package/dist/scss/mitti.dark.scss +207 -0
  184. package/dist/scss/mitti.darkMore.scss +207 -0
  185. package/dist/scss/mitti.light.scss +207 -0
  186. package/dist/scss/mitti.lightMore.scss +207 -0
  187. package/dist/scss/nabh.dark.scss +946 -0
  188. package/dist/scss/nabh.darkMore.scss +946 -0
  189. package/dist/scss/nabh.light.scss +946 -0
  190. package/dist/scss/nabh.lightMore.scss +946 -0
  191. package/dist/scss/neem.dark.scss +207 -0
  192. package/dist/scss/neem.darkMore.scss +207 -0
  193. package/dist/scss/neem.light.scss +207 -0
  194. package/dist/scss/neem.lightMore.scss +207 -0
  195. package/dist/scss/neutral.dark.scss +946 -0
  196. package/dist/scss/neutral.darkMore.scss +946 -0
  197. package/dist/scss/neutral.light.scss +946 -0
  198. package/dist/scss/neutral.lightMore.scss +946 -0
  199. package/dist/scss/raat.dark.scss +207 -0
  200. package/dist/scss/raat.darkMore.scss +207 -0
  201. package/dist/scss/stone.dark.scss +946 -0
  202. package/dist/scss/stone.darkMore.scss +946 -0
  203. package/dist/scss/stone.light.scss +946 -0
  204. package/dist/scss/stone.lightMore.scss +946 -0
  205. package/dist/scss/sutra.dark.scss +207 -0
  206. package/dist/scss/sutra.darkMore.scss +207 -0
  207. package/dist/scss/sutra.light.scss +207 -0
  208. package/dist/scss/sutra.lightMore.scss +207 -0
  209. package/dist/scss/ujala.dark.scss +207 -0
  210. package/dist/scss/ujala.darkMore.scss +207 -0
  211. package/dist/scss/ujala.light.scss +207 -0
  212. package/dist/scss/ujala.lightMore.scss +207 -0
  213. package/dist/scss/y2k.dark.scss +946 -0
  214. package/dist/scss/y2k.darkMore.scss +946 -0
  215. package/dist/scss/y2k.light.scss +946 -0
  216. package/dist/scss/y2k.lightMore.scss +946 -0
  217. package/dist/swift/UndTokens.swift +6061 -3432
  218. package/dist/tailwind/und.css +198 -2
  219. package/package.json +5 -1
  220. package/tokens/modes/dark.tokens.json +241 -0
  221. package/tokens/modes/light.tokens.json +246 -0
  222. package/tokens/palettes/butter.dark.tokens.json +887 -0
  223. package/tokens/palettes/butter.light.tokens.json +872 -0
  224. package/tokens/palettes/chocolate.dark.tokens.json +917 -0
  225. package/tokens/palettes/chocolate.light.tokens.json +902 -0
  226. package/tokens/palettes/gothic.dark.tokens.json +831 -0
  227. package/tokens/palettes/matcha.dark.tokens.json +932 -0
  228. package/tokens/palettes/matcha.light.tokens.json +907 -0
  229. package/tokens/palettes/nabh.dark.tokens.json +498 -0
  230. package/tokens/palettes/nabh.light.tokens.json +498 -0
  231. package/tokens/palettes/neutral.dark.tokens.json +837 -0
  232. package/tokens/palettes/neutral.light.tokens.json +817 -0
  233. package/tokens/palettes/stone.dark.tokens.json +877 -0
  234. package/tokens/palettes/stone.light.tokens.json +877 -0
  235. package/tokens/palettes/y2k.dark.tokens.json +877 -0
  236. package/tokens/palettes/y2k.light.tokens.json +877 -0
  237. package/tokens/semantic/roles.tokens.json +521 -0
  238. package/tokens/themes/butter.tokens.json +254 -0
  239. package/tokens/themes/chocolate.tokens.json +214 -0
  240. package/tokens/themes/gothic.tokens.json +249 -0
  241. package/tokens/themes/matcha.tokens.json +258 -0
  242. package/tokens/themes/nabh.tokens.json +174 -0
  243. package/tokens/themes/neutral.tokens.json +234 -0
  244. package/tokens/themes/stone.tokens.json +254 -0
  245. package/tokens/themes/ujala.tokens.json +1 -1
  246. package/tokens/themes/y2k.tokens.json +264 -0
  247. package/tokens/und.resolver.json +40 -4
@@ -25,6 +25,33 @@ export function stepName(key, numericPrefix = 's') {
25
25
  return `${numericPrefix}${key.replace(/_/g, 'p')}`;
26
26
  return camel(key);
27
27
  }
28
+ /**
29
+ * Most roles one group may hold. Kotlin `Color` is a `long` (2 JVM parameter slots) and a JVM method
30
+ * takes at most 255 slots, so a data class constructor must stay well below 127 colour parameters.
31
+ */
32
+ export const MAX_ROLES_PER_GROUP = 100;
33
+ /**
34
+ * Colour roles grouped by the first token path segment (bg, fg, status, data, ...). Native outputs
35
+ * store roles per group so no generated class or method grows with the total role count.
36
+ */
37
+ export function colorRoleGroups(roles) {
38
+ const groups = new Map();
39
+ for (const [flat, path] of roles) {
40
+ const [head, ...rest] = path.split('.');
41
+ if (!head || rest.length === 0)
42
+ throw new Error(`Colour role ${path} needs a group segment`);
43
+ const member = camel(rest.join('.'));
44
+ const list = groups.get(head) ?? [];
45
+ if (list.some((r) => r.member === member))
46
+ throw new Error(`Duplicate colour member ${path}`);
47
+ list.push({ flat, member, path });
48
+ groups.set(head, list);
49
+ }
50
+ for (const [g, list] of groups)
51
+ if (list.length > MAX_ROLES_PER_GROUP)
52
+ throw new Error(`Colour group ${g} has ${list.length} roles (max ${MAX_ROLES_PER_GROUP})`);
53
+ return [...groups];
54
+ }
28
55
  const COLOR_ROOTS = [
29
56
  'bg',
30
57
  'fg',
@@ -36,6 +63,12 @@ const COLOR_ROOTS = [
36
63
  'dataviz',
37
64
  'selection',
38
65
  'material',
66
+ 'icon',
67
+ 'tone',
68
+ 'data',
69
+ 'syntax',
70
+ 'tint',
71
+ 'elevation',
39
72
  ];
40
73
  function colorRoles(ctx) {
41
74
  return [...ctx.tokens.values()]
@@ -41,7 +41,8 @@ export const PAIRS = [
41
41
  // Non-text UI (1.4.11 and focus, 3:1)
42
42
  ...on('border.control', [...SURFACES, 'bg.raised', 'bg.muted'], 'ui', 'input/checkbox boundary'),
43
43
  ...on('focus.ring', [...SURFACES, 'bg.raised', 'bg.muted'], 'ui', 'focus indicator'),
44
- ...on('status.danger.solid', ['bg.canvas', 'bg.surface'], 'ui', 'invalid input border'),
44
+ // Invalid inputs draw their boundary with the danger text colour.
45
+ ...on('status.danger.fg', ['bg.canvas', 'bg.surface'], 'ui', 'invalid input border'),
45
46
  ...on('fg.on-accent', ['accent.solid'], 'ui', 'checkmark on checked box'),
46
47
  ];
47
48
  function color(ctx, path) {
@@ -54,6 +54,12 @@ export declare class TokenFiles {
54
54
  }
55
55
  /** Flattens one file into tokens, applying group `$type` inheritance. */
56
56
  export declare function flattenFile(doc: Obj, source: string, errors?: string[]): FlatToken[];
57
+ /**
58
+ * The `palette` modifier is derived, never chosen: `<theme>-<mode>` when that
59
+ * context exists, else the theme's only palette context (dark-only themes),
60
+ * else `none`.
61
+ */
62
+ export declare function derivePalette(resolver: ResolverDoc, input: ResolverInput): string | undefined;
57
63
  export declare function contextSources(resolver: ResolverDoc, input?: ResolverInput): string[];
58
64
  /** Merge files in order; a later token replaces an earlier one with the same path. */
59
65
  export declare function mergeFiles(files: TokenFiles, sources: string[], errors?: string[]): Map<string, FlatToken>;
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import { readFileSync } from 'node:fs';
7
7
  import { join } from 'node:path';
8
+ import { DEFAULT_THEME } from '../themes/definitions.js';
8
9
  import { COLOR_SPACES, DTCG_TYPES, isReference, refPath } from './types.js';
9
10
  const NAME_FORBIDDEN = /[{}.]/;
10
11
  export class TokenError extends Error {
@@ -88,9 +89,28 @@ export function flattenFile(doc, source, errors = []) {
88
89
  return out;
89
90
  }
90
91
  // ---------------------------------------------------------------- resolver
92
+ /**
93
+ * The `palette` modifier is derived, never chosen: `<theme>-<mode>` when that
94
+ * context exists, else the theme's only palette context (dark-only themes),
95
+ * else `none`.
96
+ */
97
+ export function derivePalette(resolver, input) {
98
+ const mod = resolver.modifiers.palette;
99
+ if (!mod)
100
+ return undefined;
101
+ const theme = input.theme ?? resolver.modifiers.theme?.default;
102
+ const mode = input.mode ?? resolver.modifiers.mode?.default;
103
+ const exact = `${theme}-${mode}`;
104
+ if (mod.contexts[exact])
105
+ return exact;
106
+ const own = Object.keys(mod.contexts).filter((k) => k.startsWith(`${theme}-`));
107
+ return own.length === 1 ? own[0] : (mod.default ?? 'none');
108
+ }
91
109
  export function contextSources(resolver, input = {}) {
92
110
  if (resolver.version !== '2025.10')
93
111
  throw new TokenError(`Unsupported resolver version ${resolver.version}`);
112
+ if (input.palette === undefined && resolver.modifiers.palette)
113
+ input = { ...input, palette: derivePalette(resolver, input) };
94
114
  const files = [];
95
115
  for (const entry of resolver.resolutionOrder) {
96
116
  const ref = entry.$ref;
@@ -364,7 +384,7 @@ export function resolveTokens(merged) {
364
384
  }
365
385
  export const DEFAULT_INPUT = {
366
386
  mode: 'light',
367
- theme: 'ujala',
387
+ theme: DEFAULT_THEME,
368
388
  contrast: 'standard',
369
389
  density: 'auto',
370
390
  transparency: 'full',
@@ -16,9 +16,11 @@ export interface GlassDecision {
16
16
  alpha: number;
17
17
  }
18
18
  export declare const RESOLVER_PATH = "und.resolver.json";
19
- export declare const BASE_SOURCES: readonly ["primitives/dimension.tokens.json", "primitives/typography.tokens.json", "primitives/motion.tokens.json", "primitives/spring.tokens.json", "semantic/scale.tokens.json", "semantic/color.tokens.json", "semantic/layout.tokens.json", "semantic/typography.tokens.json", "semantic/motion.tokens.json", "semantic/bridge.tokens.json"];
19
+ export declare const BASE_SOURCES: readonly ["primitives/dimension.tokens.json", "primitives/typography.tokens.json", "primitives/motion.tokens.json", "primitives/spring.tokens.json", "semantic/scale.tokens.json", "semantic/color.tokens.json", "semantic/roles.tokens.json", "semantic/layout.tokens.json", "semantic/typography.tokens.json", "semantic/motion.tokens.json", "semantic/bridge.tokens.json"];
20
20
  export declare const MODE_SOURCES: Record<Mode, readonly string[]>;
21
21
  export declare function themeSources(theme: ThemeDefinition): string[];
22
+ /** Palette files of a theme, one per mode it supports. */
23
+ export declare function paletteSources(theme: ThemeDefinition): Record<string, string>;
22
24
  export interface GeneratedSource {
23
25
  files: Record<string, Obj>;
24
26
  scales: GeneratedScale[];
@@ -15,7 +15,8 @@ import { MODES, STEPS, generateScale } from '../color/palette.js';
15
15
  import { ALL_SCALES } from '../color/scales.js';
16
16
  import { EXT } from '../dtcg/types.js';
17
17
  import { SPRINGS, springPhysics, springToCubicBezier, springToLinear } from '../motion/spring.js';
18
- import { THEMES } from '../themes/definitions.js';
18
+ import { DEFAULT_THEME, THEMES } from '../themes/definitions.js';
19
+ import { newLiteralRoles, paletteEntries, portedThemeOverrides, rolesFile, } from '../themes/ported-map.js';
19
20
  export function oklchColor(f, alpha = 1) {
20
21
  const value = { colorSpace: 'oklch', components: [f.p3.l, f.p3.c, f.p3.h] };
21
22
  if (alpha !== 1)
@@ -241,7 +242,7 @@ function modeFile(mode, scales, decisions) {
241
242
  $description: 'Inset 1px specular edge.',
242
243
  },
243
244
  };
244
- return {
245
+ const doc = {
245
246
  $description: `${mode === 'light' ? 'Light' : 'Dark'} mode semantic values that are not plain scale references.`,
246
247
  bg: {
247
248
  $type: 'color',
@@ -267,6 +268,10 @@ function modeFile(mode, scales, decisions) {
267
268
  material,
268
269
  shadow: shadows(mode),
269
270
  };
271
+ // Roles added with the default theme whose value differs per mode (tones, data, hover tint, inset rings).
272
+ for (const [path, value, type] of newLiteralRoles().perMode[mode])
273
+ setPath(doc, path, { $type: type, $value: value });
274
+ return doc;
270
275
  }
271
276
  // ---------------------------------------------------------------- scale aliases and themes
272
277
  function scaleAliases(accent, neutral, accentText) {
@@ -349,11 +354,18 @@ function themeFile(theme) {
349
354
  heading: { $value: theme.typeface.heading },
350
355
  display: { $value: theme.typeface.display },
351
356
  code: { $value: theme.typeface.code },
357
+ ...(theme.fonts ? { $extensions: { [EXT]: { webFonts: theme.fonts } } } : {}),
352
358
  });
353
359
  if (theme.focus === 'neutral')
354
360
  setPath(doc, 'focus.ring', { $type: 'color', $value: '{scale.neutral.12}' });
355
361
  for (const [path, value] of Object.entries(theme.overrides ?? {}))
356
362
  setPath(doc, path, { $type: 'color', $value: value });
363
+ if (theme.palette) {
364
+ for (const [path, value] of portedThemeOverrides(theme.palette))
365
+ setPath(doc, path, value);
366
+ // The source's "move" curve is its standard decelerating curve.
367
+ setPath(doc, 'motion.ease.move', { $type: 'cubicBezier', $value: '{ease.standard}' });
368
+ }
357
369
  if (theme.glass === 'off') {
358
370
  for (const m of ['thin', 'regular', 'thick', 'chrome']) {
359
371
  setPath(doc, `material.${m}`, {
@@ -382,6 +394,7 @@ export const BASE_SOURCES = [
382
394
  'primitives/spring.tokens.json',
383
395
  'semantic/scale.tokens.json',
384
396
  'semantic/color.tokens.json',
397
+ 'semantic/roles.tokens.json',
385
398
  'semantic/layout.tokens.json',
386
399
  'semantic/typography.tokens.json',
387
400
  'semantic/motion.tokens.json',
@@ -398,13 +411,27 @@ export function themeSources(theme) {
398
411
  sources.push('density/compact.tokens.json');
399
412
  return sources;
400
413
  }
414
+ /** Palette files of a theme, one per mode it supports. */
415
+ export function paletteSources(theme) {
416
+ if (!theme.palette)
417
+ return {};
418
+ return Object.fromEntries(theme.modes.map((m) => [`${theme.name}-${m}`, `palettes/${theme.name}.${m}.tokens.json`]));
419
+ }
420
+ function paletteFile(theme, mode) {
421
+ const doc = {
422
+ $description: `${theme.label}, ${mode} mode: literal colours and shadows (ported values; see src/themes/ported-map.ts).`,
423
+ };
424
+ for (const [path, type, value] of paletteEntries(theme.palette, mode))
425
+ setPath(doc, path, { $type: type, $value: value });
426
+ return doc;
427
+ }
401
428
  function resolverFile() {
402
429
  const ref = (p) => ({ $ref: p });
403
430
  return {
404
431
  $schema: 'https://www.designtokens.org/schemas/2025.10/resolver.json',
405
432
  name: 'UND UI tokens',
406
433
  version: '2025.10',
407
- description: 'Resolution order: base, mode, theme, contrast, density, transparency, motion. Theme overrides are mode- and contrast-independent; Raat (dark-only) pulls in the dark mode sources itself; Sutra pulls in compact density as its default.',
434
+ description: `Resolution order: base, mode, theme, palette, contrast, density, transparency, motion. Theme overrides are mode- and contrast-independent; Raat and Gothic (dark-only) pull in the dark mode sources themselves; Sutra pulls in compact density as its default. The palette input is derived, not chosen: "<theme>-<mode>" when that context exists, else the theme's only palette context (dark-only themes), else "none".`,
408
435
  sets: {
409
436
  base: { description: 'Primitives and the semantic layer.', sources: BASE_SOURCES.map(ref) },
410
437
  },
@@ -415,9 +442,17 @@ function resolverFile() {
415
442
  default: 'light',
416
443
  },
417
444
  theme: {
418
- description: 'The six UND UI themes.',
445
+ description: 'The UND UI themes.',
419
446
  contexts: Object.fromEntries(THEMES.map((t) => [t.name, themeSources(t).map(ref)])),
420
- default: 'ujala',
447
+ default: DEFAULT_THEME,
448
+ },
449
+ palette: {
450
+ description: 'Literal per-mode values of palette themes. Derived from theme and mode (see the resolver description).',
451
+ contexts: {
452
+ none: [],
453
+ ...Object.fromEntries(THEMES.flatMap((t) => Object.entries(paletteSources(t))).map(([k, f]) => [k, [ref(f)]])),
454
+ },
455
+ default: 'none',
421
456
  },
422
457
  contrast: {
423
458
  description: 'prefers-contrast: more / Increase Contrast.',
@@ -445,7 +480,16 @@ function resolverFile() {
445
480
  default: 'full',
446
481
  },
447
482
  },
448
- resolutionOrder: ['base', 'mode', 'theme', 'contrast', 'density', 'transparency', 'motion'].map((n, i) => ref(i === 0 ? '#/sets/base' : `#/modifiers/${n}`)),
483
+ resolutionOrder: [
484
+ 'base',
485
+ 'mode',
486
+ 'theme',
487
+ 'palette',
488
+ 'contrast',
489
+ 'density',
490
+ 'transparency',
491
+ 'motion',
492
+ ].map((n, i) => ref(i === 0 ? '#/sets/base' : `#/modifiers/${n}`)),
449
493
  };
450
494
  }
451
495
  export function generateSource() {
@@ -461,8 +505,13 @@ export function generateSource() {
461
505
  $description: 'Default (Ujala) scale aliases. Themes repoint these.',
462
506
  ...scaleAliases('indigo', 'neutral', 'indigo'),
463
507
  };
464
- for (const theme of THEMES)
508
+ files['semantic/roles.tokens.json'] = rolesFile(newLiteralRoles().constants);
509
+ for (const theme of THEMES) {
465
510
  files[`themes/${theme.name}.tokens.json`] = themeFile(theme);
511
+ if (theme.palette)
512
+ for (const m of theme.modes)
513
+ files[`palettes/${theme.name}.${m}.tokens.json`] = paletteFile(theme, m);
514
+ }
466
515
  files[RESOLVER_PATH] = resolverFile();
467
516
  return { files, scales, glass };
468
517
  }
@@ -0,0 +1,44 @@
1
+ export interface Rgba {
2
+ r: number;
3
+ g: number;
4
+ b: number;
5
+ a: number;
6
+ }
7
+ export declare const hexOf: (c: Rgba) => string;
8
+ export declare function rgba(hex: string, a?: number): Rgba;
9
+ /** Source-over compositing (sRGB, like browsers). */
10
+ export declare function over(top: Rgba, bottom: Rgba): Rgba;
11
+ /** `color-mix(in srgb, a, b p)`. */
12
+ export declare function mix(a: Rgba, b: Rgba, p: number): Rgba;
13
+ /** Opaque colour as seen over a backdrop. */
14
+ export declare const flat: (c: Rgba, backdrop: Rgba) => Rgba;
15
+ export declare const contrast: (a: Rgba, b: Rgba) => number;
16
+ /** Lowest contrast of `fg` against every backdrop (translucent fg composited per backdrop). */
17
+ export declare function minContrast(fg: Rgba, bgs: readonly Rgba[]): number;
18
+ /**
19
+ * The colour closest to `fg` (in OKLCH lightness, hue and chroma kept) that reaches
20
+ * `min` against every opaque backdrop. Returns `fg` unchanged when it already passes;
21
+ * falls back to black or white, whichever does better, when no lightness passes.
22
+ */
23
+ export declare function nudge(fg: Rgba, bgs: readonly Rgba[], min: number): Rgba;
24
+ /**
25
+ * Mixes a background toward `toward` (the page) until `fg` reads on it. Used when a
26
+ * pastel fill sits on the far side of the text from the page, so no text colour can
27
+ * pass on both.
28
+ */
29
+ export declare function soften(bg: Rgba, toward: Rgba, fg: Rgba, min: number): Rgba;
30
+ /** Hover fill for a solid: 15% (then 7.5%) toward the mode's tint, the other way if the label would drop below AA. */
31
+ export declare function solidHover(solid: Rgba, on: Rgba, mode: 'light' | 'dark'): Rgba;
32
+ /** Literal colour roles of a palette (UND paths), before and after AA repair. */
33
+ export type RoleColors = Map<string, Rgba>;
34
+ /**
35
+ * Repairs a palette in place so every documented pair passes WCAG 2.2 AA. Needs
36
+ * bg.canvas, bg.surface, bg.subtle, bg.raised, bg.muted, fg.default, fg.muted,
37
+ * fg.on-accent, accent.solid, accent.bg, accent.fg, border.default, bg.inverse,
38
+ * fg.inverse and status.<s>.{solid,bg,fg,fg-strong,on-solid}; sets the derived
39
+ * roles (hover fills, fg.subtle, border.control, focus.ring, link.default).
40
+ * `overlayHover`/`overlayPressed` are the translucent hover and press layers.
41
+ */
42
+ export declare function repairPalette(c: RoleColors, mode: 'light' | 'dark', overlayHover: Rgba, overlayPressed: Rgba): void;
43
+ /** Every repaired role must pass; returns the failures (for tests). */
44
+ export declare function auditPalette(c: RoleColors): string[];
@@ -0,0 +1,168 @@
1
+ /**
2
+ * WCAG 2.2 AA repair for literal palettes. Ported and generated themes keep their
3
+ * colours where they already pass; where a documented pair (src/color/pairs.ts)
4
+ * falls short, the foreground's OKLCH lightness moves the shortest distance that
5
+ * passes, keeping hue and chroma. Used by the palette files and by the theme
6
+ * generator (`@und-ui/tokens/generate`).
7
+ */
8
+ import { wcagContrast } from '../color/contrast.js';
9
+ import { hexToOklch, hexToRgb, oklchToHex, rgbToHex } from '../color/convert.js';
10
+ export const hexOf = (c) => rgbToHex([c.r, c.g, c.b]);
11
+ export function rgba(hex, a = 1) {
12
+ const [r, g, b] = hexToRgb(hex);
13
+ return { r, g, b, a };
14
+ }
15
+ /** Source-over compositing (sRGB, like browsers). */
16
+ export function over(top, bottom) {
17
+ const a = top.a + bottom.a * (1 - top.a);
18
+ if (a === 0)
19
+ return { r: 0, g: 0, b: 0, a: 0 };
20
+ const ch = (t, b) => (t * top.a + b * bottom.a * (1 - top.a)) / a;
21
+ return { r: ch(top.r, bottom.r), g: ch(top.g, bottom.g), b: ch(top.b, bottom.b), a };
22
+ }
23
+ /** `color-mix(in srgb, a, b p)`. */
24
+ export function mix(a, b, p) {
25
+ const ch = (x, y) => x * (1 - p) + y * p;
26
+ return { r: ch(a.r, b.r), g: ch(a.g, b.g), b: ch(a.b, b.b), a: ch(a.a, b.a) };
27
+ }
28
+ /** Opaque colour as seen over a backdrop. */
29
+ export const flat = (c, backdrop) => (c.a < 1 ? over(c, backdrop) : c);
30
+ export const contrast = (a, b) => wcagContrast(hexOf(a), hexOf(b));
31
+ /** Lowest contrast of `fg` against every backdrop (translucent fg composited per backdrop). */
32
+ export function minContrast(fg, bgs) {
33
+ return Math.min(...bgs.map((bg) => contrast(flat(fg, bg), bg)));
34
+ }
35
+ /**
36
+ * The colour closest to `fg` (in OKLCH lightness, hue and chroma kept) that reaches
37
+ * `min` against every opaque backdrop. Returns `fg` unchanged when it already passes;
38
+ * falls back to black or white, whichever does better, when no lightness passes.
39
+ */
40
+ export function nudge(fg, bgs, min) {
41
+ if (minContrast(fg, bgs) >= min)
42
+ return fg;
43
+ const base = hexToOklch(hexOf(flat(fg, bgs[0])));
44
+ // A tiny margin keeps the hex rounding of the result on the passing side.
45
+ const target = min + 0.02;
46
+ for (let d = 0.005; d <= 1; d += 0.005) {
47
+ for (const l of [base.l - d, base.l + d]) {
48
+ if (l < 0 || l > 1)
49
+ continue;
50
+ const c = rgba(oklchToHex({ l, c: base.c, h: base.h }));
51
+ if (minContrast(c, bgs) >= target)
52
+ return c;
53
+ }
54
+ }
55
+ const black = rgba('#000000');
56
+ const white = rgba('#ffffff');
57
+ return minContrast(black, bgs) >= minContrast(white, bgs) ? black : white;
58
+ }
59
+ /**
60
+ * Mixes a background toward `toward` (the page) until `fg` reads on it. Used when a
61
+ * pastel fill sits on the far side of the text from the page, so no text colour can
62
+ * pass on both.
63
+ */
64
+ export function soften(bg, toward, fg, min) {
65
+ for (let p = 0; p <= 1.0001; p += 0.05) {
66
+ const c = mix(flat(bg, toward), toward, p);
67
+ if (contrast(fg, c) >= min + 0.02)
68
+ return c;
69
+ }
70
+ return toward;
71
+ }
72
+ /** Hover fill for a solid: 15% (then 7.5%) toward the mode's tint, the other way if the label would drop below AA. */
73
+ export function solidHover(solid, on, mode) {
74
+ const black = rgba('#000000');
75
+ const white = rgba('#ffffff');
76
+ const tints = mode === 'light' ? [black, white] : [white, black];
77
+ for (const p of [0.15, 0.075])
78
+ for (const t of tints) {
79
+ const c = mix(solid, t, p);
80
+ if (contrast(c, on) >= 4.5)
81
+ return c;
82
+ }
83
+ return solid;
84
+ }
85
+ const STATUSES = ['success', 'warning', 'danger', 'info'];
86
+ /**
87
+ * Repairs a palette in place so every documented pair passes WCAG 2.2 AA. Needs
88
+ * bg.canvas, bg.surface, bg.subtle, bg.raised, bg.muted, fg.default, fg.muted,
89
+ * fg.on-accent, accent.solid, accent.bg, accent.fg, border.default, bg.inverse,
90
+ * fg.inverse and status.<s>.{solid,bg,fg,fg-strong,on-solid}; sets the derived
91
+ * roles (hover fills, fg.subtle, border.control, focus.ring, link.default).
92
+ * `overlayHover`/`overlayPressed` are the translucent hover and press layers.
93
+ */
94
+ export function repairPalette(c, mode, overlayHover, overlayPressed) {
95
+ const get = (p) => {
96
+ const v = c.get(p);
97
+ if (!v)
98
+ throw new Error(`repairPalette: ${p} missing`);
99
+ return v;
100
+ };
101
+ const canvas = get('bg.canvas');
102
+ const on = (p) => flat(get(p), canvas);
103
+ const surfaces = () => ['bg.canvas', 'bg.surface', 'bg.subtle'].map(on);
104
+ const withRaised = () => [...surfaces(), on('bg.raised')];
105
+ const set = (p, v) => c.set(p, v);
106
+ const fix = (p, bgs, min) => set(p, nudge(get(p), bgs, min));
107
+ const muted = on('bg.muted');
108
+ set('bg.muted-hover', over(overlayHover, get('bg.muted')));
109
+ set('bg.muted-active', over(overlayPressed, get('bg.muted')));
110
+ fix('fg.default', [...withRaised(), muted, on('bg.muted-hover'), on('bg.muted-active')], 4.5);
111
+ fix('fg.muted', [...withRaised(), muted], 4.5);
112
+ // Accent: the solid carries its label, the text reads on every surface and on the tint.
113
+ set('accent.solid', nudge(get('accent.solid'), [get('fg.on-accent')], 4.5));
114
+ set('accent.solid-hover', solidHover(get('accent.solid'), get('fg.on-accent'), mode));
115
+ set('accent.bg-hover', over(overlayHover, get('accent.bg')));
116
+ set('accent.bg-active', over(overlayPressed, get('accent.bg')));
117
+ fix('accent.fg', [...withRaised(), on('accent.bg')], 4.5);
118
+ set('link.default', get('accent.fg'));
119
+ fix('accent.fg-strong', ['accent.bg', 'accent.bg-hover', 'accent.bg-active'].map(on), 4.5);
120
+ for (const s of STATUSES) {
121
+ const k = (r) => `status.${s}.${r}`;
122
+ set(k('solid'), nudge(get(k('solid')), [get(k('on-solid'))], 4.5));
123
+ set(k('solid-hover'), solidHover(get(k('solid')), get(k('on-solid')), mode));
124
+ fix(k('fg'), surfaces(), 4.5);
125
+ // The text must also read on the status tint: try the text first, then soften the tint.
126
+ const fg = nudge(get(k('fg')), [...surfaces(), on(k('bg'))], 4.5);
127
+ if (minContrast(fg, [...surfaces(), on(k('bg'))]) >= 4.5)
128
+ set(k('fg'), fg);
129
+ else
130
+ set(k('bg'), soften(get(k('bg')), canvas, get(k('fg')), 4.5));
131
+ set(k('bg-hover'), over(overlayHover, flat(get(k('bg')), canvas)));
132
+ fix(k('fg-strong'), [on(k('bg')), on(k('bg-hover'))], 4.5);
133
+ }
134
+ fix('fg.inverse', [on('bg.inverse')], 4.5);
135
+ // Placeholder/meta text sits between fg.muted and the page.
136
+ set('fg.subtle', nudge(mix(get('fg.muted'), canvas, 0.3), ['bg.canvas', 'bg.surface'].map(on), 3));
137
+ set('border.control', nudge(on('border.default'), [...withRaised(), muted], 3));
138
+ set('focus.ring', nudge(get('accent.solid'), [...withRaised(), muted], 3));
139
+ }
140
+ /** Every repaired role must pass; returns the failures (for tests). */
141
+ export function auditPalette(c) {
142
+ const canvas = c.get('bg.canvas');
143
+ const on = (p) => flat(c.get(p), canvas);
144
+ const out = [];
145
+ const check = (fg, bgs, min) => {
146
+ for (const bg of bgs) {
147
+ const r = contrast(flat(c.get(fg), on(bg)), on(bg));
148
+ if (r < min)
149
+ out.push(`${fg} on ${bg} = ${r.toFixed(2)} < ${min}`);
150
+ }
151
+ };
152
+ const S = ['bg.canvas', 'bg.surface', 'bg.subtle'];
153
+ check('fg.default', [...S, 'bg.raised', 'bg.muted', 'bg.muted-hover', 'bg.muted-active'], 4.5);
154
+ check('fg.muted', [...S, 'bg.raised', 'bg.muted'], 4.5);
155
+ check('fg.on-accent', ['accent.solid', 'accent.solid-hover'], 4.5);
156
+ check('fg.inverse', ['bg.inverse'], 4.5);
157
+ check('accent.fg', [...S, 'bg.raised', 'accent.bg'], 4.5);
158
+ check('accent.fg-strong', ['accent.bg', 'accent.bg-hover', 'accent.bg-active'], 4.5);
159
+ for (const s of STATUSES) {
160
+ check(`status.${s}.fg`, [...S, `status.${s}.bg`], 4.5);
161
+ check(`status.${s}.fg-strong`, [`status.${s}.bg`, `status.${s}.bg-hover`], 4.5);
162
+ check(`status.${s}.on-solid`, [`status.${s}.solid`, `status.${s}.solid-hover`], 4.5);
163
+ }
164
+ check('fg.subtle', ['bg.canvas', 'bg.surface'], 3);
165
+ check('border.control', [...S, 'bg.raised', 'bg.muted'], 3);
166
+ check('focus.ring', [...S, 'bg.raised', 'bg.muted'], 3);
167
+ return out;
168
+ }
@@ -1,14 +1,20 @@
1
1
  /**
2
- * The six UND UI themes (report section 7).
2
+ * The UND UI themes: the default (Nabh), the six original themes (report
3
+ * section 7) and the seven ported themes (Neutral, Stone, Butter, Chocolate,
4
+ * Gothic, Matcha, Y2K).
3
5
  *
4
6
  * A theme is a small seed object; the generator turns it into a DTCG override
5
7
  * file (tokens/themes/<name>.tokens.json). Theme overrides are deliberately
6
8
  * mode- and contrast-independent (they point at scale aliases, which the mode
7
9
  * sources resolve), so one resolver order works for every combination:
8
- * base -> mode -> theme -> contrast -> density -> transparency -> motion.
9
- * Raat is dark-only: its theme context pulls in the dark mode sources itself.
10
+ * base -> mode -> theme -> palette -> contrast -> density -> transparency -> motion.
11
+ * Raat and Gothic are dark-only: their theme context pulls in the dark mode sources itself.
12
+ *
13
+ * Palette themes (Nabh and the ported themes) also carry literal light and dark
14
+ * colours, shadows and the like. Those live in tokens/palettes/<name>.<mode>.tokens.json
15
+ * and are selected by the `palette` modifier, whose input is derived from theme and mode.
10
16
  */
11
- export type ThemeName = 'ujala' | 'kesar' | 'neem' | 'mitti' | 'raat' | 'sutra';
17
+ export type ThemeName = 'nabh' | 'ujala' | 'kesar' | 'neem' | 'mitti' | 'raat' | 'sutra' | 'neutral' | 'stone' | 'butter' | 'chocolate' | 'gothic' | 'matcha' | 'y2k';
12
18
  export type Character = 'crisp' | 'standard' | 'expressive';
13
19
  export type Glass = 'chrome' | 'on' | 'off';
14
20
  export interface ThemeDefinition {
@@ -27,17 +33,22 @@ export interface ThemeDefinition {
27
33
  character: Character;
28
34
  density: 'comfortable' | 'compact';
29
35
  glass: Glass;
30
- typeface: {
31
- body: string;
32
- heading: string;
33
- display: string;
34
- code: string;
35
- };
36
+ /** References (`{font.sans}`) or literal font stacks. */
37
+ typeface: Record<'body' | 'heading' | 'display' | 'code', string | readonly string[]>;
36
38
  /** Focus ring source. Default `accent` (accent step 11). */
37
39
  focus?: 'accent' | 'neutral';
38
40
  /** Extra semantic overrides (values are references). */
39
41
  overrides?: Record<string, string>;
42
+ /**
43
+ * Key of a ported source palette in src/themes/ported.ts. A palette theme gets
44
+ * literal light and dark values for its colour roles, shadows, radii, type
45
+ * scale and durations (see src/themes/ported-map.ts).
46
+ */
47
+ palette?: string;
48
+ /** Web fonts the theme needs: `@und-ui/fonts/themes/<name>.css` loads exactly these families. */
49
+ fonts?: readonly string[];
40
50
  }
41
51
  export declare const THEMES: readonly ThemeDefinition[];
52
+ /** Un-themed pages get this theme. */
42
53
  export declare const DEFAULT_THEME: ThemeName;
43
54
  export declare function themeByName(name: ThemeName): ThemeDefinition;