@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,13 @@
|
|
|
1
|
+
import type { Context, TokenFiles } from '../dtcg/engine.js';
|
|
2
|
+
import type { ThemeName } from '../themes/definitions.js';
|
|
3
|
+
export type ModeName = 'light' | 'dark';
|
|
4
|
+
export type ContrastName = 'standard' | 'more';
|
|
5
|
+
export interface ColorContextKey {
|
|
6
|
+
theme: ThemeName;
|
|
7
|
+
mode: ModeName;
|
|
8
|
+
contrast: ContrastName;
|
|
9
|
+
}
|
|
10
|
+
export declare function colorContextKeys(): ColorContextKey[];
|
|
11
|
+
/** `light`, `dark`, `lightMore`, `darkMore`. */
|
|
12
|
+
export declare function variantName(key: Pick<ColorContextKey, 'mode' | 'contrast'>): string;
|
|
13
|
+
export declare function resolveColorContexts(files: TokenFiles): Context[];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Enumerates the colour contexts (theme x mode x contrast) every output is built for. */
|
|
2
|
+
import { resolveContext } from '../dtcg/engine.js';
|
|
3
|
+
import { THEMES } from '../themes/definitions.js';
|
|
4
|
+
export function colorContextKeys() {
|
|
5
|
+
const keys = [];
|
|
6
|
+
for (const t of THEMES) {
|
|
7
|
+
for (const mode of t.modes) {
|
|
8
|
+
for (const contrast of ['standard', 'more'])
|
|
9
|
+
keys.push({ theme: t.name, mode, contrast });
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return keys;
|
|
13
|
+
}
|
|
14
|
+
/** `light`, `dark`, `lightMore`, `darkMore`. */
|
|
15
|
+
export function variantName(key) {
|
|
16
|
+
return key.contrast === 'more' ? `${key.mode}More` : key.mode;
|
|
17
|
+
}
|
|
18
|
+
export function resolveColorContexts(files) {
|
|
19
|
+
return colorContextKeys().map((k) => resolveContext(files, k));
|
|
20
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { FlatToken } from '../dtcg/engine.js';
|
|
2
|
+
import type { DtcgType } from '../dtcg/types.js';
|
|
3
|
+
export declare const PREFIX = "und";
|
|
4
|
+
export declare function cssName(path: string): string;
|
|
5
|
+
export declare function cssVar(path: string): string;
|
|
6
|
+
export declare function hex8(hex: string, alpha: number): string;
|
|
7
|
+
export interface ColorLike {
|
|
8
|
+
colorSpace: string;
|
|
9
|
+
components: number[];
|
|
10
|
+
alpha?: number;
|
|
11
|
+
hex?: string;
|
|
12
|
+
}
|
|
13
|
+
/** sRGB fallback: 6-digit hex, or 8-digit hex with alpha. */
|
|
14
|
+
export declare function colorCss(c: ColorLike): string;
|
|
15
|
+
/** Display-P3 value if the token's P3 chroma exceeds its sRGB-safe chroma, else null. */
|
|
16
|
+
export declare function colorP3Css(token: Pick<FlatToken, 'value' | 'extensions'>): string | null;
|
|
17
|
+
export declare function dimensionCss(v: unknown): string;
|
|
18
|
+
export declare function fontFamilyCss(v: unknown): string;
|
|
19
|
+
export declare function cubicCss(v: unknown): string;
|
|
20
|
+
export declare function shadowCss(v: unknown): string;
|
|
21
|
+
/** Fluid clamp() between two viewport widths (rem + vw, so zoom still works, WCAG 1.4.4). */
|
|
22
|
+
export declare function fluidClamp(minPx: number, maxPx: number, minVw: number, maxVw: number): string;
|
|
23
|
+
export interface DeclOptions {
|
|
24
|
+
/** Effective type lookup for referenced paths. */
|
|
25
|
+
typeOf: (path: string) => DtcgType | undefined;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* CSS declarations for one token as written in a source file. Aliases become
|
|
29
|
+
* var() references so the cascade (themes, modes) keeps working at runtime.
|
|
30
|
+
*/
|
|
31
|
+
export declare function tokenDeclarations(token: FlatToken, type: DtcgType): [string, string][];
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/** Formats DTCG values as CSS (custom property declarations). */
|
|
2
|
+
import { round } from '../color/convert.js';
|
|
3
|
+
import { isReference, refPath, undExt } from '../dtcg/types.js';
|
|
4
|
+
export const PREFIX = 'und';
|
|
5
|
+
export function cssName(path) {
|
|
6
|
+
return `--${PREFIX}-${path.replace(/\.\$root$/, '').replace(/\./g, '-')}`;
|
|
7
|
+
}
|
|
8
|
+
export function cssVar(path) {
|
|
9
|
+
return `var(${cssName(path)})`;
|
|
10
|
+
}
|
|
11
|
+
const GENERIC_FAMILIES = new Set([
|
|
12
|
+
'serif',
|
|
13
|
+
'sans-serif',
|
|
14
|
+
'monospace',
|
|
15
|
+
'cursive',
|
|
16
|
+
'fantasy',
|
|
17
|
+
'system-ui',
|
|
18
|
+
'ui-serif',
|
|
19
|
+
'ui-sans-serif',
|
|
20
|
+
'ui-monospace',
|
|
21
|
+
'ui-rounded',
|
|
22
|
+
'emoji',
|
|
23
|
+
'math',
|
|
24
|
+
'fangsong',
|
|
25
|
+
'-apple-system',
|
|
26
|
+
]);
|
|
27
|
+
const num = (n) => String(round(n, 4));
|
|
28
|
+
export function hex8(hex, alpha) {
|
|
29
|
+
const a = Math.round(alpha * 255)
|
|
30
|
+
.toString(16)
|
|
31
|
+
.padStart(2, '0');
|
|
32
|
+
return `${hex}${a}`;
|
|
33
|
+
}
|
|
34
|
+
/** sRGB fallback: 6-digit hex, or 8-digit hex with alpha. */
|
|
35
|
+
export function colorCss(c) {
|
|
36
|
+
const alpha = c.alpha ?? 1;
|
|
37
|
+
if (!c.hex)
|
|
38
|
+
throw new Error(`Colour without hex fallback: ${JSON.stringify(c)}`);
|
|
39
|
+
return alpha < 1 ? hex8(c.hex, alpha) : c.hex;
|
|
40
|
+
}
|
|
41
|
+
/** Display-P3 value if the token's P3 chroma exceeds its sRGB-safe chroma, else null. */
|
|
42
|
+
export function colorP3Css(token) {
|
|
43
|
+
if (isReference(token.value))
|
|
44
|
+
return null;
|
|
45
|
+
const c = token.value;
|
|
46
|
+
const ext = undExt(token);
|
|
47
|
+
if (c.colorSpace !== 'oklch' || !ext.p3 || ext.srgbChroma === undefined)
|
|
48
|
+
return null;
|
|
49
|
+
if (!(c.components[1] > ext.srgbChroma))
|
|
50
|
+
return null;
|
|
51
|
+
const [r, g, b] = ext.p3;
|
|
52
|
+
const alpha = c.alpha ?? 1;
|
|
53
|
+
return `color(display-p3 ${num(r)} ${num(g)} ${num(b)}${alpha < 1 ? ` / ${num(alpha)}` : ''})`;
|
|
54
|
+
}
|
|
55
|
+
export function dimensionCss(v) {
|
|
56
|
+
if (isReference(v))
|
|
57
|
+
return cssVar(refPath(v));
|
|
58
|
+
const d = v;
|
|
59
|
+
return d.value === 0 ? '0' : `${num(d.value)}${d.unit}`;
|
|
60
|
+
}
|
|
61
|
+
export function fontFamilyCss(v) {
|
|
62
|
+
if (isReference(v))
|
|
63
|
+
return cssVar(refPath(v));
|
|
64
|
+
const list = Array.isArray(v) ? v : [v];
|
|
65
|
+
return list.map((f) => (GENERIC_FAMILIES.has(f) ? f : `"${f}"`)).join(', ');
|
|
66
|
+
}
|
|
67
|
+
export function cubicCss(v) {
|
|
68
|
+
if (isReference(v))
|
|
69
|
+
return cssVar(refPath(v));
|
|
70
|
+
const [a, b, c, d] = v;
|
|
71
|
+
if (a === 0 && b === 0 && c === 1 && d === 1)
|
|
72
|
+
return 'linear';
|
|
73
|
+
return `cubic-bezier(${num(a)}, ${num(b)}, ${num(c)}, ${num(d)})`;
|
|
74
|
+
}
|
|
75
|
+
function shadowLayerCss(l) {
|
|
76
|
+
const color = isReference(l.color) ? cssVar(refPath(l.color)) : colorCss(l.color);
|
|
77
|
+
const parts = [
|
|
78
|
+
dimensionCss(l.offsetX),
|
|
79
|
+
dimensionCss(l.offsetY),
|
|
80
|
+
dimensionCss(l.blur),
|
|
81
|
+
dimensionCss(l.spread),
|
|
82
|
+
color,
|
|
83
|
+
];
|
|
84
|
+
return `${l.inset ? 'inset ' : ''}${parts.join(' ')}`;
|
|
85
|
+
}
|
|
86
|
+
export function shadowCss(v) {
|
|
87
|
+
if (isReference(v))
|
|
88
|
+
return cssVar(refPath(v));
|
|
89
|
+
const layers = (Array.isArray(v) ? v : [v]);
|
|
90
|
+
const css = layers.map((l) => (isReference(l) ? cssVar(refPath(l)) : shadowLayerCss(l)));
|
|
91
|
+
const visible = layers.filter((l) => isReference(l) || l.color.alpha !== 0);
|
|
92
|
+
return visible.length === 0 ? 'none' : css.join(', ');
|
|
93
|
+
}
|
|
94
|
+
/** Fluid clamp() between two viewport widths (rem + vw, so zoom still works, WCAG 1.4.4). */
|
|
95
|
+
export function fluidClamp(minPx, maxPx, minVw, maxVw) {
|
|
96
|
+
const slope = (maxPx - minPx) / (maxVw - minVw);
|
|
97
|
+
const intercept = minPx - slope * minVw;
|
|
98
|
+
return `clamp(${num(minPx / 16)}rem, ${num(intercept / 16)}rem + ${num(slope * 100)}vw, ${num(maxPx / 16)}rem)`;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* CSS declarations for one token as written in a source file. Aliases become
|
|
102
|
+
* var() references so the cascade (themes, modes) keeps working at runtime.
|
|
103
|
+
*/
|
|
104
|
+
export function tokenDeclarations(token, type) {
|
|
105
|
+
const name = cssName(token.path);
|
|
106
|
+
const v = token.value;
|
|
107
|
+
const ext = undExt(token);
|
|
108
|
+
if (isReference(v) && type !== 'typography') {
|
|
109
|
+
// Spring easing semantic aliases keep their spring.
|
|
110
|
+
return [[name, cssVar(refPath(v))]];
|
|
111
|
+
}
|
|
112
|
+
switch (type) {
|
|
113
|
+
case 'color':
|
|
114
|
+
return [[name, colorCss(v)]];
|
|
115
|
+
case 'dimension': {
|
|
116
|
+
const d = v;
|
|
117
|
+
if (ext.radiusScale)
|
|
118
|
+
return [[name, `calc(${num(d.value)}${d.unit} * var(--${PREFIX}-radius-factor))`]];
|
|
119
|
+
return [[name, dimensionCss(v)]];
|
|
120
|
+
}
|
|
121
|
+
case 'number':
|
|
122
|
+
return [[name, ext.unit ? `${num(v)}${ext.unit}` : num(v)]];
|
|
123
|
+
case 'fontWeight':
|
|
124
|
+
return [[name, String(v)]];
|
|
125
|
+
case 'fontFamily':
|
|
126
|
+
return [[name, fontFamilyCss(v)]];
|
|
127
|
+
case 'duration': {
|
|
128
|
+
const d = v;
|
|
129
|
+
const ms = d.unit === 's' ? d.value * 1000 : d.value;
|
|
130
|
+
if (ms === 0)
|
|
131
|
+
return [[name, '0ms']];
|
|
132
|
+
if (ext.tempo === false)
|
|
133
|
+
return [[name, `${num(ms)}ms`]];
|
|
134
|
+
return [[name, `calc(${num(ms)}ms * var(--_${PREFIX}-tempo))`]];
|
|
135
|
+
}
|
|
136
|
+
case 'cubicBezier':
|
|
137
|
+
if (typeof ext.spring === 'string')
|
|
138
|
+
return [[name, cssVar(ext.spring)]];
|
|
139
|
+
return [[name, cubicCss(v)]];
|
|
140
|
+
case 'shadow':
|
|
141
|
+
return [[name, shadowCss(v)]];
|
|
142
|
+
case 'transition': {
|
|
143
|
+
const t = v;
|
|
144
|
+
if (ext.kind === 'spring' && typeof ext.linear === 'string') {
|
|
145
|
+
return [
|
|
146
|
+
[name, ext.linear],
|
|
147
|
+
[`${name}-fallback`, cubicCss(t.timingFunction)],
|
|
148
|
+
[`${name}-duration`, `calc(${num(t.duration.value)}ms * var(--_${PREFIX}-tempo))`],
|
|
149
|
+
];
|
|
150
|
+
}
|
|
151
|
+
return [[name, `${dimensionCss(t.duration)} ${cubicCss(t.timingFunction)}`]];
|
|
152
|
+
}
|
|
153
|
+
case 'typography': {
|
|
154
|
+
const t = v;
|
|
155
|
+
let size;
|
|
156
|
+
if (ext.fluid)
|
|
157
|
+
size = fluidClamp(ext.fluid.minPx, ext.fluid.maxPx, ext.fluid.minViewportPx, ext.fluid.maxViewportPx);
|
|
158
|
+
else if (ext.fontSizeEm !== undefined)
|
|
159
|
+
size = `${num(ext.fontSizeEm)}em`;
|
|
160
|
+
else
|
|
161
|
+
size = dimensionCss(t.fontSize);
|
|
162
|
+
const tracking = ext.letterSpacingEm !== undefined
|
|
163
|
+
? ext.letterSpacingEm === 0
|
|
164
|
+
? '0'
|
|
165
|
+
: `${num(ext.letterSpacingEm)}em`
|
|
166
|
+
: dimensionCss(t.letterSpacing);
|
|
167
|
+
const weight = isReference(t.fontWeight)
|
|
168
|
+
? cssVar(refPath(t.fontWeight))
|
|
169
|
+
: String(t.fontWeight);
|
|
170
|
+
const lh = isReference(t.lineHeight)
|
|
171
|
+
? cssVar(refPath(t.lineHeight))
|
|
172
|
+
: num(t.lineHeight);
|
|
173
|
+
const out = [
|
|
174
|
+
[`${name}-family`, fontFamilyCss(t.fontFamily)],
|
|
175
|
+
[`${name}-size`, size],
|
|
176
|
+
[`${name}-weight`, weight],
|
|
177
|
+
[`${name}-tracking`, tracking],
|
|
178
|
+
[`${name}-lh`, lh],
|
|
179
|
+
];
|
|
180
|
+
if (ext.lineHeightIndic !== undefined)
|
|
181
|
+
out.push([`${name}-lh-indic`, num(ext.lineHeightIndic)]);
|
|
182
|
+
out.push([
|
|
183
|
+
`${name}-font`,
|
|
184
|
+
`var(${name}-weight) var(${name}-size)/var(${name}-lh) var(${name}-family)`,
|
|
185
|
+
]);
|
|
186
|
+
return out;
|
|
187
|
+
}
|
|
188
|
+
default:
|
|
189
|
+
throw new Error(`No CSS format for ${type} (${token.path})`);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS custom properties. The cascade mirrors the DTCG resolver: one block per
|
|
3
|
+
* resolver context, emitted in resolution order with zero-specificity
|
|
4
|
+
* :where() selectors, so later contexts win exactly like later sources do.
|
|
5
|
+
*
|
|
6
|
+
* <html data-und-theme="kesar" data-und-mode="dark|light|system"
|
|
7
|
+
* data-und-contrast="more|standard|auto" data-und-density="compact|comfortable|touch|auto"
|
|
8
|
+
* data-und-transparency="reduced|full|auto" data-und-motion="reduced|full|auto">
|
|
9
|
+
*
|
|
10
|
+
* Any element carrying data-und-theme / -mode / -contrast is a scope: semantic
|
|
11
|
+
* aliases are re-declared there so var() chains re-resolve. A nested scope
|
|
12
|
+
* inherits the attributes it does not set from the nearest explicit ancestor
|
|
13
|
+
* (one level of nesting per attribute).
|
|
14
|
+
*/
|
|
15
|
+
import type { FlatToken, ResolverDoc, TokenFiles } from '../../dtcg/engine.js';
|
|
16
|
+
import type { DtcgType } from '../../dtcg/types.js';
|
|
17
|
+
export declare const SCOPE_ATTRS: readonly ["data-und-theme", "data-und-mode", "data-und-contrast"];
|
|
18
|
+
export interface Condition {
|
|
19
|
+
theme?: string;
|
|
20
|
+
mode?: string;
|
|
21
|
+
contrast?: string;
|
|
22
|
+
density?: string;
|
|
23
|
+
transparency?: string;
|
|
24
|
+
motion?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface CssBlock {
|
|
27
|
+
id: string;
|
|
28
|
+
/** Which resolver context(s) this block represents (for cascade simulation). */
|
|
29
|
+
condition: Condition;
|
|
30
|
+
/** true = applies only when the attribute is absent/auto and the media query matches. */
|
|
31
|
+
auto?: boolean;
|
|
32
|
+
selector: string;
|
|
33
|
+
wrappers: string[];
|
|
34
|
+
decls: Map<string, string>;
|
|
35
|
+
/** Group used to split the per-theme / motion files. */
|
|
36
|
+
group: 'base' | 'mode' | 'theme' | 'contrast' | 'density' | 'transparency' | 'motion' | 'extra';
|
|
37
|
+
/** Declarations are motion-related (for motion.css). */
|
|
38
|
+
motionOnly?: boolean;
|
|
39
|
+
}
|
|
40
|
+
export declare function buildCssBlocks(files: TokenFiles, resolver: ResolverDoc, typeOf: (p: string) => DtcgType | undefined): CssBlock[];
|
|
41
|
+
export declare function renderBlocks(blocks: CssBlock[], header: string): string;
|
|
42
|
+
export declare function filterMotion(blocks: CssBlock[]): CssBlock[];
|
|
43
|
+
export type { FlatToken };
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { flattenFile } from '../../dtcg/engine.js';
|
|
2
|
+
import { THEMES } from '../../themes/definitions.js';
|
|
3
|
+
import { PREFIX, colorP3Css, cssName, tokenDeclarations } from '../css-values.js';
|
|
4
|
+
export const SCOPE_ATTRS = ['data-und-theme', 'data-und-mode', 'data-und-contrast'];
|
|
5
|
+
const S_LIST = [':root', ...SCOPE_ATTRS.map((a) => `[${a}]`)];
|
|
6
|
+
const S = S_LIST.join(', ');
|
|
7
|
+
const MODIFIER_ATTR = {
|
|
8
|
+
mode: 'data-und-mode',
|
|
9
|
+
theme: 'data-und-theme',
|
|
10
|
+
contrast: 'data-und-contrast',
|
|
11
|
+
density: 'data-und-density',
|
|
12
|
+
transparency: 'data-und-transparency',
|
|
13
|
+
motion: 'data-und-motion',
|
|
14
|
+
};
|
|
15
|
+
const AUTO_VALUE = {
|
|
16
|
+
mode: 'system',
|
|
17
|
+
contrast: 'auto',
|
|
18
|
+
density: 'auto',
|
|
19
|
+
transparency: 'auto',
|
|
20
|
+
motion: 'auto',
|
|
21
|
+
};
|
|
22
|
+
/** `[A="V"]` plus scope elements below it that do not set A themselves. */
|
|
23
|
+
function explicitSelector(modifier, value, extra = []) {
|
|
24
|
+
const attr = MODIFIER_ATTR[modifier];
|
|
25
|
+
const others = SCOPE_ATTRS.filter((a) => a !== attr).map((a) => `[${a}]`);
|
|
26
|
+
return `:where([${attr}="${value}"], [${attr}="${value}"] :is(${others.join(', ')}):not([${attr}])${extra.length ? `, ${extra.join(', ')}` : ''})`;
|
|
27
|
+
}
|
|
28
|
+
/** Scope elements with A absent (or auto) and no explicit ancestor. */
|
|
29
|
+
function autoSelector(modifier, scope = S) {
|
|
30
|
+
const attr = MODIFIER_ATTR[modifier];
|
|
31
|
+
const explicit = `[${attr}]:not([${attr}="${AUTO_VALUE[modifier]}"])`;
|
|
32
|
+
return `:where(:is(${scope}):not(${explicit}):not(${explicit} *))`;
|
|
33
|
+
}
|
|
34
|
+
function declsForSources(ctx, sources) {
|
|
35
|
+
const decls = new Map();
|
|
36
|
+
const p3 = new Map();
|
|
37
|
+
for (const src of sources) {
|
|
38
|
+
for (const t of flattenFile(ctx.files.read(src), src)) {
|
|
39
|
+
const type = t.type ?? ctx.typeOf(t.path);
|
|
40
|
+
if (!type)
|
|
41
|
+
throw new Error(`No type for ${t.path} in ${src}`);
|
|
42
|
+
for (const [k, v] of tokenDeclarations(t, type)) {
|
|
43
|
+
decls.delete(k);
|
|
44
|
+
decls.set(k, v);
|
|
45
|
+
p3.delete(k);
|
|
46
|
+
}
|
|
47
|
+
if (type === 'color') {
|
|
48
|
+
const pv = colorP3Css(t);
|
|
49
|
+
if (pv)
|
|
50
|
+
p3.set(cssName(t.path), pv);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return { decls, p3 };
|
|
55
|
+
}
|
|
56
|
+
const P3_WRAPPERS = ['@media (color-gamut: p3)', '@supports (color: color(display-p3 1 1 1))'];
|
|
57
|
+
function pushWithP3(blocks, block, p3) {
|
|
58
|
+
blocks.push(block);
|
|
59
|
+
if (p3.size) {
|
|
60
|
+
blocks.push({
|
|
61
|
+
...block,
|
|
62
|
+
id: `${block.id}:p3`,
|
|
63
|
+
wrappers: [...block.wrappers, ...P3_WRAPPERS],
|
|
64
|
+
decls: p3,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function isMotionDecl(name) {
|
|
69
|
+
return (/^--und-(duration|ease|spring|motion|tempo)-/.test(name) ||
|
|
70
|
+
name === `--_${PREFIX}-tempo` ||
|
|
71
|
+
name === '--und-motion-tempo');
|
|
72
|
+
}
|
|
73
|
+
export function buildCssBlocks(files, resolver, typeOf) {
|
|
74
|
+
const ctx = { files, typeOf };
|
|
75
|
+
const blocks = [];
|
|
76
|
+
const refs = (list) => list.map((r) => r.$ref);
|
|
77
|
+
// 1. Base set on every scope element.
|
|
78
|
+
const base = declsForSources(ctx, Object.values(resolver.sets).flatMap((s) => refs(s.sources)));
|
|
79
|
+
base.decls.set(`--_${PREFIX}-tempo`, `calc(clamp(var(--und-tempo-min), var(--und-motion-tempo), var(--und-tempo-max)) * var(--und-motion-platform-factor))`);
|
|
80
|
+
base.decls.set('--und-motion-platform-factor', 'var(--und-tempo-default)');
|
|
81
|
+
for (const m of ['thin', 'regular', 'thick', 'chrome']) {
|
|
82
|
+
base.decls.set(`--und-material-${m}-filter`, `blur(var(--und-material-${m}-blur)) saturate(var(--und-material-${m}-saturate))`);
|
|
83
|
+
}
|
|
84
|
+
pushWithP3(blocks, {
|
|
85
|
+
id: 'base',
|
|
86
|
+
condition: {},
|
|
87
|
+
selector: `:where(${S})`,
|
|
88
|
+
wrappers: [],
|
|
89
|
+
decls: base.decls,
|
|
90
|
+
group: 'base',
|
|
91
|
+
}, base.p3);
|
|
92
|
+
// Platform tempo factor and linear() fallback (both part of the base layer).
|
|
93
|
+
blocks.push({
|
|
94
|
+
id: 'tempo-desktop',
|
|
95
|
+
condition: {},
|
|
96
|
+
selector: `:where(${S})`,
|
|
97
|
+
wrappers: ['@media (hover: hover) and (pointer: fine)'],
|
|
98
|
+
decls: new Map([['--und-motion-platform-factor', 'var(--und-tempo-desktop)']]),
|
|
99
|
+
group: 'extra',
|
|
100
|
+
motionOnly: true,
|
|
101
|
+
});
|
|
102
|
+
const fallback = new Map();
|
|
103
|
+
for (const [k] of base.decls)
|
|
104
|
+
if (/^--und-spring-[a-z]+$/.test(k))
|
|
105
|
+
fallback.set(k, `var(${k}-fallback)`);
|
|
106
|
+
blocks.push({
|
|
107
|
+
id: 'spring-fallback',
|
|
108
|
+
condition: {},
|
|
109
|
+
selector: `:where(${S})`,
|
|
110
|
+
wrappers: ['@supports not (transition-timing-function: linear(0, 1))'],
|
|
111
|
+
decls: fallback,
|
|
112
|
+
group: 'extra',
|
|
113
|
+
motionOnly: true,
|
|
114
|
+
});
|
|
115
|
+
blocks.push({
|
|
116
|
+
id: 'hairline-hidpi',
|
|
117
|
+
condition: {},
|
|
118
|
+
selector: `:where(${S})`,
|
|
119
|
+
wrappers: ['@media (min-resolution: 2dppx)'],
|
|
120
|
+
decls: new Map([['--und-border-width-hairline', '0.5px']]),
|
|
121
|
+
group: 'extra',
|
|
122
|
+
});
|
|
123
|
+
// 2. Mode modifier.
|
|
124
|
+
const mode = resolver.modifiers.mode;
|
|
125
|
+
for (const [name, list] of Object.entries(mode.contexts)) {
|
|
126
|
+
const { decls, p3 } = declsForSources(ctx, refs(list));
|
|
127
|
+
decls.set('color-scheme', name);
|
|
128
|
+
if (name === (mode.default ?? 'light')) {
|
|
129
|
+
// Default mode on every scope element; dark blocks below exclude explicit light scopes.
|
|
130
|
+
pushWithP3(blocks, {
|
|
131
|
+
id: `mode:${name}`,
|
|
132
|
+
condition: {},
|
|
133
|
+
selector: `:where(${S})`,
|
|
134
|
+
wrappers: [],
|
|
135
|
+
decls,
|
|
136
|
+
group: 'mode',
|
|
137
|
+
}, p3);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
pushWithP3(blocks, {
|
|
141
|
+
id: `mode:${name}`,
|
|
142
|
+
condition: { mode: name },
|
|
143
|
+
selector: explicitSelector('mode', name),
|
|
144
|
+
wrappers: [],
|
|
145
|
+
decls,
|
|
146
|
+
group: 'mode',
|
|
147
|
+
}, p3);
|
|
148
|
+
pushWithP3(blocks, {
|
|
149
|
+
id: `mode:${name}:auto`,
|
|
150
|
+
condition: { mode: name },
|
|
151
|
+
auto: true,
|
|
152
|
+
selector: autoSelector('mode'),
|
|
153
|
+
wrappers: [`@media (prefers-color-scheme: ${name})`],
|
|
154
|
+
decls,
|
|
155
|
+
group: 'mode',
|
|
156
|
+
}, p3);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// 3. Themes.
|
|
160
|
+
const theme = resolver.modifiers.theme;
|
|
161
|
+
for (const [name, list] of Object.entries(theme.contexts)) {
|
|
162
|
+
const { decls, p3 } = declsForSources(ctx, refs(list));
|
|
163
|
+
const def = THEMES.find((t) => t.name === name);
|
|
164
|
+
if (def && def.modes.length === 1)
|
|
165
|
+
decls.set('color-scheme', def.modes[0]);
|
|
166
|
+
pushWithP3(blocks, {
|
|
167
|
+
id: `theme:${name}`,
|
|
168
|
+
condition: { theme: name },
|
|
169
|
+
selector: explicitSelector('theme', name),
|
|
170
|
+
wrappers: [],
|
|
171
|
+
decls,
|
|
172
|
+
group: 'theme',
|
|
173
|
+
}, p3);
|
|
174
|
+
}
|
|
175
|
+
// 4-7. User-preference modifiers with media-query auto variants.
|
|
176
|
+
const media = {
|
|
177
|
+
contrast: { more: '@media (prefers-contrast: more)' },
|
|
178
|
+
density: { touch: '@media (pointer: coarse)' },
|
|
179
|
+
transparency: { reduced: '@media (prefers-reduced-transparency: reduce)' },
|
|
180
|
+
motion: { reduced: '@media (prefers-reduced-motion: reduce)' },
|
|
181
|
+
};
|
|
182
|
+
for (const modName of ['contrast', 'density', 'transparency', 'motion']) {
|
|
183
|
+
const mod = resolver.modifiers[modName];
|
|
184
|
+
for (const [name, list] of Object.entries(mod.contexts)) {
|
|
185
|
+
if (list.length === 0)
|
|
186
|
+
continue;
|
|
187
|
+
const { decls, p3 } = declsForSources(ctx, refs(list));
|
|
188
|
+
const extra = modName === 'transparency' ? ['[data-und-glass="off"]'] : [];
|
|
189
|
+
const group = modName;
|
|
190
|
+
pushWithP3(blocks, {
|
|
191
|
+
id: `${modName}:${name}`,
|
|
192
|
+
condition: { [modName]: name },
|
|
193
|
+
selector: explicitSelector(modName, name, extra),
|
|
194
|
+
wrappers: [],
|
|
195
|
+
decls,
|
|
196
|
+
group,
|
|
197
|
+
motionOnly: modName === 'motion',
|
|
198
|
+
}, p3);
|
|
199
|
+
const m = media[modName]?.[name];
|
|
200
|
+
if (m) {
|
|
201
|
+
pushWithP3(blocks, {
|
|
202
|
+
id: `${modName}:${name}:auto`,
|
|
203
|
+
condition: { [modName]: name },
|
|
204
|
+
auto: true,
|
|
205
|
+
selector: autoSelector(modName),
|
|
206
|
+
wrappers: [m],
|
|
207
|
+
decls,
|
|
208
|
+
group,
|
|
209
|
+
motionOnly: modName === 'motion',
|
|
210
|
+
}, p3);
|
|
211
|
+
}
|
|
212
|
+
if (modName === 'transparency' && name === 'reduced') {
|
|
213
|
+
blocks.push({
|
|
214
|
+
id: 'transparency:no-backdrop',
|
|
215
|
+
condition: { transparency: name },
|
|
216
|
+
auto: true,
|
|
217
|
+
selector: `:where(${S})`,
|
|
218
|
+
wrappers: [
|
|
219
|
+
'@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)))',
|
|
220
|
+
],
|
|
221
|
+
decls,
|
|
222
|
+
group,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
if (modName === 'motion' && name === 'reduced') {
|
|
226
|
+
// Touch: opacity-only cross-fade capped at 200ms (report 4.6 rule 1).
|
|
227
|
+
const touch = new Map([['--und-motion-crossfade', 'var(--und-motion-crossfade-touch)']]);
|
|
228
|
+
blocks.push({
|
|
229
|
+
id: 'motion:reduced:touch',
|
|
230
|
+
condition: { motion: name },
|
|
231
|
+
selector: explicitSelector('motion', name),
|
|
232
|
+
wrappers: ['@media (pointer: coarse)'],
|
|
233
|
+
decls: touch,
|
|
234
|
+
group,
|
|
235
|
+
motionOnly: true,
|
|
236
|
+
});
|
|
237
|
+
blocks.push({
|
|
238
|
+
id: 'motion:reduced:touch:auto',
|
|
239
|
+
condition: { motion: name },
|
|
240
|
+
auto: true,
|
|
241
|
+
selector: autoSelector('motion'),
|
|
242
|
+
wrappers: ['@media (prefers-reduced-motion: reduce) and (pointer: coarse)'],
|
|
243
|
+
decls: touch,
|
|
244
|
+
group,
|
|
245
|
+
motionOnly: true,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
// Indic scripts: taller line heights, no tracking, narrower measure (report 2.3).
|
|
251
|
+
const indic = new Map();
|
|
252
|
+
for (const [k] of base.decls) {
|
|
253
|
+
const m = /^(--und-text-[a-z0-9-]+)-lh-indic$/.exec(k);
|
|
254
|
+
if (m) {
|
|
255
|
+
indic.set(`${m[1]}-lh`, `var(${k})`);
|
|
256
|
+
indic.set(`${m[1]}-tracking`, '0');
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
indic.set('--und-container-prose', 'var(--und-container-prose-indic)');
|
|
260
|
+
if (base.decls.has('--und-line-height-body'))
|
|
261
|
+
indic.set('--und-line-height-body', 'var(--und-text-body-md-lh-indic)');
|
|
262
|
+
const langs = [
|
|
263
|
+
'hi',
|
|
264
|
+
'mr',
|
|
265
|
+
'ne',
|
|
266
|
+
'sa',
|
|
267
|
+
'bn',
|
|
268
|
+
'gu',
|
|
269
|
+
'pa',
|
|
270
|
+
'ta',
|
|
271
|
+
'te',
|
|
272
|
+
'kn',
|
|
273
|
+
'ml',
|
|
274
|
+
'or',
|
|
275
|
+
'as',
|
|
276
|
+
'kok',
|
|
277
|
+
'mai',
|
|
278
|
+
];
|
|
279
|
+
blocks.push({
|
|
280
|
+
id: 'indic',
|
|
281
|
+
condition: {},
|
|
282
|
+
selector: `:where(${langs.map((l) => `:lang(${l})`).join(', ')})`,
|
|
283
|
+
wrappers: [],
|
|
284
|
+
decls: indic,
|
|
285
|
+
group: 'extra',
|
|
286
|
+
});
|
|
287
|
+
// Forced colours: semantic tokens map to system colours (report 1.8).
|
|
288
|
+
blocks.push({
|
|
289
|
+
id: 'forced-colors',
|
|
290
|
+
condition: {},
|
|
291
|
+
selector: `:where(${S})`,
|
|
292
|
+
wrappers: ['@media (forced-colors: active)'],
|
|
293
|
+
decls: forcedColors(base.decls),
|
|
294
|
+
group: 'extra',
|
|
295
|
+
});
|
|
296
|
+
return blocks;
|
|
297
|
+
}
|
|
298
|
+
function forcedColors(baseDecls) {
|
|
299
|
+
const map = new Map();
|
|
300
|
+
const set = (k, v) => map.set(k, v);
|
|
301
|
+
for (const k of ['canvas', 'surface', 'raised', 'subtle', 'muted', 'muted-hover', 'muted-active'])
|
|
302
|
+
set(`--und-bg-${k}`, 'Canvas');
|
|
303
|
+
set('--und-bg-inverse', 'CanvasText');
|
|
304
|
+
set('--und-bg-overlay', 'transparent');
|
|
305
|
+
for (const k of ['default', 'muted', 'subtle'])
|
|
306
|
+
set(`--und-fg-${k}`, 'CanvasText');
|
|
307
|
+
set('--und-fg-disabled', 'GrayText');
|
|
308
|
+
set('--und-fg-inverse', 'Canvas');
|
|
309
|
+
set('--und-fg-on-accent', 'HighlightText');
|
|
310
|
+
for (const k of ['subtle', 'default', 'strong'])
|
|
311
|
+
set(`--und-border-${k}`, 'CanvasText');
|
|
312
|
+
set('--und-border-control', 'ButtonText');
|
|
313
|
+
set('--und-border-control-hover', 'Highlight');
|
|
314
|
+
for (const k of ['bg', 'bg-hover', 'bg-active'])
|
|
315
|
+
set(`--und-accent-${k}`, 'Canvas');
|
|
316
|
+
set('--und-accent-border', 'CanvasText');
|
|
317
|
+
set('--und-accent-solid', 'Highlight');
|
|
318
|
+
set('--und-accent-solid-hover', 'Highlight');
|
|
319
|
+
set('--und-accent-fg', 'LinkText');
|
|
320
|
+
set('--und-accent-fg-strong', 'CanvasText');
|
|
321
|
+
set('--und-focus-ring', 'Highlight');
|
|
322
|
+
set('--und-link-default', 'LinkText');
|
|
323
|
+
set('--und-link-visited', 'VisitedText');
|
|
324
|
+
set('--und-selection-bg', 'Highlight');
|
|
325
|
+
for (const s of ['success', 'warning', 'danger', 'info']) {
|
|
326
|
+
for (const k of ['bg', 'bg-hover'])
|
|
327
|
+
set(`--und-status-${s}-${k}`, 'Canvas');
|
|
328
|
+
for (const k of ['border', 'fg', 'fg-strong'])
|
|
329
|
+
set(`--und-status-${s}-${k}`, 'CanvasText');
|
|
330
|
+
for (const k of ['solid', 'solid-hover'])
|
|
331
|
+
set(`--und-status-${s}-${k}`, 'Highlight');
|
|
332
|
+
set(`--und-status-${s}-on-solid`, 'HighlightText');
|
|
333
|
+
}
|
|
334
|
+
for (const m of ['thin', 'regular', 'thick', 'chrome']) {
|
|
335
|
+
set(`--und-material-${m}-bg`, 'Canvas');
|
|
336
|
+
set(`--und-material-${m}-border`, 'CanvasText');
|
|
337
|
+
set(`--und-material-${m}-filter`, 'none');
|
|
338
|
+
}
|
|
339
|
+
set('--und-material-chrome-highlight', 'transparent');
|
|
340
|
+
for (const [k] of baseDecls)
|
|
341
|
+
if (/^--und-shadow-\d$/.test(k))
|
|
342
|
+
set(k, 'none');
|
|
343
|
+
for (let i = 0; i <= 5; i++)
|
|
344
|
+
set(`--und-shadow-${i}`, 'none');
|
|
345
|
+
set('--und-focus-width', '2px');
|
|
346
|
+
// v0 component bridge.
|
|
347
|
+
for (const tone of ['accent', 'neutral', 'success', 'warning', 'danger']) {
|
|
348
|
+
set(`--und-color-${tone}`, 'ButtonText');
|
|
349
|
+
set(`--und-color-on-${tone}`, 'ButtonFace');
|
|
350
|
+
}
|
|
351
|
+
set('--und-focus-ring-color', 'Highlight');
|
|
352
|
+
return map;
|
|
353
|
+
}
|
|
354
|
+
// ---------------------------------------------------------------- rendering
|
|
355
|
+
export function renderBlocks(blocks, header) {
|
|
356
|
+
const out = [header];
|
|
357
|
+
for (const b of blocks) {
|
|
358
|
+
if (b.decls.size === 0)
|
|
359
|
+
continue;
|
|
360
|
+
const indent = ' '.repeat(b.wrappers.length);
|
|
361
|
+
const lines = [];
|
|
362
|
+
b.wrappers.forEach((w, i) => lines.push(`${' '.repeat(i)}${w} {`));
|
|
363
|
+
lines.push(`${indent}${b.selector} {`);
|
|
364
|
+
for (const [k, v] of b.decls)
|
|
365
|
+
lines.push(`${indent} ${k}: ${v};`);
|
|
366
|
+
lines.push(`${indent}}`);
|
|
367
|
+
for (let i = b.wrappers.length - 1; i >= 0; i--)
|
|
368
|
+
lines.push(`${' '.repeat(i)}}`);
|
|
369
|
+
out.push(`/* ${b.id} */\n${lines.join('\n')}`);
|
|
370
|
+
}
|
|
371
|
+
return `${out.join('\n\n')}\n`;
|
|
372
|
+
}
|
|
373
|
+
export function filterMotion(blocks) {
|
|
374
|
+
return blocks
|
|
375
|
+
.map((b) => ({
|
|
376
|
+
...b,
|
|
377
|
+
decls: new Map([...b.decls].filter(([k]) => b.motionOnly || isMotionDecl(k))),
|
|
378
|
+
}))
|
|
379
|
+
.filter((b) => b.decls.size > 0 && !b.id.endsWith(':p3'));
|
|
380
|
+
}
|