@und-ui/tokens 0.0.0-stage → 0.2.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.
Files changed (172) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +345 -2
  3. package/dist/android/values/und_colors.xml +91 -0
  4. package/dist/android/values/und_dimens.xml +93 -0
  5. package/dist/android/values-night/und_colors.xml +91 -0
  6. package/dist/css/base.css +2335 -0
  7. package/dist/css/motion.css +223 -0
  8. package/dist/css/themes/kesar.css +68 -0
  9. package/dist/css/themes/mitti.css +84 -0
  10. package/dist/css/themes/neem.css +84 -0
  11. package/dist/css/themes/raat.css +507 -0
  12. package/dist/css/themes/sutra.css +109 -0
  13. package/dist/css/themes/ujala.css +67 -0
  14. package/dist/css/tokens.css +3167 -0
  15. package/dist/dart/und_tokens.dart +3223 -0
  16. package/dist/js/contexts.d.ts +2 -0
  17. package/dist/js/contexts.js +3 -0
  18. package/dist/js/index.d.ts +1883 -0
  19. package/dist/js/index.js +2230 -0
  20. package/dist/json/flat/kesar.dark.json +737 -0
  21. package/dist/json/flat/kesar.darkMore.json +737 -0
  22. package/dist/json/flat/kesar.light.json +737 -0
  23. package/dist/json/flat/kesar.lightMore.json +737 -0
  24. package/dist/json/flat/mitti.dark.json +737 -0
  25. package/dist/json/flat/mitti.darkMore.json +737 -0
  26. package/dist/json/flat/mitti.light.json +737 -0
  27. package/dist/json/flat/mitti.lightMore.json +737 -0
  28. package/dist/json/flat/neem.dark.json +737 -0
  29. package/dist/json/flat/neem.darkMore.json +737 -0
  30. package/dist/json/flat/neem.light.json +737 -0
  31. package/dist/json/flat/neem.lightMore.json +737 -0
  32. package/dist/json/flat/raat.dark.json +737 -0
  33. package/dist/json/flat/raat.darkMore.json +737 -0
  34. package/dist/json/flat/sutra.dark.json +738 -0
  35. package/dist/json/flat/sutra.darkMore.json +738 -0
  36. package/dist/json/flat/sutra.light.json +738 -0
  37. package/dist/json/flat/sutra.lightMore.json +738 -0
  38. package/dist/json/flat/ujala.dark.json +737 -0
  39. package/dist/json/flat/ujala.darkMore.json +737 -0
  40. package/dist/json/flat/ujala.light.json +737 -0
  41. package/dist/json/flat/ujala.lightMore.json +737 -0
  42. package/dist/json/nested/kesar.dark.json +885 -0
  43. package/dist/json/nested/kesar.darkMore.json +885 -0
  44. package/dist/json/nested/kesar.light.json +885 -0
  45. package/dist/json/nested/kesar.lightMore.json +885 -0
  46. package/dist/json/nested/mitti.dark.json +885 -0
  47. package/dist/json/nested/mitti.darkMore.json +885 -0
  48. package/dist/json/nested/mitti.light.json +885 -0
  49. package/dist/json/nested/mitti.lightMore.json +885 -0
  50. package/dist/json/nested/neem.dark.json +885 -0
  51. package/dist/json/nested/neem.darkMore.json +885 -0
  52. package/dist/json/nested/neem.light.json +885 -0
  53. package/dist/json/nested/neem.lightMore.json +885 -0
  54. package/dist/json/nested/raat.dark.json +885 -0
  55. package/dist/json/nested/raat.darkMore.json +885 -0
  56. package/dist/json/nested/sutra.dark.json +886 -0
  57. package/dist/json/nested/sutra.darkMore.json +886 -0
  58. package/dist/json/nested/sutra.light.json +886 -0
  59. package/dist/json/nested/sutra.lightMore.json +886 -0
  60. package/dist/json/nested/ujala.dark.json +885 -0
  61. package/dist/json/nested/ujala.darkMore.json +885 -0
  62. package/dist/json/nested/ujala.light.json +885 -0
  63. package/dist/json/nested/ujala.lightMore.json +885 -0
  64. package/dist/kotlin/UndTokens.kt +2870 -0
  65. package/dist/lib/build/contexts.d.ts +13 -0
  66. package/dist/lib/build/contexts.js +20 -0
  67. package/dist/lib/build/css-values.d.ts +31 -0
  68. package/dist/lib/build/css-values.js +191 -0
  69. package/dist/lib/build/formats/css.d.ts +43 -0
  70. package/dist/lib/build/formats/css.js +380 -0
  71. package/dist/lib/build/formats/dart.d.ts +9 -0
  72. package/dist/lib/build/formats/dart.js +342 -0
  73. package/dist/lib/build/formats/js.d.ts +29 -0
  74. package/dist/lib/build/formats/js.js +297 -0
  75. package/dist/lib/build/formats/kotlin.d.ts +8 -0
  76. package/dist/lib/build/formats/kotlin.js +232 -0
  77. package/dist/lib/build/formats/react-native.d.ts +2 -0
  78. package/dist/lib/build/formats/react-native.js +208 -0
  79. package/dist/lib/build/formats/style-dictionary.d.ts +8 -0
  80. package/dist/lib/build/formats/style-dictionary.js +163 -0
  81. package/dist/lib/build/formats/swift.d.ts +8 -0
  82. package/dist/lib/build/formats/swift.js +395 -0
  83. package/dist/lib/build/formats/tailwind.d.ts +9 -0
  84. package/dist/lib/build/formats/tailwind.js +105 -0
  85. package/dist/lib/build/index.d.ts +12 -0
  86. package/dist/lib/build/index.js +133 -0
  87. package/dist/lib/build/materialize.d.ts +102 -0
  88. package/dist/lib/build/materialize.js +170 -0
  89. package/dist/lib/build/native-model.d.ts +46 -0
  90. package/dist/lib/build/native-model.js +177 -0
  91. package/dist/lib/color/contrast.d.ts +24 -0
  92. package/dist/lib/color/contrast.js +95 -0
  93. package/dist/lib/color/convert.d.ts +39 -0
  94. package/dist/lib/color/convert.js +91 -0
  95. package/dist/lib/color/pairs.d.ts +29 -0
  96. package/dist/lib/color/pairs.js +90 -0
  97. package/dist/lib/color/palette.d.ts +118 -0
  98. package/dist/lib/color/palette.js +199 -0
  99. package/dist/lib/color/scales.d.ts +18 -0
  100. package/dist/lib/color/scales.js +115 -0
  101. package/dist/lib/dtcg/engine.d.ts +75 -0
  102. package/dist/lib/dtcg/engine.js +395 -0
  103. package/dist/lib/dtcg/format-json.d.ts +1 -0
  104. package/dist/lib/dtcg/format-json.js +59 -0
  105. package/dist/lib/dtcg/types.d.ts +124 -0
  106. package/dist/lib/dtcg/types.js +54 -0
  107. package/dist/lib/index.d.ts +20 -0
  108. package/dist/lib/index.js +14 -0
  109. package/dist/lib/motion/spring.d.ts +40 -0
  110. package/dist/lib/motion/spring.js +129 -0
  111. package/dist/lib/source/generate.d.ts +28 -0
  112. package/dist/lib/source/generate.js +468 -0
  113. package/dist/lib/themes/definitions.d.ts +43 -0
  114. package/dist/lib/themes/definitions.js +140 -0
  115. package/dist/react-native/index.d.ts +130 -0
  116. package/dist/react-native/index.js +15 -0
  117. package/dist/react-native/tokens.d.ts +2 -0
  118. package/dist/react-native/tokens.js +4413 -0
  119. package/dist/scss/_variables.scss +738 -0
  120. package/dist/scss/_vars.scss +857 -0
  121. package/dist/scss/kesar.dark.scss +738 -0
  122. package/dist/scss/kesar.darkMore.scss +738 -0
  123. package/dist/scss/kesar.light.scss +738 -0
  124. package/dist/scss/kesar.lightMore.scss +738 -0
  125. package/dist/scss/mitti.dark.scss +738 -0
  126. package/dist/scss/mitti.darkMore.scss +738 -0
  127. package/dist/scss/mitti.light.scss +738 -0
  128. package/dist/scss/mitti.lightMore.scss +738 -0
  129. package/dist/scss/neem.dark.scss +738 -0
  130. package/dist/scss/neem.darkMore.scss +738 -0
  131. package/dist/scss/neem.light.scss +738 -0
  132. package/dist/scss/neem.lightMore.scss +738 -0
  133. package/dist/scss/raat.dark.scss +738 -0
  134. package/dist/scss/raat.darkMore.scss +738 -0
  135. package/dist/scss/sutra.dark.scss +739 -0
  136. package/dist/scss/sutra.darkMore.scss +739 -0
  137. package/dist/scss/sutra.light.scss +739 -0
  138. package/dist/scss/sutra.lightMore.scss +739 -0
  139. package/dist/scss/ujala.dark.scss +738 -0
  140. package/dist/scss/ujala.darkMore.scss +738 -0
  141. package/dist/scss/ujala.light.scss +738 -0
  142. package/dist/scss/ujala.lightMore.scss +738 -0
  143. package/dist/swift/UndTokens.swift +4117 -0
  144. package/dist/tailwind/und.css +586 -0
  145. package/package.json +84 -3
  146. package/tokens/contrast/more.tokens.json +46 -0
  147. package/tokens/density/comfortable.tokens.json +64 -0
  148. package/tokens/density/compact.tokens.json +68 -0
  149. package/tokens/density/touch.tokens.json +64 -0
  150. package/tokens/modes/dark.tokens.json +197 -0
  151. package/tokens/modes/light.tokens.json +166 -0
  152. package/tokens/motion/reduced.tokens.json +119 -0
  153. package/tokens/primitives/color.dark.tokens.json +2001 -0
  154. package/tokens/primitives/color.light.tokens.json +2077 -0
  155. package/tokens/primitives/dimension.tokens.json +181 -0
  156. package/tokens/primitives/motion.tokens.json +41 -0
  157. package/tokens/primitives/spring.tokens.json +138 -0
  158. package/tokens/primitives/typography.tokens.json +107 -0
  159. package/tokens/semantic/bridge.tokens.json +52 -0
  160. package/tokens/semantic/color.tokens.json +129 -0
  161. package/tokens/semantic/layout.tokens.json +84 -0
  162. package/tokens/semantic/motion.tokens.json +111 -0
  163. package/tokens/semantic/scale.tokens.json +66 -0
  164. package/tokens/semantic/typography.tokens.json +281 -0
  165. package/tokens/themes/kesar.tokens.json +105 -0
  166. package/tokens/themes/mitti.tokens.json +123 -0
  167. package/tokens/themes/neem.tokens.json +123 -0
  168. package/tokens/themes/raat.tokens.json +104 -0
  169. package/tokens/themes/sutra.tokens.json +126 -0
  170. package/tokens/themes/ujala.tokens.json +96 -0
  171. package/tokens/transparency/reduced.tokens.json +30 -0
  172. package/tokens/und.resolver.json +83 -0
