@und-ui/tokens 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,9 @@
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 type { NativeModel } from '../native-model.js';
9
+ export declare function renderDart(model: NativeModel): string;
@@ -0,0 +1,342 @@
1
+ import { VARIANTS, camel, stepName } from '../native-model.js';
2
+ const d = (v) => {
3
+ const r = Math.round(v * 10000) / 10000;
4
+ return Number.isInteger(r) ? `${r}.0` : `${r}`;
5
+ };
6
+ const str = (s) => `'${s.replace(/'/g, "\\'")}'`;
7
+ function color(c) {
8
+ if (c.p3)
9
+ return `Color.from(alpha: ${d(c.alpha)}, red: ${d(c.p3[0])}, green: ${d(c.p3[1])}, blue: ${d(c.p3[2])}, colorSpace: ColorSpace.displayP3)`;
10
+ const a = Math.round(c.alpha * 255)
11
+ .toString(16)
12
+ .padStart(2, '0')
13
+ .toUpperCase();
14
+ return `Color(0x${a}${c.hex.slice(1).toUpperCase()})`;
15
+ }
16
+ function shadow(s) {
17
+ const layers = s.layers
18
+ .filter((l) => !l.inset)
19
+ .map((l) => `BoxShadow(color: ${color(l.color)}, offset: Offset(${d(l.x)}, ${d(l.y)}), blurRadius: ${d(l.blur)}, spreadRadius: ${d(l.spread)})`);
20
+ return `<BoxShadow>[${layers.join(', ')}]`;
21
+ }
22
+ export function renderDart(model) {
23
+ const roles = model.colorRoles.map(([name]) => name);
24
+ const t0 = model.themes[0];
25
+ const radiusKeys = [...t0.radius.keys()].filter((k) => k !== 'factor');
26
+ const durNames = [...t0.durations.keys()];
27
+ const easeNames = [...t0.easings.keys()];
28
+ const springNames = [...t0.springs.keys()];
29
+ const cap = (s) => s.charAt(0).toUpperCase() + s.slice(1);
30
+ const L = [];
31
+ L.push(`// Generated by @und-ui/tokens ${model.version}. Do not edit.
32
+ // Source: DTCG 2025.10 tokens. Semantic roles only. No Material dependency.
33
+ // ignore_for_file: public_member_api_docs, constant_identifier_names
34
+
35
+ import 'dart:ui' show Brightness, Color, ColorSpace, FontWeight, Offset, lerpDouble;
36
+
37
+ import 'package:flutter/animation.dart' show Cubic;
38
+ import 'package:flutter/foundation.dart' show immutable;
39
+ import 'package:flutter/painting.dart' show BoxShadow, TextStyle;
40
+ import 'package:flutter/physics.dart' show SpringDescription;
41
+ import 'package:flutter/widgets.dart' show BuildContext, InheritedWidget, Widget;
42
+
43
+ /// Package version of the tokens these classes were generated from.
44
+ const String undTokensVersion = ${str(model.version)};
45
+
46
+ enum UndThemeName { ${model.themes.map((t) => t.def.name).join(', ')} }
47
+
48
+ enum UndCharacter { crisp, standard, expressive }
49
+
50
+ enum UndDensity { comfortable, compact, touch }
51
+
52
+ /// Semantic colour roles for one theme and appearance.
53
+ @immutable
54
+ class UndColors {
55
+ const UndColors({
56
+ ${roles.map((r) => ` required this.${r},`).join('\n')}
57
+ });
58
+
59
+ ${roles.map((r) => ` final Color ${r};`).join('\n')}
60
+
61
+ ${model.themes
62
+ .flatMap((t) => VARIANTS.map((v) => ` static const UndColors ${t.def.name}${cap(v)} = UndColors(
63
+ ${roles.map((r) => ` ${r}: ${color(t.colors[v].get(r))},`).join('\n')}
64
+ );`))
65
+ .join('\n\n')}
66
+
67
+ /// Pick a scheme. Dark-only themes (Raat) ignore [brightness].
68
+ static UndColors of(UndThemeName theme, {required Brightness brightness, bool highContrast = false}) {
69
+ final dark = brightness == Brightness.dark;
70
+ switch (theme) {
71
+ ${model.themes
72
+ .map((t) => ` case UndThemeName.${t.def.name}:
73
+ return dark ? (highContrast ? ${t.def.name}DarkMore : ${t.def.name}Dark) : (highContrast ? ${t.def.name}LightMore : ${t.def.name}Light);`)
74
+ .join('\n')}
75
+ }
76
+ }
77
+
78
+ UndColors lerp(UndColors other, double t) => UndColors(
79
+ ${roles.map((r) => ` ${r}: Color.lerp(${r}, other.${r}, t)!,`).join('\n')}
80
+ );
81
+
82
+ List<Color> get _values => <Color>[${roles.join(', ')}];
83
+
84
+ @override
85
+ bool operator ==(Object other) {
86
+ if (identical(this, other)) return true;
87
+ if (other is! UndColors) return false;
88
+ final a = _values;
89
+ final b = other._values;
90
+ for (var i = 0; i < a.length; i++) {
91
+ if (a[i] != b[i]) return false;
92
+ }
93
+ return true;
94
+ }
95
+
96
+ @override
97
+ int get hashCode => Object.hashAll(_values);
98
+ }
99
+ `);
100
+ const consts = (name, entries, doc, prefix = 's') => `/// ${doc}\nabstract final class ${name} {\n${[...entries].map(([k, v]) => ` static const double ${stepName(k, prefix)} = ${d(v)};`).join('\n')}\n}\n`;
101
+ L.push(consts('UndSpacing', model.spacing, '4px spacing scale (report 3.1). Density never changes these.'));
102
+ L.push(consts('UndIconSize', model.iconSize, 'Icon sizes.'));
103
+ L.push(consts('UndBorderWidth', model.borderWidth, 'Border widths.'));
104
+ L.push(consts('UndBreakpoint', model.breakpoint, 'Window-width breakpoints (logical pixels).', 'w'));
105
+ L.push(`/// Focus ring metrics and minimum hit target.
106
+ abstract final class UndFocus {
107
+ static const double width = ${d(model.focus.width)};
108
+ static const double widthHighContrast = ${d(model.focus.widthMore)};
109
+ static const double offset = ${d(model.focus.offset)};
110
+ static const double minimumTarget = ${d(model.target.touch)};
111
+ }
112
+ `);
113
+ const controlKeys = [...model.control.comfortable.keys()];
114
+ L.push(`/// Control metrics per density.
115
+ @immutable
116
+ class UndControl {
117
+ const UndControl({${controlKeys.map((k) => `required this.${stepName(k)}`).join(', ')}});
118
+
119
+ ${controlKeys.map((k) => ` final double ${stepName(k)};`).join('\n')}
120
+
121
+ ${['comfortable', 'compact', 'touch']
122
+ .map((den) => ` static const UndControl ${den} = UndControl(${controlKeys.map((k) => `${stepName(k)}: ${d(model.control[den].get(k))}`).join(', ')});`)
123
+ .join('\n')}
124
+
125
+ static UndControl of(UndDensity density) => switch (density) {
126
+ UndDensity.comfortable => comfortable,
127
+ UndDensity.compact => compact,
128
+ UndDensity.touch => touch,
129
+ };
130
+ }
131
+
132
+ /// Radius scale with the theme radius factor applied.
133
+ @immutable
134
+ class UndRadii {
135
+ const UndRadii({required this.factor, ${radiusKeys.map((k) => `required this.${stepName(k)}`).join(', ')}});
136
+
137
+ final double factor;
138
+ ${radiusKeys.map((k) => ` final double ${stepName(k)};`).join('\n')}
139
+
140
+ /// Concentric inner radius: outer - padding, at least 2.
141
+ double inner(double outer, double padding) => (outer - padding) < 2 ? 2 : outer - padding;
142
+
143
+ UndRadii lerp(UndRadii other, double t) => UndRadii(
144
+ factor: lerpDouble(factor, other.factor, t)!,
145
+ ${radiusKeys.map((k) => ` ${stepName(k)}: lerpDouble(${stepName(k)}, other.${stepName(k)}, t)!,`).join('\n')}
146
+ );
147
+
148
+ @override
149
+ bool operator ==(Object other) => other is UndRadii && other.factor == factor${radiusKeys.map((k) => ` && other.${stepName(k)} == ${stepName(k)}`).join('')};
150
+
151
+ @override
152
+ int get hashCode => Object.hash(factor, ${radiusKeys
153
+ .slice(0, 12)
154
+ .map((k) => stepName(k))
155
+ .join(', ')});
156
+ }
157
+
158
+ /// Spring (mass 1). Use [description] with SpringSimulation.
159
+ @immutable
160
+ class UndSpring {
161
+ const UndSpring({required this.response, required this.dampingRatio, required this.stiffness, required this.damping, required this.settle});
162
+
163
+ final double response;
164
+ final double dampingRatio;
165
+ final double stiffness;
166
+ final double damping;
167
+ final Duration settle;
168
+
169
+ SpringDescription get description => SpringDescription.withDampingRatio(mass: 1, stiffness: stiffness, ratio: dampingRatio);
170
+
171
+ @override
172
+ bool operator ==(Object other) => other is UndSpring && other.stiffness == stiffness && other.dampingRatio == dampingRatio;
173
+
174
+ @override
175
+ int get hashCode => Object.hash(stiffness, dampingRatio);
176
+ }
177
+
178
+ /// Motion for a theme: durations (tempo applied), easing curves and springs.
179
+ @immutable
180
+ class UndMotion {
181
+ const UndMotion({
182
+ required this.tempo,
183
+ required this.character,
184
+ ${durNames.map((x) => ` required this.${camel(x)},`).join('\n')}
185
+ ${easeNames.map((x) => ` required this.${camel(x)},`).join('\n')}
186
+ ${springNames.map((x) => ` required this.spring${cap(x)},`).join('\n')}
187
+ });
188
+
189
+ final double tempo;
190
+ final UndCharacter character;
191
+ ${durNames.map((x) => ` final Duration ${camel(x)};`).join('\n')}
192
+ ${easeNames.map((x) => ` final Cubic ${camel(x)};`).join('\n')}
193
+ ${springNames.map((x) => ` final UndSpring spring${cap(x)};`).join('\n')}
194
+
195
+ ${model.themes
196
+ .map((t) => {
197
+ const args = [
198
+ `tempo: ${d(t.tempo)}`,
199
+ `character: UndCharacter.${t.def.character}`,
200
+ ...durNames.map((x) => `${camel(x)}: Duration(milliseconds: ${t.durations.get(x)})`),
201
+ ...easeNames.map((x) => `${camel(x)}: Cubic(${t.easings.get(x).bezier.map(d).join(', ')})`),
202
+ ...springNames.map((x) => {
203
+ const s = t.springs.get(x);
204
+ return `spring${cap(x)}: UndSpring(response: ${d(s.response)}, dampingRatio: ${d(s.dampingRatio)}, stiffness: ${d(s.stiffness)}, damping: ${d(s.damping)}, settle: Duration(milliseconds: ${s.settleMs}))`;
205
+ }),
206
+ ];
207
+ return ` static const UndMotion ${t.def.name} = UndMotion(\n ${args.join(',\n ')},\n );`;
208
+ })
209
+ .join('\n\n')}
210
+
211
+ @override
212
+ bool operator ==(Object other) => other is UndMotion && other.tempo == tempo && other.character == character;
213
+
214
+ @override
215
+ int get hashCode => Object.hash(tempo, character);
216
+ }
217
+
218
+ /// Reduced-motion durations (never scaled by tempo). Use with MediaQuery.disableAnimationsOf.
219
+ abstract final class UndReducedMotion {
220
+ ${[...model.reducedDurations].map(([k, v]) => ` static const Duration ${camel(k)} = Duration(milliseconds: ${v});`).join('\n')}
221
+ }
222
+
223
+ /// Text styles (logical pixels; respect MediaQuery.textScalerOf). Mobile sizes.
224
+ abstract final class UndTypography {
225
+ ${[...model.typography]
226
+ .map(([k, t]) => {
227
+ const size = t.sizeEm !== undefined ? 14.72 : t.minSizePx;
228
+ return ` static const TextStyle ${camel(k)} = TextStyle(fontSize: ${d(size)}, height: ${d(t.lineHeight)}, fontWeight: FontWeight.w${Math.min(900, Math.round(t.weight / 100) * 100)}, letterSpacing: ${d(t.letterSpacingEm * size)});`;
229
+ })
230
+ .join('\n')}
231
+
232
+ /// Indic line heights (Devanagari etc.).
233
+ static const Map<String, double> indicHeight = <String, double>{
234
+ ${[...model.typography].map(([k, t]) => ` ${str(camel(k))}: ${d(t.lineHeightIndic)},`).join('\n')}
235
+ };
236
+
237
+ /// Applies the Indic line height and removes letter spacing (never track Indic scripts).
238
+ static TextStyle indic(TextStyle style, String name) => style.copyWith(height: indicHeight[name] ?? 1.75, letterSpacing: 0);
239
+ }
240
+
241
+ /// Elevation shadows per brightness (BoxShadow lists).
242
+ 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') : ''}
244
+
245
+ static List<BoxShadow> of(int level, Brightness brightness) {
246
+ final dark = brightness == Brightness.dark;
247
+ switch (level) {
248
+ ${[...model.themes[0].shadows.light.keys()].map((k) => ` case ${k}:\n return dark ? dark${k} : light${k};`).join('\n')}
249
+ default:
250
+ return const <BoxShadow>[];
251
+ }
252
+ }
253
+ }
254
+
255
+ /// Everything a widget needs from the active UND theme.
256
+ @immutable
257
+ class UndThemeData {
258
+ const UndThemeData({
259
+ required this.name,
260
+ required this.darkOnly,
261
+ required this.colors,
262
+ required this.radii,
263
+ required this.motion,
264
+ required this.density,
265
+ required this.fontFamilies,
266
+ });
267
+
268
+ final UndThemeName name;
269
+ final bool darkOnly;
270
+ final UndColors colors;
271
+ final UndRadii radii;
272
+ final UndMotion motion;
273
+ final UndDensity density;
274
+ final Map<String, List<String>> fontFamilies;
275
+
276
+ UndControl get control => UndControl.of(density);
277
+
278
+ /// Resolve a theme for a brightness and contrast (MediaQuery.highContrastOf).
279
+ static UndThemeData of(UndThemeName name, {Brightness brightness = Brightness.light, bool highContrast = false}) {
280
+ switch (name) {
281
+ ${model.themes
282
+ .map((t) => ` case UndThemeName.${t.def.name}:
283
+ return UndThemeData(
284
+ name: name,
285
+ darkOnly: ${t.def.modes.length === 1},
286
+ colors: UndColors.of(name, brightness: ${t.def.modes.length === 1 ? 'Brightness.dark' : 'brightness'}, highContrast: highContrast),
287
+ radii: const UndRadii(factor: ${d(t.def.radiusFactor)}, ${radiusKeys.map((k) => `${stepName(k)}: ${d(t.radius.get(k))}`).join(', ')}),
288
+ motion: UndMotion.${t.def.name},
289
+ density: UndDensity.${t.def.density},
290
+ fontFamilies: const <String, List<String>>{${['body', 'heading', 'display', 'code'].map((r) => `${str(r)}: <String>[${t.typeface[r].map(str).join(', ')}]`).join(', ')}},
291
+ );`)
292
+ .join('\n')}
293
+ }
294
+ }
295
+
296
+ UndThemeData copyWith({UndColors? colors, UndRadii? radii, UndMotion? motion, UndDensity? density}) => UndThemeData(
297
+ name: name,
298
+ darkOnly: darkOnly,
299
+ colors: colors ?? this.colors,
300
+ radii: radii ?? this.radii,
301
+ motion: motion ?? this.motion,
302
+ density: density ?? this.density,
303
+ fontFamilies: fontFamilies,
304
+ );
305
+
306
+ /// Interpolates colours and radii (motion and density switch at t = 0.5).
307
+ UndThemeData lerp(UndThemeData other, double t) => UndThemeData(
308
+ name: t < 0.5 ? name : other.name,
309
+ darkOnly: t < 0.5 ? darkOnly : other.darkOnly,
310
+ colors: colors.lerp(other.colors, t),
311
+ radii: radii.lerp(other.radii, t),
312
+ motion: t < 0.5 ? motion : other.motion,
313
+ density: t < 0.5 ? density : other.density,
314
+ fontFamilies: t < 0.5 ? fontFamilies : other.fontFamilies,
315
+ );
316
+
317
+ @override
318
+ bool operator ==(Object other) =>
319
+ other is UndThemeData && other.name == name && other.colors == colors && other.radii == radii && other.motion == motion && other.density == density;
320
+
321
+ @override
322
+ int get hashCode => Object.hash(name, colors, radii, motion, density);
323
+ }
324
+
325
+ /// Provides [UndThemeData] to descendants without any Material dependency.
326
+ class UndTheme extends InheritedWidget {
327
+ const UndTheme({super.key, required this.data, required super.child});
328
+
329
+ final UndThemeData data;
330
+
331
+ static UndThemeData of(BuildContext context) =>
332
+ context.dependOnInheritedWidgetOfExactType<UndTheme>()?.data ?? UndThemeData.of(UndThemeName.ujala);
333
+
334
+ @override
335
+ bool updateShouldNotify(UndTheme oldWidget) => data != oldWidget.data;
336
+ }
337
+
338
+ /// Keeps [Widget] in the public import surface for wrappers.
339
+ typedef UndWidgetBuilder = Widget Function(BuildContext context, UndThemeData theme);
340
+ `);
341
+ return L.join('\n');
342
+ }
@@ -0,0 +1,29 @@
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 type { Context } from '../../dtcg/engine.js';
8
+ import type { MatValue } from '../materialize.js';
9
+ type Json = string | number | boolean | null | Json[] | {
10
+ [k: string]: Json;
11
+ };
12
+ type Tree = Record<string, Json>;
13
+ export declare function jsValue(ctx: Context, path: string, m?: MatValue): Json;
14
+ export declare function jsTree(ctx: Context): Tree;
15
+ export declare function jsFlat(ctx: Context): Map<string, Json>;
16
+ export declare function varsTree(ctx: Context): Tree;
17
+ /** Leaf-level diff of two flat maps (paths whose JSON differs). */
18
+ export declare function diffFlat(base: Map<string, Json>, next: Map<string, Json>): Record<string, Json>;
19
+ export interface JsBuildInput {
20
+ version: string;
21
+ defaultCtx: Context;
22
+ /** theme -> variant -> flat diff from default. */
23
+ contexts: Record<string, Record<string, Record<string, Json>>>;
24
+ /** theme -> variant -> modifier -> context -> flat diff from that variant. */
25
+ modifiers: Record<string, Record<string, Record<string, Record<string, Record<string, Json>>>>>;
26
+ themes: Json;
27
+ }
28
+ export declare function renderJs(input: JsBuildInput): Record<string, string>;
29
+ export {};
@@ -0,0 +1,297 @@
1
+ import { cssName } from '../css-values.js';
2
+ import { fluidClamp, hex8 } from '../css-values.js';
3
+ import { materialize } from '../materialize.js';
4
+ const fmt = (n) => String(Math.round(n * 10000) / 10000);
5
+ export function jsValue(ctx, path, m = materialize(ctx, path)) {
6
+ switch (m.kind) {
7
+ case 'color':
8
+ return m.alpha < 1 ? hex8(m.hex, m.alpha) : m.hex;
9
+ case 'dimension':
10
+ return m.css;
11
+ case 'number':
12
+ return m.unit ? `${m.value}${m.unit}` : m.value;
13
+ case 'duration':
14
+ return `${m.ms}ms`;
15
+ case 'easing': {
16
+ if (m.spring) {
17
+ const s = materialize(ctx, `spring.${m.spring}`);
18
+ if (s.kind === 'spring')
19
+ return s.linear;
20
+ }
21
+ const [a, b, c, d] = m.bezier;
22
+ return a === 0 && b === 0 && c === 1 && d === 1
23
+ ? 'linear'
24
+ : `cubic-bezier(${fmt(a)}, ${fmt(b)}, ${fmt(c)}, ${fmt(d)})`;
25
+ }
26
+ case 'fontFamily':
27
+ return m.families
28
+ .map((f) => (/^[a-z-]+$/.test(f) && !/[A-Z]/.test(f) ? f : `"${f}"`))
29
+ .join(', ');
30
+ case 'fontWeight':
31
+ return m.value;
32
+ case 'shadow':
33
+ return m.layers.length === 0
34
+ ? 'none'
35
+ : m.layers
36
+ .map((l) => `${l.inset ? 'inset ' : ''}${l.x ? `${l.x}px` : '0'} ${l.y ? `${l.y}px` : '0'} ${l.blur ? `${l.blur}px` : '0'} ${l.spread ? `${l.spread}px` : '0'} ${l.color.alpha < 1 ? hex8(l.color.hex, l.color.alpha) : l.color.hex}`)
37
+ .join(', ');
38
+ case 'typography':
39
+ return {
40
+ fontFamily: jsValue(ctx, path, { kind: 'fontFamily', families: m.families }),
41
+ fontSize: m.fluid
42
+ ? fluidClamp(m.minSizePx, m.sizePx, 360, 1440)
43
+ : m.sizeEm !== undefined
44
+ ? `${m.sizeEm}em`
45
+ : `${fmt(m.sizePx / 16)}rem`,
46
+ fontWeight: m.weight,
47
+ letterSpacing: m.letterSpacingEm === 0 ? '0' : `${m.letterSpacingEm}em`,
48
+ lineHeight: m.lineHeight,
49
+ lineHeightIndic: m.lineHeightIndic,
50
+ };
51
+ case 'spring':
52
+ return {
53
+ stiffness: m.stiffness,
54
+ damping: m.damping,
55
+ mass: m.mass,
56
+ response: m.response,
57
+ dampingRatio: m.dampingRatio,
58
+ bounce: m.bounce,
59
+ overshoot: m.overshoot,
60
+ settleMs: m.settleMs,
61
+ easing: m.linear,
62
+ fallback: `cubic-bezier(${m.bezier.map(fmt).join(', ')})`,
63
+ duration: `${m.settleMs}ms`,
64
+ };
65
+ }
66
+ }
67
+ function setDeep(tree, path, value) {
68
+ const parts = path.split('.');
69
+ let node = tree;
70
+ for (const p of parts.slice(0, -1)) {
71
+ if (typeof node[p] !== 'object' || node[p] === null)
72
+ node[p] = {};
73
+ node = node[p];
74
+ }
75
+ node[parts.at(-1)] = value;
76
+ }
77
+ export function jsTree(ctx) {
78
+ const tree = {};
79
+ for (const path of [...ctx.tokens.keys()].sort())
80
+ setDeep(tree, path, jsValue(ctx, path));
81
+ return tree;
82
+ }
83
+ export function jsFlat(ctx) {
84
+ const flat = new Map();
85
+ for (const path of [...ctx.tokens.keys()].sort())
86
+ flat.set(path, jsValue(ctx, path));
87
+ return flat;
88
+ }
89
+ export function varsTree(ctx) {
90
+ const tree = {};
91
+ for (const path of [...ctx.tokens.keys()].sort()) {
92
+ const t = ctx.tokens.get(path);
93
+ const name = cssName(path);
94
+ if (t.type === 'typography') {
95
+ setDeep(tree, path, {
96
+ fontFamily: `var(${name}-family)`,
97
+ fontSize: `var(${name}-size)`,
98
+ fontWeight: `var(${name}-weight)`,
99
+ letterSpacing: `var(${name}-tracking)`,
100
+ lineHeight: `var(${name}-lh)`,
101
+ font: `var(${name}-font)`,
102
+ });
103
+ }
104
+ else if (t.type === 'transition') {
105
+ setDeep(tree, path, { easing: `var(${name})`, duration: `var(${name}-duration)` });
106
+ }
107
+ else {
108
+ setDeep(tree, path, `var(${name})`);
109
+ }
110
+ }
111
+ return tree;
112
+ }
113
+ /** Leaf-level diff of two flat maps (paths whose JSON differs). */
114
+ export function diffFlat(base, next) {
115
+ const out = {};
116
+ for (const [k, v] of next)
117
+ if (JSON.stringify(base.get(k)) !== JSON.stringify(v))
118
+ out[k] = v;
119
+ return out;
120
+ }
121
+ // ---------------------------------------------------------------- d.ts
122
+ function tsType(value, indent) {
123
+ if (typeof value === 'string')
124
+ return 'string';
125
+ if (typeof value === 'number')
126
+ return 'number';
127
+ if (typeof value === 'boolean')
128
+ return 'boolean';
129
+ if (value === null)
130
+ return 'null';
131
+ if (Array.isArray(value))
132
+ return 'readonly unknown[]';
133
+ const obj = value;
134
+ if ('lineHeightIndic' in obj)
135
+ return 'UndTypography';
136
+ if ('stiffness' in obj && 'dampingRatio' in obj)
137
+ return 'UndSpring';
138
+ const inner = Object.entries(obj)
139
+ .map(([k, v]) => `${indent} readonly ${/^[A-Za-z_$][\w$]*$/.test(k) ? k : JSON.stringify(k)}: ${tsType(v, `${indent} `)};`)
140
+ .join('\n');
141
+ return `{\n${inner}\n${indent}}`;
142
+ }
143
+ function varsType(value, indent) {
144
+ if (typeof value === 'string')
145
+ return 'string';
146
+ const obj = value;
147
+ if ('font' in obj && 'lineHeight' in obj)
148
+ return 'UndTypographyVars';
149
+ if ('easing' in obj && 'duration' in obj && Object.keys(obj).length === 2)
150
+ return 'UndSpringVars';
151
+ const inner = Object.entries(obj)
152
+ .map(([k, v]) => `${indent} readonly ${/^[A-Za-z_$][\w$]*$/.test(k) ? k : JSON.stringify(k)}: ${varsType(v, `${indent} `)};`)
153
+ .join('\n');
154
+ return `{\n${inner}\n${indent}}`;
155
+ }
156
+ const HEADER = '// Generated by @und-ui/tokens. Do not edit.\n';
157
+ export function renderJs(input) {
158
+ const tokens = jsTree(input.defaultCtx);
159
+ const vars = varsTree(input.defaultCtx);
160
+ const files = {};
161
+ files['index.js'] = `${HEADER}import { contexts } from './contexts.js';
162
+
163
+ export const version = ${JSON.stringify(input.version)};
164
+
165
+ /** Default context: Ujala theme, light mode, standard contrast. */
166
+ export const tokens = ${JSON.stringify(tokens, null, 2)};
167
+
168
+ /** Same shape as tokens; every leaf is the CSS custom property (var(--und-...)). */
169
+ export const vars = ${JSON.stringify(vars, null, 2)};
170
+
171
+ export const themes = ${JSON.stringify(input.themes, null, 2)};
172
+
173
+ /** CSS custom property name for a token path, for example cssVarName('bg.surface') === '--und-bg-surface'. */
174
+ export function cssVarName(path) {
175
+ return '--und-' + path.split('.').join('-');
176
+ }
177
+
178
+ /** var() reference for a token path. */
179
+ export function cssVar(path) {
180
+ return 'var(' + cssVarName(path) + ')';
181
+ }
182
+
183
+ function clone(value) {
184
+ return JSON.parse(JSON.stringify(value));
185
+ }
186
+
187
+ function apply(tree, diff) {
188
+ for (const [path, value] of Object.entries(diff)) {
189
+ const parts = path.split('.');
190
+ let node = tree;
191
+ for (const p of parts.slice(0, -1)) node = node[p] ??= {};
192
+ node[parts[parts.length - 1]] = clone(value);
193
+ }
194
+ }
195
+
196
+ /**
197
+ * Resolve tokens for any combination of the resolver modifiers.
198
+ * Values match the CSS output for the same attributes (radius and tempo applied).
199
+ */
200
+ export function getTokens(input = {}) {
201
+ const theme = input.theme ?? 'ujala';
202
+ const meta = themes.find((t) => t.name === theme);
203
+ if (!meta) throw new Error('Unknown UND theme: ' + theme);
204
+ const mode = meta.modes.includes(input.mode ?? 'light') ? (input.mode ?? 'light') : meta.modes[0];
205
+ const variant = (input.contrast ?? 'standard') === 'more' ? mode + 'More' : mode;
206
+ const tree = clone(tokens);
207
+ apply(tree, contexts[theme][variant]);
208
+ for (const name of ['density', 'transparency', 'motion']) {
209
+ const ctx = input[name];
210
+ if (ctx && contexts.modifiers[theme][variant][name]?.[ctx]) apply(tree, contexts.modifiers[theme][variant][name][ctx]);
211
+ }
212
+ return tree;
213
+ }
214
+ `;
215
+ const ctxObj = { ...input.contexts, modifiers: input.modifiers };
216
+ files['contexts.js'] =
217
+ `${HEADER}/** Flat per-context diffs from the default context. Prefer getTokens(). */\nexport const contexts = ${JSON.stringify(ctxObj)};\n`;
218
+ files['contexts.d.ts'] = `${HEADER}export declare const contexts: Record<string, any>;\n`;
219
+ files['index.d.ts'] = `${HEADER}export interface UndTypography {
220
+ readonly fontFamily: string;
221
+ readonly fontSize: string;
222
+ readonly fontWeight: number;
223
+ readonly letterSpacing: string;
224
+ readonly lineHeight: number;
225
+ /** Line height for Devanagari and other Indic scripts. */
226
+ readonly lineHeightIndic: number;
227
+ }
228
+
229
+ export interface UndSpring {
230
+ readonly stiffness: number;
231
+ readonly damping: number;
232
+ readonly mass: number;
233
+ /** Period of the undamped spring, seconds (tempo applied). */
234
+ readonly response: number;
235
+ readonly dampingRatio: number;
236
+ /** SwiftUI bounce (1 - dampingRatio). */
237
+ readonly bounce: number;
238
+ readonly overshoot: number;
239
+ readonly settleMs: number;
240
+ /** CSS linear() approximation. */
241
+ readonly easing: string;
242
+ /** cubic-bezier() fallback. */
243
+ readonly fallback: string;
244
+ readonly duration: string;
245
+ }
246
+
247
+ export interface UndTypographyVars {
248
+ readonly fontFamily: string;
249
+ readonly fontSize: string;
250
+ readonly fontWeight: string;
251
+ readonly letterSpacing: string;
252
+ readonly lineHeight: string;
253
+ readonly font: string;
254
+ }
255
+
256
+ export interface UndSpringVars {
257
+ readonly easing: string;
258
+ readonly duration: string;
259
+ }
260
+
261
+ export type UndTokens = ${tsType(tokens, '')};
262
+
263
+ export type UndVars = ${varsType(vars, '')};
264
+
265
+ export type UndThemeName = ${input.themes.map((t) => JSON.stringify(t.name)).join(' | ')};
266
+
267
+ export interface UndThemeMeta {
268
+ readonly name: UndThemeName;
269
+ readonly label: string;
270
+ readonly personality: string;
271
+ readonly modes: readonly ('light' | 'dark')[];
272
+ readonly radiusFactor: number;
273
+ readonly tempo: number;
274
+ readonly character: 'crisp' | 'standard' | 'expressive';
275
+ readonly density: 'comfortable' | 'compact';
276
+ readonly glass: 'chrome' | 'on' | 'off';
277
+ }
278
+
279
+ export interface UndTokenInput {
280
+ theme?: UndThemeName;
281
+ mode?: 'light' | 'dark';
282
+ contrast?: 'standard' | 'more';
283
+ density?: 'auto' | 'comfortable' | 'compact' | 'touch';
284
+ transparency?: 'full' | 'reduced';
285
+ motion?: 'full' | 'reduced';
286
+ }
287
+
288
+ export declare const version: string;
289
+ export declare const tokens: UndTokens;
290
+ export declare const vars: UndVars;
291
+ export declare const themes: readonly UndThemeMeta[];
292
+ export declare function cssVarName(path: string): string;
293
+ export declare function cssVar(path: string): string;
294
+ export declare function getTokens(input?: UndTokenInput): UndTokens;
295
+ `;
296
+ return files;
297
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Jetpack Compose output: UndTokens.kt (package dev.undui.tokens).
3
+ * UndColors (data class per theme x variant), UndTypography, UndSpacing,
4
+ * UndRadii, UndMotion and UndControl objects. Wide-gamut colours use
5
+ * ColorSpaces.DisplayP3.
6
+ */
7
+ import type { NativeModel } from '../native-model.js';
8
+ export declare function renderKotlin(model: NativeModel): string;