@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.
- 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,232 @@
|
|
|
1
|
+
import { VARIANTS, camel, stepName } from '../native-model.js';
|
|
2
|
+
const f = (v) => {
|
|
3
|
+
const r = Math.round(v * 10000) / 10000;
|
|
4
|
+
return `${Number.isInteger(r) ? `${r}.0` : `${r}`}f`;
|
|
5
|
+
};
|
|
6
|
+
const dp = (v) => `${Math.round(v * 100) / 100}.dp`.replace(/^(-?\d+)\.dp$/, '$1.dp');
|
|
7
|
+
const sp = (v) => `${Math.round(v * 100) / 100}.sp`;
|
|
8
|
+
const str = (s) => JSON.stringify(s);
|
|
9
|
+
function color(c) {
|
|
10
|
+
if (c.p3)
|
|
11
|
+
return `Color(red = ${f(c.p3[0])}, green = ${f(c.p3[1])}, blue = ${f(c.p3[2])}, alpha = ${f(c.alpha)}, colorSpace = ColorSpaces.DisplayP3)`;
|
|
12
|
+
const a = Math.round(c.alpha * 255)
|
|
13
|
+
.toString(16)
|
|
14
|
+
.padStart(2, '0')
|
|
15
|
+
.toUpperCase();
|
|
16
|
+
return `Color(0x${a}${c.hex.slice(1).toUpperCase()})`;
|
|
17
|
+
}
|
|
18
|
+
function cap(s) {
|
|
19
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
20
|
+
}
|
|
21
|
+
export function renderKotlin(model) {
|
|
22
|
+
const roles = model.colorRoles.map(([name]) => name);
|
|
23
|
+
const L = [];
|
|
24
|
+
L.push(`// Generated by @und-ui/tokens ${model.version}. Do not edit.
|
|
25
|
+
// Source: DTCG 2025.10 tokens. Semantic roles only (no hue names).
|
|
26
|
+
@file:Suppress("MagicNumber", "LongParameterList", "unused")
|
|
27
|
+
|
|
28
|
+
package dev.undui.tokens
|
|
29
|
+
|
|
30
|
+
import androidx.compose.animation.core.CubicBezierEasing
|
|
31
|
+
import androidx.compose.animation.core.Easing
|
|
32
|
+
import androidx.compose.runtime.Immutable
|
|
33
|
+
import androidx.compose.ui.graphics.Color
|
|
34
|
+
import androidx.compose.ui.graphics.colorspace.ColorSpaces
|
|
35
|
+
import androidx.compose.ui.text.TextStyle
|
|
36
|
+
import androidx.compose.ui.text.font.FontWeight
|
|
37
|
+
import androidx.compose.ui.unit.Dp
|
|
38
|
+
import androidx.compose.ui.unit.dp
|
|
39
|
+
import androidx.compose.ui.unit.em
|
|
40
|
+
import androidx.compose.ui.unit.sp
|
|
41
|
+
|
|
42
|
+
object UndTokens {
|
|
43
|
+
const val VERSION: String = ${str(model.version)}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
enum class UndThemeName { ${model.themes.map((t) => cap(t.def.name)).join(', ')} }
|
|
47
|
+
|
|
48
|
+
enum class UndCharacter { Crisp, Standard, Expressive }
|
|
49
|
+
|
|
50
|
+
enum class UndDensity { Comfortable, Compact, Touch }
|
|
51
|
+
|
|
52
|
+
/** Semantic colour roles for one theme and appearance. */
|
|
53
|
+
@Immutable
|
|
54
|
+
data class UndColors(
|
|
55
|
+
${roles.map((r) => ` val ${r}: Color,`).join('\n')}
|
|
56
|
+
) {
|
|
57
|
+
companion object {
|
|
58
|
+
${model.themes
|
|
59
|
+
.flatMap((t) => VARIANTS.map((v) => ` val ${t.def.name}${cap(v)}: UndColors = UndColors(
|
|
60
|
+
${roles.map((r) => ` ${r} = ${color(t.colors[v].get(r))},`).join('\n')}
|
|
61
|
+
)`))
|
|
62
|
+
.join('\n\n')}
|
|
63
|
+
|
|
64
|
+
/** Pick a scheme. Dark-only themes (Raat) ignore [dark]. */
|
|
65
|
+
fun of(theme: UndThemeName, dark: Boolean, highContrast: Boolean = false): UndColors = when (theme) {
|
|
66
|
+
${model.themes
|
|
67
|
+
.map((t) => {
|
|
68
|
+
const name = t.def.name;
|
|
69
|
+
return ` UndThemeName.${cap(name)} -> when {
|
|
70
|
+
dark && highContrast -> ${name}DarkMore
|
|
71
|
+
dark -> ${name}Dark
|
|
72
|
+
highContrast -> ${name}LightMore
|
|
73
|
+
else -> ${name}Light
|
|
74
|
+
}`;
|
|
75
|
+
})
|
|
76
|
+
.join('\n')}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
`);
|
|
81
|
+
const dpObject = (name, entries, doc, prefix = 's') => `/** ${doc} */\nobject ${name} {\n${[...entries].map(([k, v]) => ` val ${stepName(k, prefix)}: Dp = ${dp(v)}`).join('\n')}\n}\n`;
|
|
82
|
+
L.push(dpObject('UndSpacing', model.spacing, '4dp spacing scale (report 3.1). Density never changes these.'));
|
|
83
|
+
L.push(dpObject('UndIconSize', model.iconSize, 'Icon sizes.'));
|
|
84
|
+
L.push(dpObject('UndBorderWidth', model.borderWidth, 'Border widths. Hairline = 1 / density in pixels.'));
|
|
85
|
+
L.push(dpObject('UndBreakpoint', model.breakpoint, 'Window-width breakpoints.', 'w'));
|
|
86
|
+
L.push(`/** Z-index layers (Compose zIndex). */
|
|
87
|
+
object UndZIndex {
|
|
88
|
+
${[...model.zIndex].map(([k, v]) => ` const val ${k.toUpperCase()}: Float = ${f(v)}`).join('\n')}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Focus ring and minimum touch target (Material 48dp via minimumInteractiveComponentSize). */
|
|
92
|
+
object UndFocus {
|
|
93
|
+
val width: Dp = ${dp(model.focus.width)}
|
|
94
|
+
val widthHighContrast: Dp = ${dp(model.focus.widthMore)}
|
|
95
|
+
val offset: Dp = ${dp(model.focus.offset)}
|
|
96
|
+
val minimumTarget: Dp = ${dp(model.target.android)}
|
|
97
|
+
}
|
|
98
|
+
`);
|
|
99
|
+
const controlKeys = [...model.control.comfortable.keys()];
|
|
100
|
+
L.push(`/** Control metrics per density (report 3.8). */
|
|
101
|
+
@Immutable
|
|
102
|
+
data class UndControl(
|
|
103
|
+
${controlKeys.map((k) => ` val ${stepName(k)}: Dp,`).join('\n')}
|
|
104
|
+
) {
|
|
105
|
+
companion object {
|
|
106
|
+
${['comfortable', 'compact', 'touch']
|
|
107
|
+
.map((d) => ` val ${cap(d)}: UndControl = UndControl(${controlKeys.map((k) => `${stepName(k)} = ${dp(model.control[d].get(k))}`).join(', ')})`)
|
|
108
|
+
.join('\n')}
|
|
109
|
+
|
|
110
|
+
fun of(density: UndDensity): UndControl = when (density) {
|
|
111
|
+
UndDensity.Comfortable -> Comfortable
|
|
112
|
+
UndDensity.Compact -> Compact
|
|
113
|
+
UndDensity.Touch -> Touch
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
`);
|
|
118
|
+
const radiusKeys = [...model.themes[0].radius.keys()].filter((k) => k !== 'factor');
|
|
119
|
+
L.push(`/** Radius scale with the theme radius factor applied (report 3.3). */
|
|
120
|
+
@Immutable
|
|
121
|
+
data class UndRadii(
|
|
122
|
+
val factor: Float,
|
|
123
|
+
${radiusKeys.map((k) => ` val ${stepName(k)}: Dp,`).join('\n')}
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
/** Spring spec for androidx.compose.animation.core.spring(dampingRatio, stiffness). Mass is 1. */
|
|
127
|
+
@Immutable
|
|
128
|
+
data class UndSpringSpec(
|
|
129
|
+
val dampingRatio: Float,
|
|
130
|
+
val stiffness: Float,
|
|
131
|
+
val damping: Float,
|
|
132
|
+
val response: Float,
|
|
133
|
+
val settleMillis: Int,
|
|
134
|
+
)
|
|
135
|
+
`);
|
|
136
|
+
// Typography
|
|
137
|
+
L.push(`/** Text styles in sp (report 2.3). Use [indic] for Devanagari and other Indic locales. */
|
|
138
|
+
object UndTypography {
|
|
139
|
+
${[...model.typography]
|
|
140
|
+
.map(([k, t]) => {
|
|
141
|
+
const a = t.android ?? {
|
|
142
|
+
size: t.minSizePx,
|
|
143
|
+
lineHeight: Math.round(t.minSizePx * t.lineHeight),
|
|
144
|
+
};
|
|
145
|
+
const tracking = t.letterSpacingEm === 0 ? '0.em' : `(${t.letterSpacingEm}).em`;
|
|
146
|
+
return ` val ${camel(k)}: TextStyle = TextStyle(fontSize = ${sp(a.size)}, lineHeight = ${sp(a.lineHeight)}, fontWeight = FontWeight(${t.weight}), letterSpacing = ${tracking})`;
|
|
147
|
+
})
|
|
148
|
+
.join('\n')}
|
|
149
|
+
|
|
150
|
+
/** Indic variant: line height = size x Indic multiplier, no letter spacing (never track Indic scripts). */
|
|
151
|
+
fun indic(style: TextStyle, lineHeightMultiplier: Float = ${f(1.75)}): TextStyle =
|
|
152
|
+
style.copy(lineHeight = (style.fontSize.value * lineHeightMultiplier).sp, letterSpacing = 0.em)
|
|
153
|
+
}
|
|
154
|
+
`);
|
|
155
|
+
// Motion per theme
|
|
156
|
+
const t0 = model.themes[0];
|
|
157
|
+
const durNames = [...t0.durations.keys()];
|
|
158
|
+
const easeNames = [...t0.easings.keys()];
|
|
159
|
+
const springNames = [...t0.springs.keys()];
|
|
160
|
+
L.push(`/** Motion tokens for a theme: durations in ms (tempo applied), easings, springs (report 4). */
|
|
161
|
+
@Immutable
|
|
162
|
+
data class UndMotion(
|
|
163
|
+
val tempo: Float,
|
|
164
|
+
val character: UndCharacter,
|
|
165
|
+
${durNames.map((d) => ` val ${camel(d)}: Int,`).join('\n')}
|
|
166
|
+
${easeNames.map((e) => ` val ${camel(e)}: Easing,`).join('\n')}
|
|
167
|
+
${springNames.map((s) => ` val spring${cap(s)}: UndSpringSpec,`).join('\n')}
|
|
168
|
+
) {
|
|
169
|
+
companion object {
|
|
170
|
+
${model.themes
|
|
171
|
+
.map((t) => {
|
|
172
|
+
const args = [
|
|
173
|
+
`tempo = ${f(t.tempo)}`,
|
|
174
|
+
`character = UndCharacter.${cap(t.def.character)}`,
|
|
175
|
+
...durNames.map((d) => `${camel(d)} = ${t.durations.get(d)}`),
|
|
176
|
+
...easeNames.map((e) => {
|
|
177
|
+
const b = t.easings.get(e).bezier;
|
|
178
|
+
return `${camel(e)} = CubicBezierEasing(${b.map(f).join(', ')})`;
|
|
179
|
+
}),
|
|
180
|
+
...springNames.map((s) => {
|
|
181
|
+
const sp2 = t.springs.get(s);
|
|
182
|
+
return `spring${cap(s)} = UndSpringSpec(dampingRatio = ${f(sp2.dampingRatio)}, stiffness = ${f(sp2.stiffness)}, damping = ${f(sp2.damping)}, response = ${f(sp2.response)}, settleMillis = ${sp2.settleMs})`;
|
|
183
|
+
}),
|
|
184
|
+
];
|
|
185
|
+
return ` val ${cap(t.def.name)}: UndMotion = UndMotion(\n ${args.join(',\n ')},\n )`;
|
|
186
|
+
})
|
|
187
|
+
.join('\n\n')}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** Reduced-motion durations in ms (never scaled by tempo; read ANIMATOR_DURATION_SCALE == 0). */
|
|
192
|
+
object UndReducedMotion {
|
|
193
|
+
${[...model.reducedDurations]
|
|
194
|
+
.map(([k, v]) => ` const val ${camel(k)
|
|
195
|
+
.replace(/([A-Z])/g, '_$1')
|
|
196
|
+
.toUpperCase()}: Int = ${v}`)
|
|
197
|
+
.join('\n')}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** A complete UND theme; provide it with a CompositionLocal. */
|
|
201
|
+
@Immutable
|
|
202
|
+
data class UndThemeSpec(
|
|
203
|
+
val name: UndThemeName,
|
|
204
|
+
val darkOnly: Boolean,
|
|
205
|
+
val radii: UndRadii,
|
|
206
|
+
val motion: UndMotion,
|
|
207
|
+
val density: UndDensity,
|
|
208
|
+
val fontFamilies: Map<String, List<String>>,
|
|
209
|
+
) {
|
|
210
|
+
fun colors(dark: Boolean, highContrast: Boolean = false): UndColors =
|
|
211
|
+
UndColors.of(name, dark || darkOnly, highContrast)
|
|
212
|
+
|
|
213
|
+
companion object {
|
|
214
|
+
${model.themes
|
|
215
|
+
.map((t) => ` val ${cap(t.def.name)}: UndThemeSpec = UndThemeSpec(
|
|
216
|
+
name = UndThemeName.${cap(t.def.name)},
|
|
217
|
+
darkOnly = ${t.def.modes.length === 1},
|
|
218
|
+
radii = UndRadii(factor = ${f(t.def.radiusFactor)}, ${radiusKeys.map((k) => `${stepName(k)} = ${dp(t.radius.get(k))}`).join(', ')}),
|
|
219
|
+
motion = UndMotion.${cap(t.def.name)},
|
|
220
|
+
density = UndDensity.${cap(t.def.density)},
|
|
221
|
+
fontFamilies = mapOf(${['body', 'heading', 'display', 'code'].map((r) => `${str(r)} to listOf(${t.typeface[r].map(str).join(', ')})`).join(', ')}),
|
|
222
|
+
)`)
|
|
223
|
+
.join('\n')}
|
|
224
|
+
|
|
225
|
+
fun of(name: UndThemeName): UndThemeSpec = when (name) {
|
|
226
|
+
${model.themes.map((t) => ` UndThemeName.${cap(t.def.name)} -> ${cap(t.def.name)}`).join('\n')}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
`);
|
|
231
|
+
return L.join('\n');
|
|
232
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Native output: plain numbers (no units) and sRGB hex colours.
|
|
3
|
+
* tokens.js pure data + createTheme(os) (no react-native import; testable in Node)
|
|
4
|
+
* index.js Platform-aware entry: resolves shadows, hit targets, hairlines and
|
|
5
|
+
* monospace families with Platform.select / StyleSheet.hairlineWidth.
|
|
6
|
+
*/
|
|
7
|
+
import { hex8 } from '../css-values.js';
|
|
8
|
+
import { VARIANTS, camel, stepName } from '../native-model.js';
|
|
9
|
+
const HEADER = '// Generated by @und-ui/tokens. Do not edit.\n';
|
|
10
|
+
const c = (m) => (m.alpha < 1 ? hex8(m.hex, m.alpha) : m.hex);
|
|
11
|
+
function shadowSpec(s) {
|
|
12
|
+
const outer = s.layers.filter((l) => !l.inset);
|
|
13
|
+
const big = outer.at(-1);
|
|
14
|
+
const boxShadow = s.layers
|
|
15
|
+
.map((l) => `${l.inset ? 'inset ' : ''}${l.x}px ${l.y}px ${l.blur}px ${l.spread}px ${c(l.color)}`)
|
|
16
|
+
.join(', ');
|
|
17
|
+
return {
|
|
18
|
+
boxShadow: boxShadow || 'none',
|
|
19
|
+
ios: big
|
|
20
|
+
? {
|
|
21
|
+
shadowColor: big.color.hex,
|
|
22
|
+
shadowOpacity: big.color.alpha,
|
|
23
|
+
shadowRadius: big.blur / 2,
|
|
24
|
+
shadowOffset: { width: big.x, height: big.y },
|
|
25
|
+
}
|
|
26
|
+
: null,
|
|
27
|
+
elevation: big ? Math.min(24, Math.round(big.blur / 3)) : 0,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export function renderReactNative(model) {
|
|
31
|
+
const themes = {};
|
|
32
|
+
for (const t of model.themes) {
|
|
33
|
+
const colors = {};
|
|
34
|
+
for (const v of VARIANTS)
|
|
35
|
+
colors[v] = Object.fromEntries([...t.colors[v]].map(([k, m]) => [k, c(m)]));
|
|
36
|
+
themes[t.def.name] = {
|
|
37
|
+
name: t.def.name,
|
|
38
|
+
label: t.def.label,
|
|
39
|
+
darkOnly: t.def.modes.length === 1,
|
|
40
|
+
colors,
|
|
41
|
+
radius: Object.fromEntries([...t.radius].filter(([k]) => k !== 'factor').map(([k, v]) => [stepName(k), v])),
|
|
42
|
+
radiusFactor: t.def.radiusFactor,
|
|
43
|
+
motion: {
|
|
44
|
+
tempo: t.tempo,
|
|
45
|
+
character: t.def.character,
|
|
46
|
+
duration: Object.fromEntries([...t.durations].map(([k, v]) => [camel(k.replace(/^motion\./, '')), v])),
|
|
47
|
+
easing: Object.fromEntries([...t.easings].map(([k, v]) => [
|
|
48
|
+
camel(k.replace(/^motion\./, '')),
|
|
49
|
+
v.spring ? { bezier: v.bezier, spring: v.spring } : { bezier: v.bezier },
|
|
50
|
+
])),
|
|
51
|
+
spring: Object.fromEntries([...t.springs].map(([k, s]) => [
|
|
52
|
+
k,
|
|
53
|
+
{
|
|
54
|
+
stiffness: s.stiffness,
|
|
55
|
+
damping: s.damping,
|
|
56
|
+
mass: 1,
|
|
57
|
+
dampingRatio: s.dampingRatio,
|
|
58
|
+
response: s.response,
|
|
59
|
+
settleMs: s.settleMs,
|
|
60
|
+
},
|
|
61
|
+
])),
|
|
62
|
+
},
|
|
63
|
+
density: t.def.density,
|
|
64
|
+
fontFamilies: t.typeface,
|
|
65
|
+
shadows: {
|
|
66
|
+
light: Object.fromEntries([...t.shadows.light].map(([k, s]) => [k, shadowSpec(s)])),
|
|
67
|
+
dark: Object.fromEntries([...t.shadows.dark].map(([k, s]) => [k, shadowSpec(s)])),
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const data = {
|
|
72
|
+
version: model.version,
|
|
73
|
+
spacing: Object.fromEntries([...model.spacing].map(([k, v]) => [stepName(k), v])),
|
|
74
|
+
iconSize: Object.fromEntries(model.iconSize),
|
|
75
|
+
borderWidth: Object.fromEntries(model.borderWidth),
|
|
76
|
+
control: Object.fromEntries(Object.entries(model.control).map(([k, m]) => [
|
|
77
|
+
k,
|
|
78
|
+
Object.fromEntries([...m].map(([kk, v]) => [stepName(kk), v])),
|
|
79
|
+
])),
|
|
80
|
+
focus: model.focus,
|
|
81
|
+
target: model.target,
|
|
82
|
+
zIndex: Object.fromEntries(model.zIndex),
|
|
83
|
+
reducedMotion: Object.fromEntries([...model.reducedDurations].map(([k, v]) => [camel(k.replace(/^motion\./, '')), v])),
|
|
84
|
+
typography: Object.fromEntries([...model.typography].map(([k, t]) => {
|
|
85
|
+
const size = t.sizeEm !== undefined ? Math.round(t.sizeEm * 16 * 100) / 100 : t.minSizePx;
|
|
86
|
+
return [
|
|
87
|
+
camel(k),
|
|
88
|
+
{
|
|
89
|
+
fontSize: size,
|
|
90
|
+
lineHeight: Math.round(size * t.lineHeight),
|
|
91
|
+
lineHeightIndic: Math.round(size * t.lineHeightIndic),
|
|
92
|
+
fontWeight: String(t.weight),
|
|
93
|
+
letterSpacing: Math.round(t.letterSpacingEm * size * 100) / 100,
|
|
94
|
+
},
|
|
95
|
+
];
|
|
96
|
+
})),
|
|
97
|
+
themes,
|
|
98
|
+
};
|
|
99
|
+
const tokensJs = `${HEADER}export const data = ${JSON.stringify(data, null, 2)};
|
|
100
|
+
|
|
101
|
+
/** Monospace family per OS (Platform-aware value). */
|
|
102
|
+
const MONO = { ios: 'Menlo', android: 'monospace', web: 'ui-monospace, monospace', default: 'monospace' };
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Builds the theme object for one OS. Exported for tests and for non-RN hosts.
|
|
106
|
+
* @param {'ios' | 'android' | 'web' | string} os
|
|
107
|
+
* @param {{ theme?: string, scheme?: 'light' | 'dark', highContrast?: boolean, hairlineWidth?: number }} [options]
|
|
108
|
+
*/
|
|
109
|
+
export function createTheme(os, options = {}) {
|
|
110
|
+
const t = data.themes[options.theme ?? 'ujala'];
|
|
111
|
+
if (!t) throw new Error('Unknown UND theme: ' + options.theme);
|
|
112
|
+
const dark = t.darkOnly || options.scheme === 'dark';
|
|
113
|
+
const variant = (dark ? 'dark' : 'light') + (options.highContrast ? 'More' : '');
|
|
114
|
+
const shadows = {};
|
|
115
|
+
for (const [level, s] of Object.entries(t.shadows[dark ? 'dark' : 'light'])) {
|
|
116
|
+
if (os === 'ios') shadows[level] = s.ios ?? {};
|
|
117
|
+
else if (os === 'android') shadows[level] = { elevation: s.elevation };
|
|
118
|
+
else shadows[level] = { boxShadow: s.boxShadow };
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
name: t.name,
|
|
122
|
+
dark,
|
|
123
|
+
color: t.colors[variant],
|
|
124
|
+
spacing: data.spacing,
|
|
125
|
+
radius: t.radius,
|
|
126
|
+
typography: data.typography,
|
|
127
|
+
motion: t.motion,
|
|
128
|
+
reducedMotion: data.reducedMotion,
|
|
129
|
+
control: data.control[t.density],
|
|
130
|
+
shadows,
|
|
131
|
+
fontFamily: { ...t.fontFamilies, mono: MONO[os] ?? MONO.default },
|
|
132
|
+
hairlineWidth: options.hairlineWidth ?? 1,
|
|
133
|
+
/** Minimum hit area: 44 on iOS (HIG), 48 on Android (Material). */
|
|
134
|
+
minTarget: os === 'android' ? data.target.android : data.target.touch,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
`;
|
|
138
|
+
const indexJs = `${HEADER}import { Platform, StyleSheet } from 'react-native';
|
|
139
|
+
import { createTheme, data } from './tokens.js';
|
|
140
|
+
|
|
141
|
+
export { data, createTheme };
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Platform-aware theme: shadows (iOS shadow* props, Android elevation, web boxShadow),
|
|
145
|
+
* hit targets and hairlines resolved for the running OS.
|
|
146
|
+
*/
|
|
147
|
+
export function getTheme(options = {}) {
|
|
148
|
+
return createTheme(Platform.OS, { hairlineWidth: StyleSheet.hairlineWidth, ...options });
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export const themeNames = Object.keys(data.themes);
|
|
152
|
+
`;
|
|
153
|
+
const roleType = model.colorRoles.map(([name]) => ` readonly ${name}: string;`).join('\n');
|
|
154
|
+
const dts = `${HEADER}export type UndThemeName = ${model.themes.map((t) => JSON.stringify(t.def.name)).join(' | ')};
|
|
155
|
+
|
|
156
|
+
export interface UndColorRoles {
|
|
157
|
+
${roleType}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export interface UndTextStyle {
|
|
161
|
+
readonly fontSize: number;
|
|
162
|
+
readonly lineHeight: number;
|
|
163
|
+
readonly lineHeightIndic: number;
|
|
164
|
+
readonly fontWeight: string;
|
|
165
|
+
readonly letterSpacing: number;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export interface UndRNTheme {
|
|
169
|
+
readonly name: UndThemeName;
|
|
170
|
+
readonly dark: boolean;
|
|
171
|
+
readonly color: UndColorRoles;
|
|
172
|
+
readonly spacing: Readonly<Record<string, number>>;
|
|
173
|
+
readonly radius: Readonly<Record<string, number>>;
|
|
174
|
+
readonly typography: Readonly<Record<string, UndTextStyle>>;
|
|
175
|
+
readonly motion: {
|
|
176
|
+
readonly tempo: number;
|
|
177
|
+
readonly character: 'crisp' | 'standard' | 'expressive';
|
|
178
|
+
readonly duration: Readonly<Record<string, number>>;
|
|
179
|
+
readonly easing: Readonly<Record<string, { readonly bezier: readonly number[]; readonly spring?: string }>>;
|
|
180
|
+
readonly spring: Readonly<Record<string, { readonly stiffness: number; readonly damping: number; readonly mass: number; readonly dampingRatio: number; readonly response: number; readonly settleMs: number }>>;
|
|
181
|
+
};
|
|
182
|
+
readonly reducedMotion: Readonly<Record<string, number>>;
|
|
183
|
+
readonly control: Readonly<Record<string, number>>;
|
|
184
|
+
readonly shadows: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
185
|
+
readonly fontFamily: Readonly<Record<'body' | 'heading' | 'display' | 'code', readonly string[]>> & { readonly mono: string };
|
|
186
|
+
readonly hairlineWidth: number;
|
|
187
|
+
readonly minTarget: number;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export interface UndRNThemeOptions {
|
|
191
|
+
theme?: UndThemeName;
|
|
192
|
+
scheme?: 'light' | 'dark';
|
|
193
|
+
highContrast?: boolean;
|
|
194
|
+
hairlineWidth?: number;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export declare const data: Readonly<Record<string, unknown>>;
|
|
198
|
+
export declare function createTheme(os: string, options?: UndRNThemeOptions): UndRNTheme;
|
|
199
|
+
export declare function getTheme(options?: Omit<UndRNThemeOptions, 'hairlineWidth'>): UndRNTheme;
|
|
200
|
+
export declare const themeNames: readonly UndThemeName[];
|
|
201
|
+
`;
|
|
202
|
+
return {
|
|
203
|
+
'tokens.js': tokensJs,
|
|
204
|
+
'tokens.d.ts': `${HEADER}export { data, createTheme } from './index.js';\n`,
|
|
205
|
+
'index.js': indexJs,
|
|
206
|
+
'index.d.ts': dts,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Context } from '../../dtcg/engine.js';
|
|
2
|
+
type Obj = Record<string, unknown>;
|
|
3
|
+
/** Resolved DTCG tree for a context (no references, themed knobs applied). */
|
|
4
|
+
export declare function resolvedTree(ctx: Context): Obj;
|
|
5
|
+
export type SdOutput = Record<string, string>;
|
|
6
|
+
export declare function buildScssAndJson(ctx: Context, name: string): Promise<SdOutput>;
|
|
7
|
+
export declare function buildAndroid(light: Context, dark: Context): Promise<SdOutput>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Style Dictionary v5 builds for the formats it covers well: SCSS variables,
|
|
3
|
+
* JSON (flat + nested) and Android resources. Each context is fed as a
|
|
4
|
+
* resolved DTCG 2025.10 tree (references already resolved by our engine, with
|
|
5
|
+
* the theme radius factor and tempo applied) so SD's output matches CSS/JS.
|
|
6
|
+
*/
|
|
7
|
+
import StyleDictionary from 'style-dictionary';
|
|
8
|
+
import { EXT, isBridge, undExt } from '../../dtcg/types.js';
|
|
9
|
+
import { contextKnobs, literalToken } from '../materialize.js';
|
|
10
|
+
/** Resolved DTCG tree for a context (no references, themed knobs applied). */
|
|
11
|
+
export function resolvedTree(ctx) {
|
|
12
|
+
const { radiusFactor, tempo } = contextKnobs(ctx);
|
|
13
|
+
const tree = {};
|
|
14
|
+
for (const path of [...ctx.tokens.keys()].sort()) {
|
|
15
|
+
const t = ctx.tokens.get(path);
|
|
16
|
+
if (isBridge(t))
|
|
17
|
+
continue; // v0 component names are CSS/JS only
|
|
18
|
+
const ext = undExt(literalToken(ctx, path));
|
|
19
|
+
let value = t.resolved;
|
|
20
|
+
if (t.type === 'dimension' && ext.radiusScale) {
|
|
21
|
+
const d = value;
|
|
22
|
+
value = { value: Math.round(d.value * radiusFactor * 100) / 100, unit: d.unit };
|
|
23
|
+
}
|
|
24
|
+
if (t.type === 'duration' && ext.tempo !== false) {
|
|
25
|
+
const d = value;
|
|
26
|
+
value = { value: Math.round(d.value * tempo), unit: d.unit };
|
|
27
|
+
}
|
|
28
|
+
if (t.type === 'transition' && ext.kind === 'spring') {
|
|
29
|
+
const v = value;
|
|
30
|
+
value = { ...v, duration: { ...v.duration, value: Math.round(v.duration.value * tempo) } };
|
|
31
|
+
}
|
|
32
|
+
const node = { $type: t.type, $value: value };
|
|
33
|
+
if (t.description)
|
|
34
|
+
node.$description = t.description;
|
|
35
|
+
const own = undExt(t);
|
|
36
|
+
if (Object.keys(own).length)
|
|
37
|
+
node.$extensions = { [EXT]: own };
|
|
38
|
+
const parts = path.split('.');
|
|
39
|
+
let cur = tree;
|
|
40
|
+
for (const p of parts.slice(0, -1))
|
|
41
|
+
cur = (cur[p] ??= {});
|
|
42
|
+
cur[parts.at(-1)] = node;
|
|
43
|
+
}
|
|
44
|
+
return tree;
|
|
45
|
+
}
|
|
46
|
+
let registered = false;
|
|
47
|
+
function register() {
|
|
48
|
+
if (registered)
|
|
49
|
+
return;
|
|
50
|
+
registered = true;
|
|
51
|
+
StyleDictionary.registerTransform({
|
|
52
|
+
name: 'und/size/px-to-dp',
|
|
53
|
+
type: 'value',
|
|
54
|
+
filter: (token) => (token.$type ?? token.type) === 'dimension',
|
|
55
|
+
transform: (token) => {
|
|
56
|
+
const v = (token.$value ?? token.value);
|
|
57
|
+
if (typeof v === 'string')
|
|
58
|
+
return v;
|
|
59
|
+
const px = v.unit === 'rem' ? v.value * 16 : v.value;
|
|
60
|
+
return `${Math.round(px * 100) / 100}dp`;
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
StyleDictionary.registerTransformGroup({
|
|
64
|
+
name: 'und/android',
|
|
65
|
+
transforms: ['attribute/cti', 'name/snake', 'color/hex8android', 'und/size/px-to-dp'],
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
async function run(tokens, platforms) {
|
|
69
|
+
register();
|
|
70
|
+
const sd = new StyleDictionary({
|
|
71
|
+
tokens: tokens,
|
|
72
|
+
platforms: platforms,
|
|
73
|
+
log: { verbosity: 'silent', warnings: 'disabled' },
|
|
74
|
+
});
|
|
75
|
+
const out = {};
|
|
76
|
+
for (const platform of Object.keys(platforms)) {
|
|
77
|
+
const results = (await sd.formatPlatform(platform));
|
|
78
|
+
for (const r of results)
|
|
79
|
+
if (r.destination)
|
|
80
|
+
out[r.destination] = String(r.output);
|
|
81
|
+
}
|
|
82
|
+
return out;
|
|
83
|
+
}
|
|
84
|
+
const HEADER_NOTE = 'Generated by @und-ui/tokens via Style Dictionary v5. Do not edit.';
|
|
85
|
+
export async function buildScssAndJson(ctx, name) {
|
|
86
|
+
const tokens = resolvedTree(ctx);
|
|
87
|
+
return run(tokens, {
|
|
88
|
+
scss: {
|
|
89
|
+
transformGroup: 'scss',
|
|
90
|
+
prefix: 'und',
|
|
91
|
+
files: [
|
|
92
|
+
{
|
|
93
|
+
destination: `scss/${name}.scss`,
|
|
94
|
+
format: 'scss/variables',
|
|
95
|
+
options: { fileHeader: () => [HEADER_NOTE] },
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
json: {
|
|
100
|
+
transformGroup: 'css',
|
|
101
|
+
files: [
|
|
102
|
+
{ destination: `json/flat/${name}.json`, format: 'json/flat' },
|
|
103
|
+
{ destination: `json/nested/${name}.json`, format: 'json/nested' },
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
export async function buildAndroid(light, dark) {
|
|
109
|
+
const colorFilter = (t) => (t.$type ?? t.type) === 'color' && !['color', 'scale'].includes(t.path[0]);
|
|
110
|
+
const dimenFilter = (t) => (t.$type ?? t.type) === 'dimension' &&
|
|
111
|
+
[
|
|
112
|
+
'space',
|
|
113
|
+
'radius',
|
|
114
|
+
'size',
|
|
115
|
+
'border-width',
|
|
116
|
+
'control',
|
|
117
|
+
'shape',
|
|
118
|
+
'focus',
|
|
119
|
+
'gap',
|
|
120
|
+
'inset',
|
|
121
|
+
].includes(t.path[0]);
|
|
122
|
+
const header = {
|
|
123
|
+
fileHeader: () => [
|
|
124
|
+
HEADER_NOTE,
|
|
125
|
+
'Default theme (Ujala). Use the Compose output for other themes.',
|
|
126
|
+
],
|
|
127
|
+
};
|
|
128
|
+
const lightOut = await run(resolvedTree(light), {
|
|
129
|
+
android: {
|
|
130
|
+
transformGroup: 'und/android',
|
|
131
|
+
prefix: 'und',
|
|
132
|
+
files: [
|
|
133
|
+
{
|
|
134
|
+
destination: 'android/values/und_colors.xml',
|
|
135
|
+
format: 'android/resources',
|
|
136
|
+
filter: colorFilter,
|
|
137
|
+
options: { ...header, resourceType: 'color' },
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
destination: 'android/values/und_dimens.xml',
|
|
141
|
+
format: 'android/resources',
|
|
142
|
+
filter: dimenFilter,
|
|
143
|
+
options: { ...header, resourceType: 'dimen' },
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
const darkOut = await run(resolvedTree(dark), {
|
|
149
|
+
android: {
|
|
150
|
+
transformGroup: 'und/android',
|
|
151
|
+
prefix: 'und',
|
|
152
|
+
files: [
|
|
153
|
+
{
|
|
154
|
+
destination: 'android/values-night/und_colors.xml',
|
|
155
|
+
format: 'android/resources',
|
|
156
|
+
filter: colorFilter,
|
|
157
|
+
options: { ...header, resourceType: 'color' },
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
return { ...lightOut, ...darkOut };
|
|
163
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SwiftUI output: UndTokens.swift.
|
|
3
|
+
* Foundation-only value types (compile on Linux) plus `#if canImport(SwiftUI)`
|
|
4
|
+
* extensions that produce dynamic Colors (light/dark x Increase Contrast),
|
|
5
|
+
* Fonts (Dynamic Type relative) and spring Animations.
|
|
6
|
+
*/
|
|
7
|
+
import type { NativeModel } from '../native-model.js';
|
|
8
|
+
export declare function renderSwift(model: NativeModel): string;
|