@@ -0,0 +1,468 @@
1
+ /**
2
+ * Generates the computed DTCG source files under tokens/:
3
+ * primitives/color.light.tokens.json, primitives/color.dark.tokens.json
4
+ * primitives/spring.tokens.json
5
+ * modes/light.tokens.json, modes/dark.tokens.json (surfaces, overlay, selection, glass, shadows)
6
+ * semantic/scale.tokens.json (default theme scale aliases)
7
+ * themes/<name>.tokens.json
8
+ * und.resolver.json (DTCG 2025.10 Resolver module)
9
+ * Hand-authored files (dimension, typography, motion, semantic colour/layout,
10
+ * contrast, density, transparency, reduced motion) are not touched.
11
+ */
12
+ import { compositeOver, wcagContrast } from '../color/contrast.js';
13
+ import { fitColor, round } from '../color/convert.js';
14
+ import { MODES, STEPS, generateScale } from '../color/palette.js';
15
+ import { ALL_SCALES } from '../color/scales.js';
16
+ import { EXT } from '../dtcg/types.js';
17
+ import { SPRINGS, springPhysics, springToCubicBezier, springToLinear } from '../motion/spring.js';
18
+ import { THEMES } from '../themes/definitions.js';
19
+ export function oklchColor(f, alpha = 1) {
20
+ const value = { colorSpace: 'oklch', components: [f.p3.l, f.p3.c, f.p3.h] };
21
+ if (alpha !== 1)
22
+ value.alpha = alpha;
23
+ value.hex = f.hex;
24
+ return value;
25
+ }
26
+ function colorToken(f, alpha = 1, description) {
27
+ return {
28
+ $value: oklchColor(f, alpha),
29
+ ...(description ? { $description: description } : {}),
30
+ $extensions: { [EXT]: { srgbChroma: f.srgb.c, p3: f.p3Components } },
31
+ };
32
+ }
33
+ function alphaToken(a) {
34
+ return { $value: { colorSpace: 'srgb', components: a.components, alpha: a.alpha, hex: a.hex } };
35
+ }
36
+ function srgbToken(components, hex, alpha = 1, description) {
37
+ return {
38
+ $value: { colorSpace: 'srgb', components, ...(alpha !== 1 ? { alpha } : {}), hex },
39
+ ...(description ? { $description: description } : {}),
40
+ };
41
+ }
42
+ /** A literal OKLCH colour (for shadows, overlays and glass). */
43
+ function literal(l, c, h, alpha, description) {
44
+ const f = fitColor({ l, c, h });
45
+ return { $type: 'color', ...colorToken(f, alpha, description) };
46
+ }
47
+ export function generateScales() {
48
+ return ALL_SCALES.map((s) => generateScale(s));
49
+ }
50
+ function colorFile(scales, mode) {
51
+ const color = {
52
+ $type: 'color',
53
+ $description: `UND UI primitive palettes, ${mode} mode. Generated by src/color/palette.ts (report 1.4): OKLCH value with P3 chroma, sRGB hex fallback, alpha twins solved per channel against ${mode === 'light' ? 'white' : 'black'}.`,
54
+ white: srgbToken([1, 1, 1], '#ffffff'),
55
+ black: srgbToken([0, 0, 0], '#000000'),
56
+ transparent: srgbToken([0, 0, 0], '#000000', 0),
57
+ };
58
+ for (const scale of scales) {
59
+ const group = {
60
+ $description: `${scale.spec.label}. hue ${scale.spec.hue}, Cmax ${scale.spec.cmax}.`,
61
+ };
62
+ for (const step of STEPS)
63
+ group[String(step)] = colorToken(scale.steps[step - 1][mode]);
64
+ for (const step of STEPS)
65
+ group[`a${step}`] = alphaToken(scale.alpha[mode][step - 1]);
66
+ const on = scale.onSolidByMode[mode];
67
+ group.contrast =
68
+ on.kind === 'white'
69
+ ? srgbToken([1, 1, 1], '#ffffff', 1, scale.spec.kind === 'chromatic'
70
+ ? 'Text on steps 9-10: white.'
71
+ : `Text on step 9 (${mode}): white.`)
72
+ : {
73
+ ...colorToken(on.fitted, 1, scale.spec.kind === 'chromatic'
74
+ ? 'Text on steps 9-10: light-mode step 12 (dark text), same in both modes.'
75
+ : `Text on step 9 (${mode}): light-mode step 12 (dark text).`),
76
+ };
77
+ color[scale.spec.name] = group;
78
+ }
79
+ return { color };
80
+ }
81
+ function springFile() {
82
+ const spring = {
83
+ $type: 'transition',
84
+ $description: 'Spring presets (report 4.4). Springs are not a DTCG type: the $value is a transition whose duration is the settle time (+-0.1%) and whose timing function is the cubic-bezier fallback. The physical parameters and a CSS linear() approximation live in $extensions.',
85
+ };
86
+ for (const s of SPRINGS) {
87
+ const p = springPhysics(s);
88
+ const lin = springToLinear(s, 40);
89
+ spring[s.name] = {
90
+ $value: {
91
+ duration: { value: p.settleMs, unit: 'ms' },
92
+ delay: { value: 0, unit: 'ms' },
93
+ timingFunction: springToCubicBezier(s),
94
+ },
95
+ $description: s.description,
96
+ $extensions: {
97
+ [EXT]: {
98
+ kind: 'spring',
99
+ response: s.response,
100
+ dampingRatio: s.dampingRatio,
101
+ mass: 1,
102
+ stiffness: p.stiffness,
103
+ damping: p.damping,
104
+ bounce: p.bounce,
105
+ overshoot: p.overshoot,
106
+ settleMs: p.settleMs,
107
+ linear: lin.easing,
108
+ },
109
+ },
110
+ };
111
+ }
112
+ return { spring };
113
+ }
114
+ // ---------------------------------------------------------------- glass alpha solving
115
+ const GLASS = {
116
+ light: {
117
+ thin: { l: 0.99, c: 0.003, h: 275, alpha: 0.62 },
118
+ regular: { l: 0.99, c: 0.003, h: 275, alpha: 0.72 },
119
+ thick: { l: 0.99, c: 0.003, h: 275, alpha: 0.84 },
120
+ },
121
+ dark: {
122
+ thin: { l: 0.22, c: 0.01, h: 275, alpha: 0.55 },
123
+ regular: { l: 0.22, c: 0.01, h: 275, alpha: 0.68 },
124
+ thick: { l: 0.2, c: 0.01, h: 275, alpha: 0.8 },
125
+ },
126
+ };
127
+ /**
128
+ * Raise a glass alpha until fg.default keeps >= 4.5:1 over the worst-case
129
+ * backdrops (pure black and pure white) for every theme neutral in the mode.
130
+ */
131
+ export function solveGlassAlpha(mode, bg, alpha, scales) {
132
+ const fgCandidates = scales
133
+ .filter((s) => s.spec.kind === 'neutral')
134
+ .map((s) => s.steps[11][mode].hex);
135
+ const bgHex = fitColor(bg).hex;
136
+ let a = alpha;
137
+ const ok = (x) => ['#000000', '#ffffff'].every((backdrop) => fgCandidates.every((fg) => wcagContrast(fg, compositeOver(bgHex, x, backdrop)) >= 4.5));
138
+ while (!ok(a) && a < 1)
139
+ a = round(a + 0.01, 2);
140
+ return a;
141
+ }
142
+ const shadowColor = (alpha) => ({
143
+ colorSpace: 'oklch',
144
+ components: [0.2, 0.02, 275],
145
+ alpha,
146
+ hex: fitColor({ l: 0.2, c: 0.02, h: 275 }).hex,
147
+ });
148
+ const white = (alpha) => ({
149
+ colorSpace: 'srgb',
150
+ components: [1, 1, 1],
151
+ alpha,
152
+ hex: '#ffffff',
153
+ });
154
+ const black = (alpha) => ({
155
+ colorSpace: 'srgb',
156
+ components: [0, 0, 0],
157
+ alpha,
158
+ hex: '#000000',
159
+ });
160
+ const px = (v) => ({ value: v, unit: 'px' });
161
+ const layer = (color, y, blur, spread = 0, inset = false, x = 0) => ({
162
+ color,
163
+ offsetX: px(x),
164
+ offsetY: px(y),
165
+ blur: px(blur),
166
+ spread: px(spread),
167
+ ...(inset ? { inset: true } : {}),
168
+ });
169
+ function shadows(mode) {
170
+ const none = [layer(black(0), 0, 0)];
171
+ if (mode === 'light') {
172
+ return {
173
+ $type: 'shadow',
174
+ $description: 'Light elevation: two layers tinted with the neutral hue, a tight contact shadow plus a soft ambient one (report 3.5).',
175
+ '0': { $value: none, $description: 'Flat.' },
176
+ '1': {
177
+ $value: [layer(shadowColor(0.06), 1, 2), layer(shadowColor(0.08), 1, 3)],
178
+ $description: 'Cards, raised buttons.',
179
+ },
180
+ '2': {
181
+ $value: [layer(shadowColor(0.06), 2, 4), layer(shadowColor(0.1), 4, 12)],
182
+ $description: 'Dropdowns, popovers.',
183
+ },
184
+ '3': {
185
+ $value: [layer(shadowColor(0.06), 4, 8), layer(shadowColor(0.12), 12, 24)],
186
+ $description: 'Sticky headers, FAB.',
187
+ },
188
+ '4': {
189
+ $value: [layer(shadowColor(0.08), 8, 16), layer(shadowColor(0.16), 24, 48)],
190
+ $description: 'Dialogs, sheets.',
191
+ },
192
+ '5': {
193
+ $value: [layer(shadowColor(0.1), 16, 32), layer(shadowColor(0.2), 40, 80)],
194
+ $description: 'Command palette, spotlight.',
195
+ },
196
+ };
197
+ }
198
+ const ring = (top, ringA) => [
199
+ layer(white(top), 1, 0, 0, true),
200
+ layer(white(ringA), 0, 0, 1),
201
+ ];
202
+ return {
203
+ $type: 'shadow',
204
+ $description: 'Dark elevation: surface lightness, a 1px top highlight and a hairline ring; shadows only add depth (report 3.5).',
205
+ '0': { $value: none, $description: 'Flat.' },
206
+ '1': { $value: ring(0.04, 0.06), $description: 'Cards (on neutral-2).' },
207
+ '2': {
208
+ $value: [...ring(0.06, 0.08), layer(black(0.45), 8, 24)],
209
+ $description: 'Dropdowns, popovers (on neutral-3).',
210
+ },
211
+ '3': {
212
+ $value: [...ring(0.06, 0.08), layer(black(0.5), 12, 32)],
213
+ $description: 'Sticky headers, FAB.',
214
+ },
215
+ '4': {
216
+ $value: [...ring(0.07, 0.1), layer(black(0.6), 24, 64)],
217
+ $description: 'Dialogs, sheets.',
218
+ },
219
+ '5': {
220
+ $value: [...ring(0.07, 0.1), layer(black(0.6), 24, 64)],
221
+ $description: 'Command palette (plus a scrim).',
222
+ },
223
+ };
224
+ }
225
+ function modeFile(mode, scales, decisions) {
226
+ const material = {
227
+ $description: `Glass backgrounds, ${mode} mode (report 3.6). Alphas are raised where needed so fg.default keeps 4.5:1 over pure black and pure white backdrops.`,
228
+ };
229
+ for (const [name, g] of Object.entries(GLASS[mode])) {
230
+ const alpha = solveGlassAlpha(mode, g, g.alpha, scales);
231
+ decisions.push({ mode, material: name, reportAlpha: g.alpha, alpha });
232
+ material[name] = { bg: literal(g.l, g.c, g.h, alpha) };
233
+ }
234
+ const reg = GLASS[mode].regular;
235
+ const regAlpha = solveGlassAlpha(mode, reg, reg.alpha, scales);
236
+ material.chrome = {
237
+ bg: literal(reg.l, reg.c, reg.h, regAlpha, 'Glass controls: material-regular plus a specular edge and elevation 2.'),
238
+ highlight: {
239
+ $type: 'color',
240
+ $value: white(mode === 'light' ? 0.5 : 0.12),
241
+ $description: 'Inset 1px specular edge.',
242
+ },
243
+ };
244
+ return {
245
+ $description: `${mode === 'light' ? 'Light' : 'Dark'} mode semantic values that are not plain scale references.`,
246
+ bg: {
247
+ $type: 'color',
248
+ surface: {
249
+ $value: mode === 'light' ? '{color.white}' : '{scale.neutral.2}',
250
+ $description: 'Cards, sheets (raised by lightness in dark mode).',
251
+ },
252
+ raised: {
253
+ $value: mode === 'light' ? '{color.white}' : '{scale.neutral.3}',
254
+ $description: 'Popovers and menus.',
255
+ },
256
+ overlay: mode === 'light'
257
+ ? { ...literal(0.16, 0.02, 275, 0.45, 'Modal scrim.') }
258
+ : { $value: black(0.6), $description: 'Modal scrim.' },
259
+ },
260
+ selection: {
261
+ bg: {
262
+ $type: 'color',
263
+ $value: mode === 'light' ? '{scale.accent.a5}' : '{scale.accent.a6}',
264
+ $description: '::selection',
265
+ },
266
+ },
267
+ material,
268
+ shadow: shadows(mode),
269
+ };
270
+ }
271
+ // ---------------------------------------------------------------- scale aliases and themes
272
+ function scaleAliases(accent, neutral, accentText) {
273
+ const acc = {
274
+ $description: 'Theme accent scale. Semantic tokens read these, never hue names.',
275
+ };
276
+ const neu = { $description: 'Theme neutral scale.' };
277
+ for (const step of STEPS) {
278
+ acc[String(step)] = { $value: `{color.${accent}.${step}}` };
279
+ neu[String(step)] = { $value: `{color.${neutral}.${step}}` };
280
+ }
281
+ for (const step of STEPS) {
282
+ acc[`a${step}`] = { $value: `{color.${accent}.a${step}}` };
283
+ neu[`a${step}`] = { $value: `{color.${neutral}.a${step}}` };
284
+ }
285
+ acc.contrast = { $value: `{color.${accent}.contrast}` };
286
+ return {
287
+ scale: {
288
+ $type: 'color',
289
+ accent: acc,
290
+ neutral: neu,
291
+ 'accent-text': {
292
+ $description: 'Scale for accent text and links (Sutra uses blue).',
293
+ '11': { $value: `{color.${accentText}.11}` },
294
+ '12': { $value: `{color.${accentText}.12}` },
295
+ },
296
+ },
297
+ };
298
+ }
299
+ const CHARACTER_EASE = {
300
+ crisp: { enter: { $value: '{ease.move}' }, move: { $value: '{ease.move}' } },
301
+ standard: { enter: { $value: '{ease.enter}' }, move: { $value: '{ease.move}' } },
302
+ expressive: {
303
+ enter: {
304
+ $value: springToCubicBezier(SPRINGS.find((s) => s.name === 'bouncy')),
305
+ $description: 'spring.bouncy (linear() in CSS, cubic-bezier fallback).',
306
+ $extensions: { [EXT]: { spring: 'spring.bouncy' } },
307
+ },
308
+ move: {
309
+ $value: springToCubicBezier(SPRINGS.find((s) => s.name === 'snappy')),
310
+ $description: 'spring.snappy (linear() in CSS, cubic-bezier fallback).',
311
+ $extensions: { [EXT]: { spring: 'spring.snappy' } },
312
+ },
313
+ },
314
+ };
315
+ function setPath(target, path, value) {
316
+ const parts = path.split('.');
317
+ let node = target;
318
+ for (const p of parts.slice(0, -1)) {
319
+ node[p] ??= {};
320
+ node = node[p];
321
+ }
322
+ node[parts.at(-1)] = value;
323
+ }
324
+ function themeFile(theme) {
325
+ const doc = {
326
+ $description: `${theme.label}: ${theme.personality}`,
327
+ $extensions: {
328
+ [EXT]: {
329
+ theme: {
330
+ name: theme.name,
331
+ label: theme.label,
332
+ modes: theme.modes,
333
+ radiusFactor: theme.radiusFactor,
334
+ tempo: theme.tempo,
335
+ character: theme.character,
336
+ density: theme.density,
337
+ glass: theme.glass,
338
+ },
339
+ },
340
+ },
341
+ ...scaleAliases(theme.accent, theme.neutral, theme.accentText ?? theme.accent),
342
+ };
343
+ setPath(doc, 'radius.factor', { $type: 'number', $value: theme.radiusFactor });
344
+ setPath(doc, 'motion.tempo', { $type: 'number', $value: theme.tempo });
345
+ setPath(doc, 'motion.ease', { $type: 'cubicBezier', ...CHARACTER_EASE[theme.character] });
346
+ setPath(doc, 'typeface', {
347
+ $type: 'fontFamily',
348
+ body: { $value: theme.typeface.body },
349
+ heading: { $value: theme.typeface.heading },
350
+ display: { $value: theme.typeface.display },
351
+ code: { $value: theme.typeface.code },
352
+ });
353
+ if (theme.focus === 'neutral')
354
+ setPath(doc, 'focus.ring', { $type: 'color', $value: '{scale.neutral.12}' });
355
+ for (const [path, value] of Object.entries(theme.overrides ?? {}))
356
+ setPath(doc, path, { $type: 'color', $value: value });
357
+ if (theme.glass === 'off') {
358
+ for (const m of ['thin', 'regular', 'thick', 'chrome']) {
359
+ setPath(doc, `material.${m}`, {
360
+ bg: { $type: 'color', $value: '{bg.surface}' },
361
+ border: { $type: 'color', $value: '{border.default}' },
362
+ blur: { $type: 'dimension', $value: { value: 0, unit: 'px' } },
363
+ saturate: { $type: 'number', $value: 1 },
364
+ ...(m === 'chrome' ? { highlight: { $type: 'color', $value: '{color.transparent}' } } : {}),
365
+ });
366
+ }
367
+ }
368
+ if (theme.density === 'compact') {
369
+ // Theme default density; an explicit density context (applied later) wins.
370
+ doc['$extensions'] = {
371
+ [EXT]: { ...doc.$extensions[EXT], defaultDensity: 'compact' },
372
+ };
373
+ }
374
+ return doc;
375
+ }
376
+ // ---------------------------------------------------------------- resolver
377
+ export const RESOLVER_PATH = 'und.resolver.json';
378
+ export const BASE_SOURCES = [
379
+ 'primitives/dimension.tokens.json',
380
+ 'primitives/typography.tokens.json',
381
+ 'primitives/motion.tokens.json',
382
+ 'primitives/spring.tokens.json',
383
+ 'semantic/scale.tokens.json',
384
+ 'semantic/color.tokens.json',
385
+ 'semantic/layout.tokens.json',
386
+ 'semantic/typography.tokens.json',
387
+ 'semantic/motion.tokens.json',
388
+ 'semantic/bridge.tokens.json',
389
+ ];
390
+ export const MODE_SOURCES = {
391
+ light: ['primitives/color.light.tokens.json', 'modes/light.tokens.json'],
392
+ dark: ['primitives/color.dark.tokens.json', 'modes/dark.tokens.json'],
393
+ };
394
+ export function themeSources(theme) {
395
+ const own = `themes/${theme.name}.tokens.json`;
396
+ const sources = theme.modes.length === 1 ? [...MODE_SOURCES[theme.modes[0]], own] : [own];
397
+ if (theme.density === 'compact')
398
+ sources.push('density/compact.tokens.json');
399
+ return sources;
400
+ }
401
+ function resolverFile() {
402
+ const ref = (p) => ({ $ref: p });
403
+ return {
404
+ $schema: 'https://www.designtokens.org/schemas/2025.10/resolver.json',
405
+ name: 'UND UI tokens',
406
+ 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.',
408
+ sets: {
409
+ base: { description: 'Primitives and the semantic layer.', sources: BASE_SOURCES.map(ref) },
410
+ },
411
+ modifiers: {
412
+ mode: {
413
+ description: 'Colour scheme.',
414
+ contexts: { light: MODE_SOURCES.light.map(ref), dark: MODE_SOURCES.dark.map(ref) },
415
+ default: 'light',
416
+ },
417
+ theme: {
418
+ description: 'The six UND UI themes.',
419
+ contexts: Object.fromEntries(THEMES.map((t) => [t.name, themeSources(t).map(ref)])),
420
+ default: 'ujala',
421
+ },
422
+ contrast: {
423
+ description: 'prefers-contrast: more / Increase Contrast.',
424
+ contexts: { standard: [], more: [ref('contrast/more.tokens.json')] },
425
+ default: 'standard',
426
+ },
427
+ density: {
428
+ description: 'auto keeps the theme default (comfortable, or compact for Sutra).',
429
+ contexts: {
430
+ auto: [],
431
+ comfortable: [ref('density/comfortable.tokens.json')],
432
+ compact: [ref('density/compact.tokens.json')],
433
+ touch: [ref('density/touch.tokens.json')],
434
+ },
435
+ default: 'auto',
436
+ },
437
+ transparency: {
438
+ description: 'prefers-reduced-transparency / Reduce Transparency.',
439
+ contexts: { full: [], reduced: [ref('transparency/reduced.tokens.json')] },
440
+ default: 'full',
441
+ },
442
+ motion: {
443
+ description: 'prefers-reduced-motion / Reduce Motion.',
444
+ contexts: { full: [], reduced: [ref('motion/reduced.tokens.json')] },
445
+ default: 'full',
446
+ },
447
+ },
448
+ resolutionOrder: ['base', 'mode', 'theme', 'contrast', 'density', 'transparency', 'motion'].map((n, i) => ref(i === 0 ? '#/sets/base' : `#/modifiers/${n}`)),
449
+ };
450
+ }
451
+ export function generateSource() {
452
+ const scales = generateScales();
453
+ const glass = [];
454
+ const files = {};
455
+ for (const mode of MODES) {
456
+ files[`primitives/color.${mode}.tokens.json`] = colorFile(scales, mode);
457
+ files[`modes/${mode}.tokens.json`] = modeFile(mode, scales, glass);
458
+ }
459
+ files['primitives/spring.tokens.json'] = springFile();
460
+ files['semantic/scale.tokens.json'] = {
461
+ $description: 'Default (Ujala) scale aliases. Themes repoint these.',
462
+ ...scaleAliases('indigo', 'neutral', 'indigo'),
463
+ };
464
+ for (const theme of THEMES)
465
+ files[`themes/${theme.name}.tokens.json`] = themeFile(theme);
466
+ files[RESOLVER_PATH] = resolverFile();
467
+ return { files, scales, glass };
468
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * The six UND UI themes (report section 7).
3
+ *
4
+ * A theme is a small seed object; the generator turns it into a DTCG override
5
+ * file (tokens/themes/<name>.tokens.json). Theme overrides are deliberately
6
+ * mode- and contrast-independent (they point at scale aliases, which the mode
7
+ * 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
+ */
11
+ export type ThemeName = 'ujala' | 'kesar' | 'neem' | 'mitti' | 'raat' | 'sutra';
12
+ export type Character = 'crisp' | 'standard' | 'expressive';
13
+ export type Glass = 'chrome' | 'on' | 'off';
14
+ export interface ThemeDefinition {
15
+ name: ThemeName;
16
+ label: string;
17
+ personality: string;
18
+ /** Scale used for accent steps 1-12 (`scale.accent.*`). */
19
+ accent: string;
20
+ /** Scale used for neutral steps 1-12 (`scale.neutral.*`). */
21
+ neutral: string;
22
+ /** Scale used for accent text and links (`scale.accent-text.*`). Defaults to `accent`. */
23
+ accentText?: string;
24
+ modes: readonly ('light' | 'dark')[];
25
+ radiusFactor: number;
26
+ tempo: number;
27
+ character: Character;
28
+ density: 'comfortable' | 'compact';
29
+ glass: Glass;
30
+ typeface: {
31
+ body: string;
32
+ heading: string;
33
+ display: string;
34
+ code: string;
35
+ };
36
+ /** Focus ring source. Default `accent` (accent step 11). */
37
+ focus?: 'accent' | 'neutral';
38
+ /** Extra semantic overrides (values are references). */
39
+ overrides?: Record<string, string>;
40
+ }
41
+ export declare const THEMES: readonly ThemeDefinition[];
42
+ export declare const DEFAULT_THEME: ThemeName;
43
+ export declare function themeByName(name: ThemeName): ThemeDefinition;
@@ -0,0 +1,140 @@
1
+ /**
2
+ * The six UND UI themes (report section 7).
3
+ *
4
+ * A theme is a small seed object; the generator turns it into a DTCG override
5
+ * file (tokens/themes/<name>.tokens.json). Theme overrides are deliberately
6
+ * mode- and contrast-independent (they point at scale aliases, which the mode
7
+ * 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
+ */
11
+ const INTER = {
12
+ body: '{font.sans}',
13
+ heading: '{font.sans}',
14
+ display: '{font.display}',
15
+ code: '{font.mono}',
16
+ };
17
+ export const THEMES = [
18
+ {
19
+ name: 'ujala',
20
+ label: 'Ujala',
21
+ personality: 'Default. Confident, friendly, modern civic. The UND brand.',
22
+ accent: 'indigo',
23
+ neutral: 'neutral',
24
+ modes: ['light', 'dark'],
25
+ radiusFactor: 1,
26
+ tempo: 1,
27
+ character: 'standard',
28
+ density: 'comfortable',
29
+ glass: 'chrome',
30
+ typeface: INTER,
31
+ },
32
+ {
33
+ name: 'kesar',
34
+ label: 'Kesar',
35
+ personality: 'Festive, warm, celebratory: events, festivals, community drives.',
36
+ accent: 'saffron',
37
+ neutral: 'warm',
38
+ modes: ['light', 'dark'],
39
+ radiusFactor: 1.25,
40
+ tempo: 1,
41
+ character: 'expressive',
42
+ density: 'comfortable',
43
+ glass: 'on',
44
+ typeface: {
45
+ body: '{font.sans}',
46
+ heading: '{font.anek}',
47
+ display: '{font.anek}',
48
+ code: '{font.mono}',
49
+ },
50
+ // Saffron step 9 is below 3:1 on light surfaces, so the ring is neutral-12 (report 6.1).
51
+ focus: 'neutral',
52
+ },
53
+ {
54
+ name: 'neem',
55
+ label: 'Neem',
56
+ personality: 'Calm, trustworthy, grounded: civic, health, education.',
57
+ accent: 'green',
58
+ neutral: 'sage',
59
+ modes: ['light', 'dark'],
60
+ radiusFactor: 1,
61
+ tempo: 1,
62
+ character: 'crisp',
63
+ density: 'comfortable',
64
+ glass: 'off',
65
+ typeface: INTER,
66
+ },
67
+ {
68
+ name: 'mitti',
69
+ label: 'Mitti',
70
+ personality: 'Editorial, tactile, handmade: long reads, local stories, marketplace.',
71
+ accent: 'terracotta',
72
+ neutral: 'sand',
73
+ modes: ['light', 'dark'],
74
+ radiusFactor: 1.5,
75
+ tempo: 1.15,
76
+ character: 'standard',
77
+ density: 'comfortable',
78
+ glass: 'off',
79
+ typeface: {
80
+ body: '{font.sans}',
81
+ heading: '{font.serif}',
82
+ display: '{font.serif}',
83
+ code: '{font.mono}',
84
+ },
85
+ },
86
+ {
87
+ name: 'raat',
88
+ label: 'Raat',
89
+ personality: 'Immersive, cinematic, premium: media, live events. Dark-only.',
90
+ accent: 'indigo',
91
+ neutral: 'midnight',
92
+ modes: ['dark'],
93
+ radiusFactor: 1.25,
94
+ tempo: 1,
95
+ character: 'expressive',
96
+ density: 'comfortable',
97
+ glass: 'on',
98
+ typeface: INTER,
99
+ },
100
+ {
101
+ name: 'sutra',
102
+ label: 'Sutra',
103
+ personality: 'Precise, monochrome, enterprise: admin, dashboards, developer tools.',
104
+ accent: 'gray',
105
+ neutral: 'gray',
106
+ accentText: 'blue',
107
+ modes: ['light', 'dark'],
108
+ radiusFactor: 0.5,
109
+ tempo: 0.85,
110
+ character: 'crisp',
111
+ density: 'compact',
112
+ glass: 'off',
113
+ typeface: {
114
+ body: '{font.geist}',
115
+ heading: '{font.geist}',
116
+ display: '{font.geist}',
117
+ code: '{font.mono}',
118
+ },
119
+ focus: 'neutral',
120
+ overrides: {
121
+ // Neutral-12 solid: black buttons in light mode, white in dark mode. The solid
122
+ // band of the accent scale (9, 10, their alpha twins and the on-solid contrast)
123
+ // is repointed, so accent.solid, fg.on-accent and scale.accent.contrast agree.
124
+ 'scale.accent.9': '{color.gray.12}',
125
+ 'scale.accent.10': '{color.gray.11}',
126
+ 'scale.accent.a9': '{color.gray.a12}',
127
+ 'scale.accent.a10': '{color.gray.a11}',
128
+ 'scale.accent.contrast': '{color.gray.1}',
129
+ // v0 component bridge: black/white tone instead of grey step 11.
130
+ 'color.accent': '{scale.neutral.12}',
131
+ },
132
+ },
133
+ ];
134
+ export const DEFAULT_THEME = 'ujala';
135
+ export function themeByName(name) {
136
+ const t = THEMES.find((x) => x.name === name);
137
+ if (!t)
138
+ throw new Error(`Unknown theme ${name}`);
139
+ return t;
140
+ }