@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.
- package/LICENSE +21 -0
- package/README.md +345 -2
- package/dist/android/values/und_colors.xml +91 -0
- package/dist/android/values/und_dimens.xml +93 -0
- package/dist/android/values-night/und_colors.xml +91 -0
- package/dist/css/base.css +2335 -0
- package/dist/css/motion.css +223 -0
- package/dist/css/themes/kesar.css +68 -0
- package/dist/css/themes/mitti.css +84 -0
- package/dist/css/themes/neem.css +84 -0
- package/dist/css/themes/raat.css +507 -0
- package/dist/css/themes/sutra.css +109 -0
- package/dist/css/themes/ujala.css +67 -0
- package/dist/css/tokens.css +3167 -0
- package/dist/dart/und_tokens.dart +3223 -0
- package/dist/js/contexts.d.ts +2 -0
- package/dist/js/contexts.js +3 -0
- package/dist/js/index.d.ts +1883 -0
- package/dist/js/index.js +2230 -0
- package/dist/json/flat/kesar.dark.json +737 -0
- package/dist/json/flat/kesar.darkMore.json +737 -0
- package/dist/json/flat/kesar.light.json +737 -0
- package/dist/json/flat/kesar.lightMore.json +737 -0
- package/dist/json/flat/mitti.dark.json +737 -0
- package/dist/json/flat/mitti.darkMore.json +737 -0
- package/dist/json/flat/mitti.light.json +737 -0
- package/dist/json/flat/mitti.lightMore.json +737 -0
- package/dist/json/flat/neem.dark.json +737 -0
- package/dist/json/flat/neem.darkMore.json +737 -0
- package/dist/json/flat/neem.light.json +737 -0
- package/dist/json/flat/neem.lightMore.json +737 -0
- package/dist/json/flat/raat.dark.json +737 -0
- package/dist/json/flat/raat.darkMore.json +737 -0
- package/dist/json/flat/sutra.dark.json +738 -0
- package/dist/json/flat/sutra.darkMore.json +738 -0
- package/dist/json/flat/sutra.light.json +738 -0
- package/dist/json/flat/sutra.lightMore.json +738 -0
- package/dist/json/flat/ujala.dark.json +737 -0
- package/dist/json/flat/ujala.darkMore.json +737 -0
- package/dist/json/flat/ujala.light.json +737 -0
- package/dist/json/flat/ujala.lightMore.json +737 -0
- package/dist/json/nested/kesar.dark.json +885 -0
- package/dist/json/nested/kesar.darkMore.json +885 -0
- package/dist/json/nested/kesar.light.json +885 -0
- package/dist/json/nested/kesar.lightMore.json +885 -0
- package/dist/json/nested/mitti.dark.json +885 -0
- package/dist/json/nested/mitti.darkMore.json +885 -0
- package/dist/json/nested/mitti.light.json +885 -0
- package/dist/json/nested/mitti.lightMore.json +885 -0
- package/dist/json/nested/neem.dark.json +885 -0
- package/dist/json/nested/neem.darkMore.json +885 -0
- package/dist/json/nested/neem.light.json +885 -0
- package/dist/json/nested/neem.lightMore.json +885 -0
- package/dist/json/nested/raat.dark.json +885 -0
- package/dist/json/nested/raat.darkMore.json +885 -0
- package/dist/json/nested/sutra.dark.json +886 -0
- package/dist/json/nested/sutra.darkMore.json +886 -0
- package/dist/json/nested/sutra.light.json +886 -0
- package/dist/json/nested/sutra.lightMore.json +886 -0
- package/dist/json/nested/ujala.dark.json +885 -0
- package/dist/json/nested/ujala.darkMore.json +885 -0
- package/dist/json/nested/ujala.light.json +885 -0
- package/dist/json/nested/ujala.lightMore.json +885 -0
- package/dist/kotlin/UndTokens.kt +2870 -0
- package/dist/lib/build/contexts.d.ts +13 -0
- package/dist/lib/build/contexts.js +20 -0
- package/dist/lib/build/css-values.d.ts +31 -0
- package/dist/lib/build/css-values.js +191 -0
- package/dist/lib/build/formats/css.d.ts +43 -0
- package/dist/lib/build/formats/css.js +380 -0
- package/dist/lib/build/formats/dart.d.ts +9 -0
- package/dist/lib/build/formats/dart.js +342 -0
- package/dist/lib/build/formats/js.d.ts +29 -0
- package/dist/lib/build/formats/js.js +297 -0
- package/dist/lib/build/formats/kotlin.d.ts +8 -0
- package/dist/lib/build/formats/kotlin.js +232 -0
- package/dist/lib/build/formats/react-native.d.ts +2 -0
- package/dist/lib/build/formats/react-native.js +208 -0
- package/dist/lib/build/formats/style-dictionary.d.ts +8 -0
- package/dist/lib/build/formats/style-dictionary.js +163 -0
- package/dist/lib/build/formats/swift.d.ts +8 -0
- package/dist/lib/build/formats/swift.js +395 -0
- package/dist/lib/build/formats/tailwind.d.ts +9 -0
- package/dist/lib/build/formats/tailwind.js +105 -0
- package/dist/lib/build/index.d.ts +12 -0
- package/dist/lib/build/index.js +133 -0
- package/dist/lib/build/materialize.d.ts +102 -0
- package/dist/lib/build/materialize.js +170 -0
- package/dist/lib/build/native-model.d.ts +46 -0
- package/dist/lib/build/native-model.js +177 -0
- package/dist/lib/color/contrast.d.ts +24 -0
- package/dist/lib/color/contrast.js +95 -0
- package/dist/lib/color/convert.d.ts +39 -0
- package/dist/lib/color/convert.js +91 -0
- package/dist/lib/color/pairs.d.ts +29 -0
- package/dist/lib/color/pairs.js +90 -0
- package/dist/lib/color/palette.d.ts +118 -0
- package/dist/lib/color/palette.js +199 -0
- package/dist/lib/color/scales.d.ts +18 -0
- package/dist/lib/color/scales.js +115 -0
- package/dist/lib/dtcg/engine.d.ts +75 -0
- package/dist/lib/dtcg/engine.js +395 -0
- package/dist/lib/dtcg/format-json.d.ts +1 -0
- package/dist/lib/dtcg/format-json.js +59 -0
- package/dist/lib/dtcg/types.d.ts +124 -0
- package/dist/lib/dtcg/types.js +54 -0
- package/dist/lib/index.d.ts +20 -0
- package/dist/lib/index.js +14 -0
- package/dist/lib/motion/spring.d.ts +40 -0
- package/dist/lib/motion/spring.js +129 -0
- package/dist/lib/source/generate.d.ts +28 -0
- package/dist/lib/source/generate.js +468 -0
- package/dist/lib/themes/definitions.d.ts +43 -0
- package/dist/lib/themes/definitions.js +140 -0
- package/dist/react-native/index.d.ts +130 -0
- package/dist/react-native/index.js +15 -0
- package/dist/react-native/tokens.d.ts +2 -0
- package/dist/react-native/tokens.js +4413 -0
- package/dist/scss/_variables.scss +738 -0
- package/dist/scss/_vars.scss +857 -0
- package/dist/scss/kesar.dark.scss +738 -0
- package/dist/scss/kesar.darkMore.scss +738 -0
- package/dist/scss/kesar.light.scss +738 -0
- package/dist/scss/kesar.lightMore.scss +738 -0
- package/dist/scss/mitti.dark.scss +738 -0
- package/dist/scss/mitti.darkMore.scss +738 -0
- package/dist/scss/mitti.light.scss +738 -0
- package/dist/scss/mitti.lightMore.scss +738 -0
- package/dist/scss/neem.dark.scss +738 -0
- package/dist/scss/neem.darkMore.scss +738 -0
- package/dist/scss/neem.light.scss +738 -0
- package/dist/scss/neem.lightMore.scss +738 -0
- package/dist/scss/raat.dark.scss +738 -0
- package/dist/scss/raat.darkMore.scss +738 -0
- package/dist/scss/sutra.dark.scss +739 -0
- package/dist/scss/sutra.darkMore.scss +739 -0
- package/dist/scss/sutra.light.scss +739 -0
- package/dist/scss/sutra.lightMore.scss +739 -0
- package/dist/scss/ujala.dark.scss +738 -0
- package/dist/scss/ujala.darkMore.scss +738 -0
- package/dist/scss/ujala.light.scss +738 -0
- package/dist/scss/ujala.lightMore.scss +738 -0
- package/dist/swift/UndTokens.swift +4117 -0
- package/dist/tailwind/und.css +586 -0
- package/package.json +84 -3
- package/tokens/contrast/more.tokens.json +46 -0
- package/tokens/density/comfortable.tokens.json +64 -0
- package/tokens/density/compact.tokens.json +68 -0
- package/tokens/density/touch.tokens.json +64 -0
- package/tokens/modes/dark.tokens.json +197 -0
- package/tokens/modes/light.tokens.json +166 -0
- package/tokens/motion/reduced.tokens.json +119 -0
- package/tokens/primitives/color.dark.tokens.json +2001 -0
- package/tokens/primitives/color.light.tokens.json +2077 -0
- package/tokens/primitives/dimension.tokens.json +181 -0
- package/tokens/primitives/motion.tokens.json +41 -0
- package/tokens/primitives/spring.tokens.json +138 -0
- package/tokens/primitives/typography.tokens.json +107 -0
- package/tokens/semantic/bridge.tokens.json +52 -0
- package/tokens/semantic/color.tokens.json +129 -0
- package/tokens/semantic/layout.tokens.json +84 -0
- package/tokens/semantic/motion.tokens.json +111 -0
- package/tokens/semantic/scale.tokens.json +66 -0
- package/tokens/semantic/typography.tokens.json +281 -0
- package/tokens/themes/kesar.tokens.json +105 -0
- package/tokens/themes/mitti.tokens.json +123 -0
- package/tokens/themes/neem.tokens.json +123 -0
- package/tokens/themes/raat.tokens.json +104 -0
- package/tokens/themes/sutra.tokens.json +126 -0
- package/tokens/themes/ujala.tokens.json +96 -0
- package/tokens/transparency/reduced.tokens.json +30 -0
- package/tokens/und.resolver.json +83 -0
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import { VARIANTS, camel, stepName } from '../native-model.js';
|
|
2
|
+
const n = (v) => {
|
|
3
|
+
const r = Math.round(v * 10000) / 10000;
|
|
4
|
+
return Number.isInteger(r) ? `${r}` : `${r}`;
|
|
5
|
+
};
|
|
6
|
+
const str = (s) => JSON.stringify(s);
|
|
7
|
+
function rgba(c) {
|
|
8
|
+
if (c.p3)
|
|
9
|
+
return `UndRGBA(${n(c.p3[0])}, ${n(c.p3[1])}, ${n(c.p3[2])}, ${n(c.alpha)}, space: .displayP3)`;
|
|
10
|
+
return `UndRGBA(${n(c.rgb[0])}, ${n(c.rgb[1])}, ${n(c.rgb[2])}, ${n(c.alpha)})`;
|
|
11
|
+
}
|
|
12
|
+
const IOS_WEIGHT = {
|
|
13
|
+
regular: '.regular',
|
|
14
|
+
medium: '.medium',
|
|
15
|
+
semibold: '.semibold',
|
|
16
|
+
bold: '.bold',
|
|
17
|
+
};
|
|
18
|
+
const IOS_STYLE = {
|
|
19
|
+
largeTitle: '.largeTitle',
|
|
20
|
+
title: '.title',
|
|
21
|
+
title2: '.title2',
|
|
22
|
+
title3: '.title3',
|
|
23
|
+
headline: '.headline',
|
|
24
|
+
body: '.body',
|
|
25
|
+
callout: '.callout',
|
|
26
|
+
subheadline: '.subheadline',
|
|
27
|
+
footnote: '.footnote',
|
|
28
|
+
caption: '.caption',
|
|
29
|
+
caption2: '.caption2',
|
|
30
|
+
};
|
|
31
|
+
export function renderSwift(model) {
|
|
32
|
+
const roles = model.colorRoles.map(([name]) => name);
|
|
33
|
+
const L = [];
|
|
34
|
+
L.push(`// Generated by @und-ui/tokens ${model.version}. Do not edit.
|
|
35
|
+
// Source: DTCG 2025.10 tokens (packages/tokens/tokens). Semantic roles only.
|
|
36
|
+
|
|
37
|
+
import Foundation
|
|
38
|
+
#if canImport(CoreGraphics)
|
|
39
|
+
import CoreGraphics
|
|
40
|
+
#endif
|
|
41
|
+
|
|
42
|
+
public enum UndTokens {
|
|
43
|
+
public static let version = ${str(model.version)}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/// A colour value (components 0...1) in sRGB or Display P3.
|
|
47
|
+
public struct UndRGBA: Sendable, Equatable, Hashable {
|
|
48
|
+
public enum Space: Sendable, Equatable, Hashable { case sRGB, displayP3 }
|
|
49
|
+
public let red: Double
|
|
50
|
+
public let green: Double
|
|
51
|
+
public let blue: Double
|
|
52
|
+
public let alpha: Double
|
|
53
|
+
public let space: Space
|
|
54
|
+
|
|
55
|
+
public init(_ red: Double, _ green: Double, _ blue: Double, _ alpha: Double = 1, space: Space = .sRGB) {
|
|
56
|
+
self.red = red
|
|
57
|
+
self.green = green
|
|
58
|
+
self.blue = blue
|
|
59
|
+
self.alpha = alpha
|
|
60
|
+
self.space = space
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/// A semantic colour resolved for every appearance: light, dark, and Increase Contrast.
|
|
65
|
+
public struct UndDynamicColor: Sendable, Equatable, Hashable {
|
|
66
|
+
public let light: UndRGBA
|
|
67
|
+
public let dark: UndRGBA
|
|
68
|
+
public let lightMore: UndRGBA
|
|
69
|
+
public let darkMore: UndRGBA
|
|
70
|
+
|
|
71
|
+
public init(light: UndRGBA, dark: UndRGBA, lightMore: UndRGBA, darkMore: UndRGBA) {
|
|
72
|
+
self.light = light
|
|
73
|
+
self.dark = dark
|
|
74
|
+
self.lightMore = lightMore
|
|
75
|
+
self.darkMore = darkMore
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public func resolve(dark isDark: Bool, increasedContrast: Bool) -> UndRGBA {
|
|
79
|
+
switch (isDark, increasedContrast) {
|
|
80
|
+
case (false, false): return light
|
|
81
|
+
case (true, false): return dark
|
|
82
|
+
case (false, true): return lightMore
|
|
83
|
+
case (true, true): return darkMore
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public enum UndThemeName: String, CaseIterable, Sendable {
|
|
89
|
+
${model.themes.map((t) => ` case ${t.def.name}`).join('\n')}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public enum UndCharacter: String, Sendable { case crisp, standard, expressive }
|
|
93
|
+
public enum UndDensity: String, Sendable { case comfortable, compact, touch }
|
|
94
|
+
public enum UndGlass: String, Sendable { case chrome, on, off }
|
|
95
|
+
`);
|
|
96
|
+
// Colour roles struct
|
|
97
|
+
L.push(`/// Semantic colour roles (names generated from token paths, for example bg.surface -> bgSurface).
|
|
98
|
+
public struct UndColorRoles: Sendable, Equatable {
|
|
99
|
+
${roles.map((r) => ` public let ${r}: UndDynamicColor`).join('\n')}
|
|
100
|
+
}
|
|
101
|
+
`);
|
|
102
|
+
L.push('extension UndColorRoles {');
|
|
103
|
+
for (const t of model.themes) {
|
|
104
|
+
L.push(` public static let ${t.def.name} = UndColorRoles(`);
|
|
105
|
+
L.push(roles
|
|
106
|
+
.map((r) => {
|
|
107
|
+
const parts = VARIANTS.map((v) => `${v}: ${rgba(t.colors[v].get(r))}`).join(',\n ');
|
|
108
|
+
return ` ${r}: UndDynamicColor(\n ${parts}\n )`;
|
|
109
|
+
})
|
|
110
|
+
.join(',\n'));
|
|
111
|
+
L.push(' )');
|
|
112
|
+
}
|
|
113
|
+
L.push('}\n');
|
|
114
|
+
// Spacing / sizes
|
|
115
|
+
const cg = (name, entries, doc, prefix = 's') => `/// ${doc}\npublic enum ${name} {\n${[...entries].map(([k, v]) => ` public static let ${stepName(k, prefix)}: CGFloat = ${n(v)}`).join('\n')}\n}\n`;
|
|
116
|
+
L.push(cg('UndSpacing', model.spacing, '4pt spacing scale (report 3.1). Density never changes these.'));
|
|
117
|
+
L.push(cg('UndIconSize', model.iconSize, 'Icon sizes.'));
|
|
118
|
+
L.push(cg('UndBorderWidth', model.borderWidth, 'Border widths. Use 1 / displayScale for hairlines.'));
|
|
119
|
+
L.push(cg('UndBreakpoint', model.breakpoint, 'Breakpoints in points (for size classes and window widths).', 'w'));
|
|
120
|
+
L.push(`/// Focus ring and hit-target metrics.
|
|
121
|
+
public enum UndFocus {
|
|
122
|
+
public static let width: CGFloat = ${n(model.focus.width)}
|
|
123
|
+
public static let widthIncreasedContrast: CGFloat = ${n(model.focus.widthMore)}
|
|
124
|
+
public static let offset: CGFloat = ${n(model.focus.offset)}
|
|
125
|
+
/// Minimum hit area on iOS (HIG).
|
|
126
|
+
public static let minimumTarget: CGFloat = ${n(model.target.touch)}
|
|
127
|
+
}
|
|
128
|
+
`);
|
|
129
|
+
const controlKeys = [...model.control.comfortable.keys()];
|
|
130
|
+
L.push(`/// Control metrics for a density.
|
|
131
|
+
public struct UndControlMetrics: Sendable, Equatable {
|
|
132
|
+
${controlKeys.map((k) => ` public let ${stepName(k)}: CGFloat`).join('\n')}
|
|
133
|
+
|
|
134
|
+
${['comfortable', 'compact', 'touch']
|
|
135
|
+
.map((d) => ` public static let ${d} = UndControlMetrics(${controlKeys.map((k) => `${stepName(k)}: ${n(model.control[d].get(k))}`).join(', ')})`)
|
|
136
|
+
.join('\n')}
|
|
137
|
+
|
|
138
|
+
public static func of(_ density: UndDensity) -> UndControlMetrics {
|
|
139
|
+
switch density {
|
|
140
|
+
case .comfortable: return .comfortable
|
|
141
|
+
case .compact: return .compact
|
|
142
|
+
case .touch: return .touch
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
`);
|
|
147
|
+
// Radius
|
|
148
|
+
const radiusKeys = [...model.themes[0].radius.keys()].filter((k) => k !== 'factor');
|
|
149
|
+
L.push(`/// Radius scale with the theme radius factor applied (report 3.3).
|
|
150
|
+
public struct UndRadius: Sendable, Equatable {
|
|
151
|
+
public let factor: CGFloat
|
|
152
|
+
${radiusKeys.map((k) => ` public let ${stepName(k)}: CGFloat`).join('\n')}
|
|
153
|
+
|
|
154
|
+
/// Concentric inner radius: outer - padding, at least 2.
|
|
155
|
+
public func inner(outer: CGFloat, padding: CGFloat) -> CGFloat { max(2, outer - padding) }
|
|
156
|
+
}
|
|
157
|
+
`);
|
|
158
|
+
// Motion
|
|
159
|
+
const durNames = [...model.themes[0].durations.keys()];
|
|
160
|
+
const springNames = [...model.themes[0].springs.keys()];
|
|
161
|
+
L.push(`/// Cubic-bezier control points.
|
|
162
|
+
public struct UndEasing: Sendable, Equatable {
|
|
163
|
+
public let x1: Double
|
|
164
|
+
public let y1: Double
|
|
165
|
+
public let x2: Double
|
|
166
|
+
public let y2: Double
|
|
167
|
+
/// Spring preset to use instead, when the theme character is expressive.
|
|
168
|
+
public let spring: String?
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/// Spring defined perceptually (response, damping ratio) with mass 1 (report 4.4).
|
|
172
|
+
public struct UndSpring: Sendable, Equatable {
|
|
173
|
+
public let response: Double
|
|
174
|
+
public let dampingFraction: Double
|
|
175
|
+
public let stiffness: Double
|
|
176
|
+
public let damping: Double
|
|
177
|
+
public let mass: Double
|
|
178
|
+
/// iOS 17 spring(duration:bounce:) bounce, about 1 - dampingFraction.
|
|
179
|
+
public let bounce: Double
|
|
180
|
+
/// Settle time (+-0.1%), seconds.
|
|
181
|
+
public let settle: Double
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/// Durations (seconds, theme tempo applied), easings and springs.
|
|
185
|
+
public struct UndMotion: Sendable, Equatable {
|
|
186
|
+
public let tempo: Double
|
|
187
|
+
public let character: UndCharacter
|
|
188
|
+
${durNames.map((d) => ` public let ${camel(d)}: TimeInterval`).join('\n')}
|
|
189
|
+
${[...model.themes[0].easings.keys()].map((e) => ` public let ${camel(e)}: UndEasing`).join('\n')}
|
|
190
|
+
${springNames.map((s) => ` public let spring${s.charAt(0).toUpperCase()}${s.slice(1)}: UndSpring`).join('\n')}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/// Reduced-motion durations (seconds). Never scaled by tempo; themes cannot loosen them (report 4.6).
|
|
194
|
+
public enum UndReducedMotion {
|
|
195
|
+
${[...model.reducedDurations].map(([k, v]) => ` public static let ${camel(k)}: TimeInterval = ${n(v / 1000)}`).join('\n')}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/// Font roles. Native defaults to system fonts (Dynamic Type); these families are the opt-in brand stack.
|
|
199
|
+
public struct UndTypeface: Sendable, Equatable {
|
|
200
|
+
public let body: [String]
|
|
201
|
+
public let heading: [String]
|
|
202
|
+
public let display: [String]
|
|
203
|
+
public let code: [String]
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/// A text style mapped to an iOS Dynamic Type style (report 2.3).
|
|
207
|
+
public struct UndTextStyle: Sendable, Equatable {
|
|
208
|
+
/// Point size at the default (Large) content size.
|
|
209
|
+
public let size: CGFloat
|
|
210
|
+
/// Dynamic Type style it scales with (UIFont.TextStyle raw name).
|
|
211
|
+
public let textStyle: String
|
|
212
|
+
public let weight: String
|
|
213
|
+
public let lineHeight: CGFloat
|
|
214
|
+
/// Line height multiplier for Devanagari and other Indic scripts.
|
|
215
|
+
public let lineHeightIndic: CGFloat
|
|
216
|
+
/// Letter spacing in em (Latin only; never track Indic scripts).
|
|
217
|
+
public let trackingEm: CGFloat
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
public enum UndTypography {
|
|
221
|
+
${[...model.typography]
|
|
222
|
+
.map(([k, t]) => {
|
|
223
|
+
const ios = t.ios ?? { textStyle: 'body', size: t.minSizePx, weight: 'regular' };
|
|
224
|
+
return ` public static let ${camel(k)} = UndTextStyle(size: ${n(ios.size)}, textStyle: ${str(ios.textStyle)}, weight: ${str(ios.weight)}, lineHeight: ${n(t.lineHeight)}, lineHeightIndic: ${n(t.lineHeightIndic)}, trackingEm: ${n(t.letterSpacingEm)})`;
|
|
225
|
+
})
|
|
226
|
+
.join('\n')}
|
|
227
|
+
}
|
|
228
|
+
`);
|
|
229
|
+
// Theme
|
|
230
|
+
L.push(`/// A complete UND theme. Provide it through the SwiftUI environment.
|
|
231
|
+
public struct UndTheme: Sendable, Equatable {
|
|
232
|
+
public let name: UndThemeName
|
|
233
|
+
public let label: String
|
|
234
|
+
/// true for dark-only themes (Raat).
|
|
235
|
+
public let darkOnly: Bool
|
|
236
|
+
public let colors: UndColorRoles
|
|
237
|
+
public let radius: UndRadius
|
|
238
|
+
public let motion: UndMotion
|
|
239
|
+
public let typeface: UndTypeface
|
|
240
|
+
public let density: UndDensity
|
|
241
|
+
public let glass: UndGlass
|
|
242
|
+
`);
|
|
243
|
+
for (const t of model.themes) {
|
|
244
|
+
const e = (k) => {
|
|
245
|
+
const m = t.easings.get(k);
|
|
246
|
+
return `UndEasing(x1: ${n(m.bezier[0])}, y1: ${n(m.bezier[1])}, x2: ${n(m.bezier[2])}, y2: ${n(m.bezier[3])}, spring: ${m.spring ? str(m.spring) : 'nil'})`;
|
|
247
|
+
};
|
|
248
|
+
const motion = [
|
|
249
|
+
`tempo: ${n(t.tempo)}`,
|
|
250
|
+
`character: .${t.def.character}`,
|
|
251
|
+
...durNames.map((d) => `${camel(d)}: ${n(t.durations.get(d) / 1000)}`),
|
|
252
|
+
...[...t.easings.keys()].map((k) => `${camel(k)}: ${e(k)}`),
|
|
253
|
+
...springNames.map((s) => {
|
|
254
|
+
const sp = t.springs.get(s);
|
|
255
|
+
return `spring${s.charAt(0).toUpperCase()}${s.slice(1)}: UndSpring(response: ${n(sp.response)}, dampingFraction: ${n(sp.dampingRatio)}, stiffness: ${n(sp.stiffness)}, damping: ${n(sp.damping)}, mass: 1, bounce: ${n(sp.bounce)}, settle: ${n(sp.settleMs / 1000)})`;
|
|
256
|
+
}),
|
|
257
|
+
];
|
|
258
|
+
L.push(` public static let ${t.def.name} = UndTheme(
|
|
259
|
+
name: .${t.def.name},
|
|
260
|
+
label: ${str(t.def.label)},
|
|
261
|
+
darkOnly: ${t.def.modes.length === 1 ? 'true' : 'false'},
|
|
262
|
+
colors: .${t.def.name},
|
|
263
|
+
radius: UndRadius(factor: ${n(t.def.radiusFactor)}, ${radiusKeys.map((k) => `${stepName(k)}: ${n(t.radius.get(k))}`).join(', ')}),
|
|
264
|
+
motion: UndMotion(
|
|
265
|
+
${motion.join(',\n ')}
|
|
266
|
+
),
|
|
267
|
+
typeface: UndTypeface(body: ${JSON.stringify(t.typeface.body)}, heading: ${JSON.stringify(t.typeface.heading)}, display: ${JSON.stringify(t.typeface.display)}, code: ${JSON.stringify(t.typeface.code)}),
|
|
268
|
+
density: .${t.def.density},
|
|
269
|
+
glass: .${t.def.glass}
|
|
270
|
+
)
|
|
271
|
+
`);
|
|
272
|
+
}
|
|
273
|
+
L.push(` public static func named(_ name: UndThemeName) -> UndTheme {
|
|
274
|
+
switch name {
|
|
275
|
+
${model.themes.map((t) => ` case .${t.def.name}: return .${t.def.name}`).join('\n')}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
`);
|
|
280
|
+
// SwiftUI layer
|
|
281
|
+
L.push(`#if canImport(SwiftUI)
|
|
282
|
+
import SwiftUI
|
|
283
|
+
#if canImport(UIKit)
|
|
284
|
+
import UIKit
|
|
285
|
+
#elseif canImport(AppKit)
|
|
286
|
+
import AppKit
|
|
287
|
+
#endif
|
|
288
|
+
|
|
289
|
+
extension UndRGBA {
|
|
290
|
+
public var color: Color {
|
|
291
|
+
Color(space == .displayP3 ? .displayP3 : .sRGB, red: red, green: green, blue: blue, opacity: alpha)
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
extension UndDynamicColor {
|
|
296
|
+
/// A SwiftUI Color that follows light/dark appearance and Increase Contrast.
|
|
297
|
+
public var color: Color {
|
|
298
|
+
#if canImport(UIKit) && !os(watchOS)
|
|
299
|
+
return Color(uiColor: UIColor { traits in
|
|
300
|
+
let value = resolve(dark: traits.userInterfaceStyle == .dark, increasedContrast: traits.accessibilityContrast == .high)
|
|
301
|
+
return value.space == .displayP3
|
|
302
|
+
? UIColor(displayP3Red: value.red, green: value.green, blue: value.blue, alpha: value.alpha)
|
|
303
|
+
: UIColor(red: value.red, green: value.green, blue: value.blue, alpha: value.alpha)
|
|
304
|
+
})
|
|
305
|
+
#elseif canImport(AppKit)
|
|
306
|
+
return Color(nsColor: NSColor(name: nil) { appearance in
|
|
307
|
+
let match = appearance.bestMatch(from: [.aqua, .darkAqua, .accessibilityHighContrastAqua, .accessibilityHighContrastDarkAqua])
|
|
308
|
+
let isDark = match == .darkAqua || match == .accessibilityHighContrastDarkAqua
|
|
309
|
+
let more = match == .accessibilityHighContrastAqua || match == .accessibilityHighContrastDarkAqua
|
|
310
|
+
let value = resolve(dark: isDark, increasedContrast: more)
|
|
311
|
+
return value.space == .displayP3
|
|
312
|
+
? NSColor(displayP3Red: value.red, green: value.green, blue: value.blue, alpha: value.alpha)
|
|
313
|
+
: NSColor(srgbRed: value.red, green: value.green, blue: value.blue, alpha: value.alpha)
|
|
314
|
+
})
|
|
315
|
+
#else
|
|
316
|
+
return dark.color
|
|
317
|
+
#endif
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/// SwiftUI Colors for a theme's semantic roles.
|
|
322
|
+
public struct UndColors {
|
|
323
|
+
${roles.map((r) => ` public let ${r}: Color`).join('\n')}
|
|
324
|
+
|
|
325
|
+
public init(_ roles: UndColorRoles) {
|
|
326
|
+
${roles.map((r) => ` ${r} = roles.${r}.color`).join('\n')}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
extension UndSpring {
|
|
331
|
+
/// SwiftUI spring with the same physics.
|
|
332
|
+
public var animation: Animation {
|
|
333
|
+
.spring(response: response, dampingFraction: dampingFraction, blendDuration: 0)
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
extension UndEasing {
|
|
338
|
+
public func animation(duration: TimeInterval) -> Animation {
|
|
339
|
+
.timingCurve(x1, y1, x2, y2, duration: duration)
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
extension UndTextStyle {
|
|
344
|
+
var swiftUITextStyle: Font.TextStyle {
|
|
345
|
+
switch textStyle {
|
|
346
|
+
${Object.entries(IOS_STYLE)
|
|
347
|
+
.map(([k, v]) => ` case ${str(k)}: return ${v}`)
|
|
348
|
+
.join('\n')}
|
|
349
|
+
default: return .body
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
var swiftUIWeight: Font.Weight {
|
|
354
|
+
switch weight {
|
|
355
|
+
${Object.entries(IOS_WEIGHT)
|
|
356
|
+
.map(([k, v]) => ` case ${str(k)}: return ${v}`)
|
|
357
|
+
.join('\n')}
|
|
358
|
+
default: return .regular
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/// System font at the matching Dynamic Type style (scales through all accessibility sizes).
|
|
363
|
+
public var font: Font {
|
|
364
|
+
.system(swiftUITextStyle, design: .default, weight: swiftUIWeight)
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/// Brand font (opt-in) relative to the matching Dynamic Type style.
|
|
368
|
+
public func font(family: String) -> Font {
|
|
369
|
+
.custom(family, size: size, relativeTo: swiftUITextStyle).weight(swiftUIWeight)
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
private struct UndThemeKey: EnvironmentKey {
|
|
374
|
+
static let defaultValue: UndTheme = .ujala
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
extension EnvironmentValues {
|
|
378
|
+
/// The active UND theme. Set it with .undTheme(.kesar).
|
|
379
|
+
public var undTheme: UndTheme {
|
|
380
|
+
get { self[UndThemeKey.self] }
|
|
381
|
+
set { self[UndThemeKey.self] = newValue }
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
extension View {
|
|
386
|
+
/// Applies an UND theme; dark-only themes force the dark colour scheme.
|
|
387
|
+
public func undTheme(_ theme: UndTheme) -> some View {
|
|
388
|
+
environment(\\.undTheme, theme)
|
|
389
|
+
.preferredColorScheme(theme.darkOnly ? .dark : nil)
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
#endif
|
|
393
|
+
`);
|
|
394
|
+
return L.join('\n');
|
|
395
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tailwind CSS v4 preset: an `@theme inline` block mapping Tailwind namespaces
|
|
3
|
+
* to UND custom properties, so utilities follow the active UND theme/mode at
|
|
4
|
+
* runtime (bg-bg-surface, text-fg-muted, border-border-control, rounded-control,
|
|
5
|
+
* shadow-2, font-heading, text-body-md, ease-enter, p-4 = 1rem ...).
|
|
6
|
+
* Load after `@import "tailwindcss"` and `@und-ui/tokens/css`.
|
|
7
|
+
*/
|
|
8
|
+
import type { Context } from '../../dtcg/engine.js';
|
|
9
|
+
export declare function renderTailwind(ctx: Context, themes: string[], version: string): string;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { isBridge } from '../../dtcg/types.js';
|
|
2
|
+
import { cssName } from '../css-values.js';
|
|
3
|
+
import { materialize } from '../materialize.js';
|
|
4
|
+
export function renderTailwind(ctx, themes, version) {
|
|
5
|
+
const lines = [];
|
|
6
|
+
const paths = [...ctx.tokens.keys()].filter((p) => !isBridge(ctx.tokens.get(p))).sort();
|
|
7
|
+
const colorRoots = [
|
|
8
|
+
'bg',
|
|
9
|
+
'fg',
|
|
10
|
+
'border',
|
|
11
|
+
'accent',
|
|
12
|
+
'focus',
|
|
13
|
+
'status',
|
|
14
|
+
'link',
|
|
15
|
+
'dataviz',
|
|
16
|
+
'selection',
|
|
17
|
+
];
|
|
18
|
+
const add = (k, v) => lines.push(` ${k}: ${v};`);
|
|
19
|
+
lines.push(' /* Colours: semantic roles (theme-aware) */');
|
|
20
|
+
for (const p of paths) {
|
|
21
|
+
const t = ctx.tokens.get(p);
|
|
22
|
+
if (t.type === 'color' && colorRoots.includes(p.split('.')[0]))
|
|
23
|
+
add(`--color-${p.replace(/\./g, '-')}`, `var(${cssName(p)})`);
|
|
24
|
+
}
|
|
25
|
+
lines.push(' /* Colours: primitive scales (prefer semantic roles) */');
|
|
26
|
+
for (const p of paths) {
|
|
27
|
+
const t = ctx.tokens.get(p);
|
|
28
|
+
if (t.type === 'color' && p.startsWith('color.') && !/\.(white|black|transparent)$/.test(p))
|
|
29
|
+
add(`--color-${p.slice(6).replace(/\./g, '-')}`, `var(${cssName(p)})`);
|
|
30
|
+
}
|
|
31
|
+
add('--color-white', 'var(--und-color-white)');
|
|
32
|
+
add('--color-black', 'var(--und-color-black)');
|
|
33
|
+
lines.push(' /* Spacing: Tailwind multiplies --spacing, which matches the UND 4px base */');
|
|
34
|
+
add('--spacing', '0.25rem');
|
|
35
|
+
lines.push(' /* Radius (theme radius factor applied) */');
|
|
36
|
+
for (const p of paths)
|
|
37
|
+
if (p.startsWith('radius.') && p !== 'radius.factor')
|
|
38
|
+
add(`--radius-${p.slice(7)}`, `var(${cssName(p)})`);
|
|
39
|
+
for (const p of paths)
|
|
40
|
+
if (p.startsWith('shape.'))
|
|
41
|
+
add(`--radius-${p.slice(6)}`, `var(${cssName(p)})`);
|
|
42
|
+
lines.push(' /* Elevation */');
|
|
43
|
+
for (const p of paths)
|
|
44
|
+
if (/^shadow\.\d$/.test(p))
|
|
45
|
+
add(`--shadow-${p.slice(7)}`, `var(${cssName(p)})`);
|
|
46
|
+
lines.push(' /* Fonts */');
|
|
47
|
+
add('--font-sans', 'var(--und-typeface-body)');
|
|
48
|
+
add('--font-heading', 'var(--und-typeface-heading)');
|
|
49
|
+
add('--font-display', 'var(--und-typeface-display)');
|
|
50
|
+
add('--font-mono', 'var(--und-typeface-code)');
|
|
51
|
+
for (const p of paths)
|
|
52
|
+
if (p.startsWith('font-weight.'))
|
|
53
|
+
add(`--font-weight-und-${p.slice(12)}`, `var(${cssName(p)})`);
|
|
54
|
+
lines.push(' /* Type scale (fluid; Indic line heights switch automatically via :lang()) */');
|
|
55
|
+
for (const p of paths) {
|
|
56
|
+
if (ctx.tokens.get(p).type !== 'typography')
|
|
57
|
+
continue;
|
|
58
|
+
const n = p.slice(5);
|
|
59
|
+
const v = cssName(p);
|
|
60
|
+
add(`--text-${n}`, `var(${v}-size)`);
|
|
61
|
+
add(`--text-${n}--line-height`, `var(${v}-lh)`);
|
|
62
|
+
add(`--text-${n}--letter-spacing`, `var(${v}-tracking)`);
|
|
63
|
+
add(`--text-${n}--font-weight`, `var(${v}-weight)`);
|
|
64
|
+
}
|
|
65
|
+
lines.push(' /* Motion */');
|
|
66
|
+
for (const e of ['enter', 'exit', 'move', 'emphasized'])
|
|
67
|
+
add(`--ease-${e}`, `var(--und-motion-ease-${e})`);
|
|
68
|
+
for (const p of paths)
|
|
69
|
+
if (/^spring\.[a-z]+$/.test(p))
|
|
70
|
+
add(`--ease-spring-${p.slice(7)}`, `var(${cssName(p)})`);
|
|
71
|
+
add('--default-transition-duration', 'var(--und-motion-hover)');
|
|
72
|
+
add('--default-transition-timing-function', 'var(--und-motion-ease-move)');
|
|
73
|
+
const bp = [];
|
|
74
|
+
for (const p of paths) {
|
|
75
|
+
if (!p.startsWith('breakpoint.'))
|
|
76
|
+
continue;
|
|
77
|
+
const m = materialize(ctx, p);
|
|
78
|
+
if (m.kind === 'dimension')
|
|
79
|
+
bp.push(` --breakpoint-${p.slice(11)}: ${m.css};`);
|
|
80
|
+
}
|
|
81
|
+
const variants = [
|
|
82
|
+
'@custom-variant und-dark (&:where([data-und-mode="dark"], [data-und-mode="dark"] *, [data-und-theme="raat"], [data-und-theme="raat"] *));',
|
|
83
|
+
'@custom-variant und-more (&:where([data-und-contrast="more"], [data-und-contrast="more"] *));',
|
|
84
|
+
'@custom-variant und-compact (&:where([data-und-density="compact"], [data-und-density="compact"] *));',
|
|
85
|
+
...themes.map((t) => `@custom-variant theme-${t} (&:where([data-und-theme="${t}"], [data-und-theme="${t}"] *));`),
|
|
86
|
+
];
|
|
87
|
+
return `/* Generated by @und-ui/tokens ${version}. Do not edit.
|
|
88
|
+
* Tailwind CSS v4 preset.
|
|
89
|
+
* @import "tailwindcss";
|
|
90
|
+
* @import "@und-ui/tokens/css";
|
|
91
|
+
* @import "@und-ui/tokens/tailwind";
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
${variants.join('\n')}
|
|
95
|
+
|
|
96
|
+
@theme inline {
|
|
97
|
+
${lines.join('\n')}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/* Breakpoints must be literal (media queries cannot read custom properties). */
|
|
101
|
+
@theme {
|
|
102
|
+
${bp.join('\n')}
|
|
103
|
+
}
|
|
104
|
+
`;
|
|
105
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CssBlock } from './formats/css.js';
|
|
2
|
+
export interface BuildResult {
|
|
3
|
+
files: Record<string, string>;
|
|
4
|
+
blocks: CssBlock[];
|
|
5
|
+
stats: {
|
|
6
|
+
tokens: number;
|
|
7
|
+
contexts: number;
|
|
8
|
+
cssProperties: number;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export declare function packageVersion(root: string): string;
|
|
12
|
+
export declare function buildAll(root: string): Promise<BuildResult>;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build orchestrator: resolves every context through the DTCG resolver and
|
|
3
|
+
* renders all outputs from the same source. Returns a map of dist-relative
|
|
4
|
+
* paths to file contents (the build script writes them; tests snapshot them).
|
|
5
|
+
*/
|
|
6
|
+
import { readFileSync } from 'node:fs';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import { TokenFiles, resolveContext } from '../dtcg/engine.js';
|
|
9
|
+
import { THEMES } from '../themes/definitions.js';
|
|
10
|
+
import { colorContextKeys, variantName } from './contexts.js';
|
|
11
|
+
import { buildCssBlocks, filterMotion, renderBlocks } from './formats/css.js';
|
|
12
|
+
import { renderDart } from './formats/dart.js';
|
|
13
|
+
import { diffFlat, jsFlat, renderJs } from './formats/js.js';
|
|
14
|
+
import { renderKotlin } from './formats/kotlin.js';
|
|
15
|
+
import { renderReactNative } from './formats/react-native.js';
|
|
16
|
+
import { buildAndroid, buildScssAndJson } from './formats/style-dictionary.js';
|
|
17
|
+
import { renderSwift } from './formats/swift.js';
|
|
18
|
+
import { renderTailwind } from './formats/tailwind.js';
|
|
19
|
+
import { buildNativeModel } from './native-model.js';
|
|
20
|
+
export function packageVersion(root) {
|
|
21
|
+
return JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'))
|
|
22
|
+
.version;
|
|
23
|
+
}
|
|
24
|
+
function header(version, what) {
|
|
25
|
+
return `/* Generated by @und-ui/tokens ${version}. Do not edit.
|
|
26
|
+
* ${what}
|
|
27
|
+
* Source: DTCG 2025.10 tokens resolved through tokens/und.resolver.json.
|
|
28
|
+
*/`;
|
|
29
|
+
}
|
|
30
|
+
export async function buildAll(root) {
|
|
31
|
+
const version = packageVersion(root);
|
|
32
|
+
const files = new TokenFiles(join(root, 'tokens'));
|
|
33
|
+
const resolver = files.resolver();
|
|
34
|
+
const defaultCtx = resolveContext(files);
|
|
35
|
+
const typeOf = (p) => defaultCtx.tokens.get(p)?.type;
|
|
36
|
+
const out = {};
|
|
37
|
+
// ---------------------------------------------------------------- CSS
|
|
38
|
+
const blocks = buildCssBlocks(files, resolver, typeOf);
|
|
39
|
+
const cssHeader = (what) => header(version, what);
|
|
40
|
+
out['css/tokens.css'] = renderBlocks(blocks, cssHeader('All themes, modes, contrast, density, transparency and motion contexts. Attributes on <html> (or any scope element): data-und-theme, data-und-mode, data-und-contrast, data-und-density, data-und-transparency, data-und-motion.'));
|
|
41
|
+
const nonDefaultTheme = (b) => b.group === 'theme' && !b.id.startsWith('theme:ujala');
|
|
42
|
+
out['css/base.css'] = renderBlocks(blocks.filter((b) => !nonDefaultTheme(b)), cssHeader('Everything except the non-default themes. Add css/themes/<name>.css for the themes you use.'));
|
|
43
|
+
for (const t of THEMES) {
|
|
44
|
+
out[`css/themes/${t.name}.css`] = renderBlocks(blocks.filter((b) => b.group === 'theme' && b.id.split(':')[1] === t.name), cssHeader(`${t.label} theme. Load after css/base.css; activate with data-und-theme="${t.name}".`));
|
|
45
|
+
}
|
|
46
|
+
out['css/motion.css'] = renderBlocks(filterMotion(blocks), cssHeader('Motion only: durations x tempo (--und-motion-tempo), easings, spring linear() curves with cubic-bezier fallback, and reduced-motion rules. Included in tokens.css.'));
|
|
47
|
+
const cssProperties = new Set();
|
|
48
|
+
for (const b of blocks)
|
|
49
|
+
for (const k of b.decls.keys())
|
|
50
|
+
cssProperties.add(k);
|
|
51
|
+
// ---------------------------------------------------------------- contexts for JS / SD
|
|
52
|
+
const ctxByKey = new Map();
|
|
53
|
+
for (const k of colorContextKeys())
|
|
54
|
+
ctxByKey.set(`${k.theme}/${variantName(k)}`, resolveContext(files, k));
|
|
55
|
+
// JS
|
|
56
|
+
const defaultFlat = jsFlat(defaultCtx);
|
|
57
|
+
const contexts = {};
|
|
58
|
+
const modifiers = {};
|
|
59
|
+
for (const k of colorContextKeys()) {
|
|
60
|
+
const v = variantName(k);
|
|
61
|
+
const ctx = ctxByKey.get(`${k.theme}/${v}`);
|
|
62
|
+
const flat = jsFlat(ctx);
|
|
63
|
+
(contexts[k.theme] ??= {})[v] = diffFlat(defaultFlat, flat);
|
|
64
|
+
const mods = {};
|
|
65
|
+
for (const [modName, mod] of Object.entries(resolver.modifiers)) {
|
|
66
|
+
if (['mode', 'theme', 'contrast'].includes(modName))
|
|
67
|
+
continue;
|
|
68
|
+
for (const ctxName of Object.keys(mod.contexts)) {
|
|
69
|
+
if (ctxName === mod.default)
|
|
70
|
+
continue;
|
|
71
|
+
const withMod = resolveContext(files, { ...k, [modName]: ctxName });
|
|
72
|
+
(mods[modName] ??= {})[ctxName] = diffFlat(flat, jsFlat(withMod));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
(modifiers[k.theme] ??= {})[v] = mods;
|
|
76
|
+
}
|
|
77
|
+
const themesMeta = THEMES.map((t) => ({
|
|
78
|
+
modes: [...t.modes],
|
|
79
|
+
name: t.name,
|
|
80
|
+
label: t.label,
|
|
81
|
+
personality: t.personality,
|
|
82
|
+
radiusFactor: t.radiusFactor,
|
|
83
|
+
tempo: t.tempo,
|
|
84
|
+
character: t.character,
|
|
85
|
+
density: t.density,
|
|
86
|
+
glass: t.glass,
|
|
87
|
+
}));
|
|
88
|
+
for (const [f, content] of Object.entries(renderJs({
|
|
89
|
+
version,
|
|
90
|
+
defaultCtx,
|
|
91
|
+
contexts: contexts,
|
|
92
|
+
modifiers: modifiers,
|
|
93
|
+
themes: themesMeta,
|
|
94
|
+
}))) {
|
|
95
|
+
out[`js/${f}`] = content;
|
|
96
|
+
}
|
|
97
|
+
// Style Dictionary: SCSS + JSON per context, Android for the default theme.
|
|
98
|
+
for (const [key, ctx] of ctxByKey) {
|
|
99
|
+
const name = key.replace('/', '.');
|
|
100
|
+
const sd = await buildScssAndJson(ctx, name);
|
|
101
|
+
for (const [f, content] of Object.entries(sd))
|
|
102
|
+
out[f] = content;
|
|
103
|
+
}
|
|
104
|
+
out['scss/_variables.scss'] = out['scss/ujala.light.scss'];
|
|
105
|
+
out['scss/_vars.scss'] =
|
|
106
|
+
`// Generated by @und-ui/tokens ${version}. Do not edit.\n// Runtime-themable Sass variables: each one is the CSS custom property.\n${[
|
|
107
|
+
...cssProperties,
|
|
108
|
+
]
|
|
109
|
+
.filter((p) => p.startsWith('--und-'))
|
|
110
|
+
.sort()
|
|
111
|
+
.map((p) => `$${p.slice(2)}: var(${p});`)
|
|
112
|
+
.join('\n')}\n`;
|
|
113
|
+
Object.assign(out, await buildAndroid(ctxByKey.get('ujala/light'), ctxByKey.get('ujala/dark')));
|
|
114
|
+
// Tailwind
|
|
115
|
+
out['tailwind/und.css'] = renderTailwind(defaultCtx, THEMES.map((t) => t.name), version);
|
|
116
|
+
// Native
|
|
117
|
+
const model = buildNativeModel(files, version);
|
|
118
|
+
out['swift/UndTokens.swift'] = renderSwift(model);
|
|
119
|
+
out['kotlin/UndTokens.kt'] = renderKotlin(model);
|
|
120
|
+
out['dart/und_tokens.dart'] = renderDart(model);
|
|
121
|
+
for (const [f, content] of Object.entries(renderReactNative(model)))
|
|
122
|
+
out[`react-native/${f}`] = content;
|
|
123
|
+
// Resolved DTCG for each context (handy for docs and other tools).
|
|
124
|
+
return {
|
|
125
|
+
files: out,
|
|
126
|
+
blocks,
|
|
127
|
+
stats: {
|
|
128
|
+
tokens: defaultCtx.tokens.size,
|
|
129
|
+
contexts: ctxByKey.size,
|
|
130
|
+
cssProperties: cssProperties.size,
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|