@uni-design-system/uni-angular 4.0.0 → 5.0.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 +116 -15
- package/fesm2022/uni-design-system-uni-angular.mjs +2226 -1267
- package/fesm2022/uni-design-system-uni-angular.mjs.map +1 -1
- package/package.json +11 -7
- package/schematics/collection.json +9 -0
- package/schematics/ng-add/index.js +1586 -0
- package/schematics/ng-add/schema.json +47 -0
- package/types/uni-design-system-uni-angular.d.ts +442 -166
|
@@ -0,0 +1,1586 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _angular_devkit_schematics = require("@angular-devkit/schematics");
|
|
3
|
+
let _angular_devkit_schematics_tasks = require("@angular-devkit/schematics/tasks");
|
|
4
|
+
//#region ../core/dist/esm/index.js
|
|
5
|
+
var cycle = (angle) => {
|
|
6
|
+
if (angle > 360) return angle - 360;
|
|
7
|
+
if (angle < 0) return angle + 360;
|
|
8
|
+
return angle;
|
|
9
|
+
};
|
|
10
|
+
var getAnalogousHues = (hue) => [cycle(hue + 30), cycle(hue + 60)];
|
|
11
|
+
var getComplimentaryHue = (hue) => cycle(hue + 180);
|
|
12
|
+
var getTriadicHues = (hue) => [cycle(hue + 120), cycle(hue - 120)];
|
|
13
|
+
var getSplitComplimentaryHues = (hue) => [cycle(hue + 150), cycle(hue - 150)];
|
|
14
|
+
/**
|
|
15
|
+
* Derive the primary/secondary/tertiary hues from a seed hue using the color
|
|
16
|
+
* wheel relationships in {@link ColorScheme}. Pure angle math — works in any
|
|
17
|
+
* hue space (HSL historically, OKLCH in the generation engine).
|
|
18
|
+
*/
|
|
19
|
+
var schemeHues = (hue, scheme) => {
|
|
20
|
+
switch (scheme) {
|
|
21
|
+
case "monochromatic": return {
|
|
22
|
+
primary: hue,
|
|
23
|
+
secondary: hue,
|
|
24
|
+
tertiary: hue
|
|
25
|
+
};
|
|
26
|
+
case "analogous": {
|
|
27
|
+
const [a, b] = getAnalogousHues(hue);
|
|
28
|
+
return {
|
|
29
|
+
primary: hue,
|
|
30
|
+
secondary: a,
|
|
31
|
+
tertiary: b
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
case "complimentary": {
|
|
35
|
+
const [a] = getAnalogousHues(hue);
|
|
36
|
+
return {
|
|
37
|
+
primary: hue,
|
|
38
|
+
secondary: getComplimentaryHue(hue),
|
|
39
|
+
tertiary: a
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
case "splitComplimentary": {
|
|
43
|
+
const [a, b] = getSplitComplimentaryHues(hue);
|
|
44
|
+
return {
|
|
45
|
+
primary: hue,
|
|
46
|
+
secondary: a,
|
|
47
|
+
tertiary: b
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
case "triadic": {
|
|
51
|
+
const [a, b] = getTriadicHues(hue);
|
|
52
|
+
return {
|
|
53
|
+
primary: hue,
|
|
54
|
+
secondary: a,
|
|
55
|
+
tertiary: b
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
var clamp$2 = (value, min, max) => Math.min(max, Math.max(min, value));
|
|
61
|
+
var toHex2 = (value) => clamp$2(Math.round(value), 0, 255).toString(16).padStart(2, "0");
|
|
62
|
+
var rgbToHex = ({ red, green, blue }) => `#${toHex2(red)}${toHex2(green)}${toHex2(blue)}`.toUpperCase();
|
|
63
|
+
var hexToRgb = (hex) => {
|
|
64
|
+
let h = hex.replace("#", "").trim();
|
|
65
|
+
if (h.length === 3) h = h.split("").map((c) => c + c).join("");
|
|
66
|
+
const int = parseInt(h, 16);
|
|
67
|
+
return {
|
|
68
|
+
red: int >> 16 & 255,
|
|
69
|
+
green: int >> 8 & 255,
|
|
70
|
+
blue: int & 255
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
/** WCAG relative luminance of an sRGB color (0 = black, 1 = white). */
|
|
74
|
+
var relativeLuminance = ({ red, green, blue }) => {
|
|
75
|
+
const channel = (value) => {
|
|
76
|
+
const v = value / 255;
|
|
77
|
+
return v <= .03928 ? v / 12.92 : Math.pow((v + .055) / 1.055, 2.4);
|
|
78
|
+
};
|
|
79
|
+
return .2126 * channel(red) + .7152 * channel(green) + .0722 * channel(blue);
|
|
80
|
+
};
|
|
81
|
+
/** WCAG contrast ratio between two colors (1:1 – 21:1). Accepts RGB or hex. */
|
|
82
|
+
var contrastRatio = (a, b) => {
|
|
83
|
+
const la = relativeLuminance(typeof a === "string" ? hexToRgb(a) : a);
|
|
84
|
+
const lb = relativeLuminance(typeof b === "string" ? hexToRgb(b) : b);
|
|
85
|
+
const [hi, lo] = la > lb ? [la, lb] : [lb, la];
|
|
86
|
+
return (hi + .05) / (lo + .05);
|
|
87
|
+
};
|
|
88
|
+
var clamp$1 = (value, min, max) => Math.min(max, Math.max(min, value));
|
|
89
|
+
var srgbToLinear = (channel) => channel <= .04045 ? channel / 12.92 : Math.pow((channel + .055) / 1.055, 2.4);
|
|
90
|
+
var linearToSrgb = (channel) => channel <= .0031308 ? 12.92 * channel : 1.055 * Math.pow(channel, 1 / 2.4) - .055;
|
|
91
|
+
var linearRgbToOklab = ({ r, g, b }) => {
|
|
92
|
+
const l = Math.cbrt(.4122214708 * r + .5363325363 * g + .0514459929 * b);
|
|
93
|
+
const m = Math.cbrt(.2119034982 * r + .6806995451 * g + .1073969566 * b);
|
|
94
|
+
const s = Math.cbrt(.0883024619 * r + .2817188376 * g + .6299787005 * b);
|
|
95
|
+
return {
|
|
96
|
+
l: .2104542553 * l + .793617785 * m - .0040720468 * s,
|
|
97
|
+
a: 1.9779984951 * l - 2.428592205 * m + .4505937099 * s,
|
|
98
|
+
b: .0259040371 * l + .7827717662 * m - .808675766 * s
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
var oklabToLinearRgb = (l, a, b) => {
|
|
102
|
+
const l_ = Math.pow(l + .3963377774 * a + .2158037573 * b, 3);
|
|
103
|
+
const m_ = Math.pow(l - .1055613458 * a - .0638541728 * b, 3);
|
|
104
|
+
const s_ = Math.pow(l - .0894841775 * a - 1.291485548 * b, 3);
|
|
105
|
+
return {
|
|
106
|
+
r: 4.0767416621 * l_ - 3.3077115913 * m_ + .2309699292 * s_,
|
|
107
|
+
g: -1.2684380046 * l_ + 2.6097574011 * m_ - .3413193965 * s_,
|
|
108
|
+
b: -.0041960863 * l_ - .7034186147 * m_ + 1.707614701 * s_
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
var oklchToLinearRgb = ({ l, c, h }) => {
|
|
112
|
+
const rad = h * Math.PI / 180;
|
|
113
|
+
return oklabToLinearRgb(l, c * Math.cos(rad), c * Math.sin(rad));
|
|
114
|
+
};
|
|
115
|
+
var GAMUT_EPSILON = 1e-4;
|
|
116
|
+
var inSrgbGamut = ({ r, g, b }) => r >= -GAMUT_EPSILON && r <= 1 + GAMUT_EPSILON && g >= -GAMUT_EPSILON && g <= 1 + GAMUT_EPSILON && b >= -GAMUT_EPSILON && b <= 1 + GAMUT_EPSILON;
|
|
117
|
+
/** Parse a hex color (`#RGB` or `#RRGGBB`) into OKLCH. */
|
|
118
|
+
var hexToOklch = (hex) => {
|
|
119
|
+
const { red, green, blue } = hexToRgb(hex);
|
|
120
|
+
const { l, a, b } = linearRgbToOklab({
|
|
121
|
+
r: srgbToLinear(red / 255),
|
|
122
|
+
g: srgbToLinear(green / 255),
|
|
123
|
+
b: srgbToLinear(blue / 255)
|
|
124
|
+
});
|
|
125
|
+
const c = Math.hypot(a, b);
|
|
126
|
+
const h = c < 1e-6 ? 0 : Math.atan2(b, a) * 180 / Math.PI;
|
|
127
|
+
return {
|
|
128
|
+
l,
|
|
129
|
+
c,
|
|
130
|
+
h: h < 0 ? h + 360 : h
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* Render OKLCH as an sRGB hex string. Out-of-gamut colors are mapped back
|
|
135
|
+
* into sRGB by reducing chroma only — lightness and hue are preserved, so
|
|
136
|
+
* vivid seeds desaturate gracefully instead of shifting hue or clipping.
|
|
137
|
+
*/
|
|
138
|
+
var oklchToHex = (color) => {
|
|
139
|
+
const target = {
|
|
140
|
+
l: clamp$1(color.l, 0, 1),
|
|
141
|
+
c: Math.max(color.c, 0),
|
|
142
|
+
h: color.h
|
|
143
|
+
};
|
|
144
|
+
let rgb = oklchToLinearRgb(target);
|
|
145
|
+
if (!inSrgbGamut(rgb)) {
|
|
146
|
+
let low = 0;
|
|
147
|
+
let high = target.c;
|
|
148
|
+
for (let i = 0; i < 24; i++) {
|
|
149
|
+
const mid = (low + high) / 2;
|
|
150
|
+
if (inSrgbGamut(oklchToLinearRgb({
|
|
151
|
+
...target,
|
|
152
|
+
c: mid
|
|
153
|
+
}))) low = mid;
|
|
154
|
+
else high = mid;
|
|
155
|
+
}
|
|
156
|
+
rgb = oklchToLinearRgb({
|
|
157
|
+
...target,
|
|
158
|
+
c: low
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
return rgbToHex(toSrgb255(rgb));
|
|
162
|
+
};
|
|
163
|
+
var toSrgb255 = ({ r, g, b }) => ({
|
|
164
|
+
red: 255 * linearToSrgb(clamp$1(r, 0, 1)),
|
|
165
|
+
green: 255 * linearToSrgb(clamp$1(g, 0, 1)),
|
|
166
|
+
blue: 255 * linearToSrgb(clamp$1(b, 0, 1))
|
|
167
|
+
});
|
|
168
|
+
var toneMap = (dark) => dark ? {
|
|
169
|
+
accent: .78,
|
|
170
|
+
container: .42,
|
|
171
|
+
roleSurface: .26,
|
|
172
|
+
background: .18,
|
|
173
|
+
surface: .21,
|
|
174
|
+
surfaceVariant: .32,
|
|
175
|
+
outline: .66,
|
|
176
|
+
onSurface: .93,
|
|
177
|
+
mutedText: .76,
|
|
178
|
+
inverse: .93,
|
|
179
|
+
onInverse: .25,
|
|
180
|
+
onDeep: .2,
|
|
181
|
+
onLight: .985,
|
|
182
|
+
grey: .72,
|
|
183
|
+
disabledContainer: .3
|
|
184
|
+
} : {
|
|
185
|
+
accent: .55,
|
|
186
|
+
container: .9,
|
|
187
|
+
roleSurface: .97,
|
|
188
|
+
background: .995,
|
|
189
|
+
surface: .985,
|
|
190
|
+
surfaceVariant: .94,
|
|
191
|
+
outline: .6,
|
|
192
|
+
onSurface: .25,
|
|
193
|
+
mutedText: .48,
|
|
194
|
+
inverse: .3,
|
|
195
|
+
onInverse: .97,
|
|
196
|
+
onDeep: .24,
|
|
197
|
+
onLight: .985,
|
|
198
|
+
grey: .5,
|
|
199
|
+
disabledContainer: .96
|
|
200
|
+
};
|
|
201
|
+
var CategoryChroma = {
|
|
202
|
+
jewel: .17,
|
|
203
|
+
pastel: .055,
|
|
204
|
+
earth: .08,
|
|
205
|
+
neutral: .03,
|
|
206
|
+
florescent: .26,
|
|
207
|
+
shades: 0
|
|
208
|
+
};
|
|
209
|
+
/** Dark-mode accents cap chroma so they don't vibrate on dark surfaces. */
|
|
210
|
+
var DARK_ACCENT_CHROMA_CAP = .16;
|
|
211
|
+
var SemanticColors = {
|
|
212
|
+
error: {
|
|
213
|
+
hue: 27,
|
|
214
|
+
chroma: .2
|
|
215
|
+
},
|
|
216
|
+
warn: {
|
|
217
|
+
hue: 55,
|
|
218
|
+
chroma: .18
|
|
219
|
+
},
|
|
220
|
+
success: {
|
|
221
|
+
hue: 152,
|
|
222
|
+
chroma: .16
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
var clamp = (value, min, max) => Math.min(max, Math.max(min, value));
|
|
226
|
+
/**
|
|
227
|
+
* Generate a complete {@link Colors} token set in OKLCH. Same contract as
|
|
228
|
+
* `generatePalette` (which delegates here), plus soft brand targets and a
|
|
229
|
+
* contrast-check sink for {@link ContrastReport} consumers.
|
|
230
|
+
*/
|
|
231
|
+
var generateColors = (config) => {
|
|
232
|
+
const { seed, scheme, category, mode = "light", accentSaturationFloor = 18, brand = {}, targets = {}, checks } = config;
|
|
233
|
+
const dark = mode === "dark";
|
|
234
|
+
const t = toneMap(dark);
|
|
235
|
+
const anchor = hexToOklch(brand.primary ?? targets.primary ?? seed);
|
|
236
|
+
const hues = schemeHues(anchor.h, scheme);
|
|
237
|
+
const chromaFloor = accentSaturationFloor / 100 * .28;
|
|
238
|
+
let accentC = Math.max(CategoryChroma[category], chromaFloor);
|
|
239
|
+
if (dark) accentC = Math.min(accentC, DARK_ACCENT_CHROMA_CAP);
|
|
240
|
+
const containerC = Math.max(CategoryChroma[category] * .45, accentC * .35);
|
|
241
|
+
const surfaceC = Math.min(CategoryChroma[category], .012);
|
|
242
|
+
const tone = (hue, c, l) => oklchToHex({
|
|
243
|
+
l,
|
|
244
|
+
c,
|
|
245
|
+
h: hue
|
|
246
|
+
});
|
|
247
|
+
/**
|
|
248
|
+
* The WCAG guard-rail: walk the foreground's OKLCH lightness away from the
|
|
249
|
+
* background until the pair meets `target` (≤ 50 steps). Hue is never
|
|
250
|
+
* touched; chroma only shrinks as a last resort when L runs out of room.
|
|
251
|
+
*/
|
|
252
|
+
const ensureContrast = (fg, bg, target) => {
|
|
253
|
+
const out = { ...fg };
|
|
254
|
+
let hex = oklchToHex(out);
|
|
255
|
+
if (contrastRatio(hex, bg) >= target) return out;
|
|
256
|
+
const bgY = relativeLuminance(hexToRgb(bg));
|
|
257
|
+
const darkCeiling = (bgY + .05) / .05;
|
|
258
|
+
const lightCeiling = 1.05 / (bgY + .05);
|
|
259
|
+
let lighten = relativeLuminance(hexToRgb(hex)) >= bgY;
|
|
260
|
+
if (lighten && lightCeiling < target && darkCeiling >= target) lighten = false;
|
|
261
|
+
if (!lighten && darkCeiling < target && lightCeiling >= target) lighten = true;
|
|
262
|
+
const step = lighten ? .015 : -.015;
|
|
263
|
+
for (let i = 0; i < 50 && contrastRatio(hex, bg) < target; i++) {
|
|
264
|
+
if (step > 0 && out.l < .995 || step < 0 && out.l > .02) out.l = clamp(out.l + step, 0, 1);
|
|
265
|
+
else out.c = Math.max(0, out.c - .02);
|
|
266
|
+
hex = oklchToHex(out);
|
|
267
|
+
}
|
|
268
|
+
return out;
|
|
269
|
+
};
|
|
270
|
+
/** Guard-railed token: adjust toward `target` contrast, then record the pair. */
|
|
271
|
+
const contrasted = (fg, bgHex, target) => oklchToHex(ensureContrast(fg, bgHex, target));
|
|
272
|
+
const record = (foreground, background, foregroundColor, backgroundColor, required) => {
|
|
273
|
+
if (!checks) return;
|
|
274
|
+
const ratio = contrastRatio(foregroundColor, backgroundColor);
|
|
275
|
+
checks.push({
|
|
276
|
+
mode,
|
|
277
|
+
foreground,
|
|
278
|
+
background,
|
|
279
|
+
foregroundColor,
|
|
280
|
+
backgroundColor,
|
|
281
|
+
ratio: Math.round(ratio * 100) / 100,
|
|
282
|
+
required,
|
|
283
|
+
pass: ratio >= required,
|
|
284
|
+
level: ratio < required ? "fail" : ratio >= 7 ? "AAA" : "AA"
|
|
285
|
+
});
|
|
286
|
+
};
|
|
287
|
+
const background = tone(anchor.h, surfaceC, t.background);
|
|
288
|
+
const surface = tone(anchor.h, surfaceC, t.surface);
|
|
289
|
+
const surfaceVariant = tone(anchor.h, surfaceC, t.surfaceVariant);
|
|
290
|
+
const onColor = (hue, bg, c) => {
|
|
291
|
+
const deep = {
|
|
292
|
+
l: t.onDeep,
|
|
293
|
+
c: Math.min(c, .05),
|
|
294
|
+
h: hue
|
|
295
|
+
};
|
|
296
|
+
const light = {
|
|
297
|
+
l: t.onLight,
|
|
298
|
+
c: Math.min(c, .02),
|
|
299
|
+
h: hue
|
|
300
|
+
};
|
|
301
|
+
return contrasted(contrastRatio(oklchToHex(deep), bg) >= contrastRatio(oklchToHex(light), bg) ? deep : light, bg, 4.5);
|
|
302
|
+
};
|
|
303
|
+
const adaptPinForDark = (hex) => {
|
|
304
|
+
const pin = hexToOklch(hex);
|
|
305
|
+
pin.l = Math.max(pin.l, .6);
|
|
306
|
+
return oklchToHex(ensureContrast(pin, background, 3));
|
|
307
|
+
};
|
|
308
|
+
/**
|
|
309
|
+
* Resolve a role's base color: hard pins are verbatim in light mode and
|
|
310
|
+
* lightness-lifted in dark; soft targets and generated tones are pulled to
|
|
311
|
+
* ≥ 4.5:1 as standalone ink on `background` and `surface` (§3.6).
|
|
312
|
+
*/
|
|
313
|
+
const baseFor = (name, hue, c) => {
|
|
314
|
+
const pinned = brand[name];
|
|
315
|
+
if (pinned) return dark ? adaptPinForDark(pinned) : pinned;
|
|
316
|
+
const target = targets[name];
|
|
317
|
+
let base;
|
|
318
|
+
if (target) {
|
|
319
|
+
base = hexToOklch(target);
|
|
320
|
+
if (dark) {
|
|
321
|
+
base.c = Math.min(base.c, DARK_ACCENT_CHROMA_CAP);
|
|
322
|
+
base.l = Math.max(base.l, t.accent - .08);
|
|
323
|
+
}
|
|
324
|
+
} else base = {
|
|
325
|
+
l: t.accent,
|
|
326
|
+
c,
|
|
327
|
+
h: hue
|
|
328
|
+
};
|
|
329
|
+
return oklchToHex(ensureContrast(ensureContrast(base, background, 4.5), surface, 4.5));
|
|
330
|
+
};
|
|
331
|
+
const disabled = dark ? "rgba(255,255,255,0.12)" : "rgba(0,0,0,0.12)";
|
|
332
|
+
const onDisabled = dark ? "rgba(255,255,255,0.38)" : "rgba(0,0,0,0.38)";
|
|
333
|
+
const role = (name, base, cC = containerC) => {
|
|
334
|
+
const { h, c } = hexToOklch(base);
|
|
335
|
+
const container = tone(h, cC, t.container);
|
|
336
|
+
const roleSurface = tone(h, surfaceC, t.roleSurface);
|
|
337
|
+
const onBase = onColor(h, base, c);
|
|
338
|
+
const onContainer = onColor(h, container, c);
|
|
339
|
+
const onContainerVariant = contrasted({
|
|
340
|
+
l: t.mutedText,
|
|
341
|
+
c: Math.min(cC, .06),
|
|
342
|
+
h
|
|
343
|
+
}, container, 4.5);
|
|
344
|
+
const borderHex = oklchToHex(ensureContrast(ensureContrast(hexToOklch(base), container, 3), surface, 3));
|
|
345
|
+
const onRoleSurface = onColor(h, roleSurface, surfaceC);
|
|
346
|
+
const onRoleSurfaceVariant = contrasted(hexToOklch(base), roleSurface, 4.5);
|
|
347
|
+
record(`on-${name}`, name, onBase, base, 4.5);
|
|
348
|
+
record(`on-${name}-container`, `${name}-container`, onContainer, container, 4.5);
|
|
349
|
+
record(`on-${name}-container-variant`, `${name}-container`, onContainerVariant, container, 4.5);
|
|
350
|
+
record(`on-${name}-container-border`, `${name}-container`, borderHex, container, 3);
|
|
351
|
+
record(`on-${name}-container-border`, "surface", borderHex, surface, 3);
|
|
352
|
+
record(`on-${name}-surface`, `${name}-surface`, onRoleSurface, roleSurface, 4.5);
|
|
353
|
+
record(`on-${name}-surface-variant`, `${name}-surface`, onRoleSurfaceVariant, roleSurface, 4.5);
|
|
354
|
+
record(name, "background", base, background, 4.5);
|
|
355
|
+
record(name, "surface", base, surface, 4.5);
|
|
356
|
+
return {
|
|
357
|
+
[name]: base,
|
|
358
|
+
[`on-${name}`]: onBase,
|
|
359
|
+
[`${name}-container`]: container,
|
|
360
|
+
[`on-${name}-container`]: onContainer,
|
|
361
|
+
[`on-${name}-container-variant`]: onContainerVariant,
|
|
362
|
+
[`on-${name}-container-border`]: borderHex,
|
|
363
|
+
[`${name}-surface`]: roleSurface,
|
|
364
|
+
[`on-${name}-surface`]: onRoleSurface,
|
|
365
|
+
[`on-${name}-surface-variant`]: onRoleSurfaceVariant
|
|
366
|
+
};
|
|
367
|
+
};
|
|
368
|
+
const primaryBase = baseFor("primary", hues.primary, accentC);
|
|
369
|
+
const secondaryBase = baseFor("secondary", hues.secondary, accentC);
|
|
370
|
+
const tertiaryBase = baseFor("tertiary", hues.tertiary, accentC);
|
|
371
|
+
const quaternaryGrey = brand.quaternary ? dark ? adaptPinForDark(brand.quaternary) : brand.quaternary : oklchToHex(ensureContrast({
|
|
372
|
+
l: t.grey,
|
|
373
|
+
c: surfaceC,
|
|
374
|
+
h: anchor.h
|
|
375
|
+
}, surface, 3));
|
|
376
|
+
const quaternarySurface = tone(anchor.h, surfaceC, t.roleSurface);
|
|
377
|
+
const onQuaternary = onColor(anchor.h, quaternaryGrey, surfaceC);
|
|
378
|
+
const onQuaternarySurface = onColor(anchor.h, quaternarySurface, surfaceC);
|
|
379
|
+
const onQuaternarySurfaceVariant = contrasted(hexToOklch(primaryBase), quaternarySurface, 4.5);
|
|
380
|
+
const onQuaternaryContainerVariant = contrasted({
|
|
381
|
+
l: t.mutedText,
|
|
382
|
+
c: Math.min(containerC, .06),
|
|
383
|
+
h: anchor.h
|
|
384
|
+
}, quaternarySurface, 4.5);
|
|
385
|
+
record("on-quaternary", "quaternary", onQuaternary, quaternaryGrey, 4.5);
|
|
386
|
+
record("on-quaternary-surface", "quaternary-surface", onQuaternarySurface, quaternarySurface, 4.5);
|
|
387
|
+
record("on-quaternary-surface-variant", "quaternary-surface", onQuaternarySurfaceVariant, quaternarySurface, 4.5);
|
|
388
|
+
const semantic = (name) => {
|
|
389
|
+
const { hue, chroma } = SemanticColors[name];
|
|
390
|
+
const base = baseFor(name, hue, dark ? Math.min(chroma, DARK_ACCENT_CHROMA_CAP) : chroma);
|
|
391
|
+
const { h } = hexToOklch(base);
|
|
392
|
+
const container = tone(h, containerC + .04, t.container);
|
|
393
|
+
const onBase = onColor(h, base, chroma);
|
|
394
|
+
const onContainer = onColor(h, container, chroma);
|
|
395
|
+
record(`on-${name}`, name, onBase, base, 4.5);
|
|
396
|
+
record(`on-${name}-container`, `${name}-container`, onContainer, container, 4.5);
|
|
397
|
+
record(name, "background", base, background, 4.5);
|
|
398
|
+
record(name, "surface", base, surface, 4.5);
|
|
399
|
+
return {
|
|
400
|
+
base,
|
|
401
|
+
container,
|
|
402
|
+
onBase,
|
|
403
|
+
onContainer,
|
|
404
|
+
h
|
|
405
|
+
};
|
|
406
|
+
};
|
|
407
|
+
const error = semantic("error");
|
|
408
|
+
const warn = semantic("warn");
|
|
409
|
+
const success = semantic("success");
|
|
410
|
+
const semanticExtras = (name, s) => {
|
|
411
|
+
const variant = contrasted({
|
|
412
|
+
l: t.mutedText,
|
|
413
|
+
c: .06,
|
|
414
|
+
h: s.h
|
|
415
|
+
}, s.container, 4.5);
|
|
416
|
+
const border = oklchToHex(ensureContrast(ensureContrast(hexToOklch(s.base), s.container, 3), surface, 3));
|
|
417
|
+
record(`on-${name}-container-variant`, `${name}-container`, variant, s.container, 4.5);
|
|
418
|
+
record(`on-${name}-container-border`, `${name}-container`, border, s.container, 3);
|
|
419
|
+
return {
|
|
420
|
+
variant,
|
|
421
|
+
border
|
|
422
|
+
};
|
|
423
|
+
};
|
|
424
|
+
const warnExtras = semanticExtras("warn", warn);
|
|
425
|
+
const successExtras = semanticExtras("success", success);
|
|
426
|
+
const onBackground = tone(anchor.h, surfaceC, t.onSurface);
|
|
427
|
+
const onBackgroundVariant = contrasted({
|
|
428
|
+
l: t.mutedText,
|
|
429
|
+
c: surfaceC,
|
|
430
|
+
h: anchor.h
|
|
431
|
+
}, background, 4.5);
|
|
432
|
+
const onSurface = tone(anchor.h, surfaceC, t.onSurface);
|
|
433
|
+
const onSurfaceVariant = contrasted({
|
|
434
|
+
l: dark ? t.mutedText : t.mutedText - .14,
|
|
435
|
+
c: surfaceC,
|
|
436
|
+
h: anchor.h
|
|
437
|
+
}, surfaceVariant, 4.5);
|
|
438
|
+
record("on-background", "background", onBackground, background, 4.5);
|
|
439
|
+
record("on-background-variant", "background", onBackgroundVariant, background, 4.5);
|
|
440
|
+
record("on-surface", "surface", onSurface, surface, 4.5);
|
|
441
|
+
record("on-surface-variant", "surface-variant", onSurfaceVariant, surfaceVariant, 4.5);
|
|
442
|
+
const inverseSurface = tone(anchor.h, surfaceC, t.inverse);
|
|
443
|
+
const onInverse = tone(anchor.h, surfaceC, t.onInverse);
|
|
444
|
+
const inversePrimary = contrasted(hexToOklch(primaryBase), inverseSurface, 4.5);
|
|
445
|
+
record("on-inverse-surface", "inverse-surface", onInverse, inverseSurface, 4.5);
|
|
446
|
+
record("on-inverse-surface-primary", "inverse-surface", inversePrimary, inverseSurface, 4.5);
|
|
447
|
+
record("on-inverse-container", "inverse-container", onInverse, inverseSurface, 4.5);
|
|
448
|
+
const outline = oklchToHex(ensureContrast(ensureContrast({
|
|
449
|
+
l: t.outline,
|
|
450
|
+
c: Math.min(surfaceC, .02),
|
|
451
|
+
h: hues.primary
|
|
452
|
+
}, surface, 3), background, 3));
|
|
453
|
+
record("outline", "surface", outline, surface, 3);
|
|
454
|
+
record("outline", "background", outline, background, 3);
|
|
455
|
+
return {
|
|
456
|
+
...role("primary", primaryBase),
|
|
457
|
+
...role("secondary", secondaryBase),
|
|
458
|
+
...role("tertiary", tertiaryBase),
|
|
459
|
+
quaternary: quaternaryGrey,
|
|
460
|
+
"on-quaternary": onQuaternary,
|
|
461
|
+
"quaternary-surface": quaternarySurface,
|
|
462
|
+
"on-quaternary-surface": onQuaternarySurface,
|
|
463
|
+
"on-quaternary-surface-variant": onQuaternarySurfaceVariant,
|
|
464
|
+
"on-quaternary-container-variant": onQuaternaryContainerVariant,
|
|
465
|
+
"on-quaternary-container-border": quaternaryGrey,
|
|
466
|
+
error: error.base,
|
|
467
|
+
"on-error": error.onBase,
|
|
468
|
+
"error-container": error.container,
|
|
469
|
+
"on-error-container": error.onContainer,
|
|
470
|
+
warn: warn.base,
|
|
471
|
+
"on-warn": warn.onBase,
|
|
472
|
+
"warn-container": warn.container,
|
|
473
|
+
"on-warn-container": warn.onContainer,
|
|
474
|
+
"on-warn-container-variant": warnExtras.variant,
|
|
475
|
+
"on-warn-container-border": warnExtras.border,
|
|
476
|
+
success: success.base,
|
|
477
|
+
"on-success": success.onBase,
|
|
478
|
+
"success-container": success.container,
|
|
479
|
+
"on-success-container": success.onContainer,
|
|
480
|
+
"on-success-container-variant": successExtras.variant,
|
|
481
|
+
"on-success-container-border": successExtras.border,
|
|
482
|
+
background,
|
|
483
|
+
"on-background": onBackground,
|
|
484
|
+
"on-background-variant": onBackgroundVariant,
|
|
485
|
+
surface,
|
|
486
|
+
"on-surface": onSurface,
|
|
487
|
+
"surface-variant": surfaceVariant,
|
|
488
|
+
"on-surface-variant": onSurfaceVariant,
|
|
489
|
+
"inverse-surface": inverseSurface,
|
|
490
|
+
"on-inverse-surface": onInverse,
|
|
491
|
+
"on-inverse-surface-primary": inversePrimary,
|
|
492
|
+
"on-inverse-surface-variant": inversePrimary,
|
|
493
|
+
"inverse-container": inverseSurface,
|
|
494
|
+
"on-inverse-container": onInverse,
|
|
495
|
+
outline,
|
|
496
|
+
shadow: "#000000",
|
|
497
|
+
scrim: "#000000",
|
|
498
|
+
"surface-tint": primaryBase,
|
|
499
|
+
transparent: "rgba(0,0,0,0)",
|
|
500
|
+
ghost: "rgba(0,0,0,0)",
|
|
501
|
+
disabled,
|
|
502
|
+
"on-disabled": onDisabled,
|
|
503
|
+
"disabled-container": tone(hues.primary, surfaceC, t.disabledContainer),
|
|
504
|
+
"on-disabled-container": onDisabled,
|
|
505
|
+
"disabled-surface": disabled,
|
|
506
|
+
"on-disabled-surface": dark ? "rgba(255,255,255,0.5)" : "rgba(0,0,0,0.5)",
|
|
507
|
+
"on-disabled-surface-variant": dark ? "rgba(255,255,255,0.4)" : "rgba(0,0,0,0.4)"
|
|
508
|
+
};
|
|
509
|
+
};
|
|
510
|
+
/**
|
|
511
|
+
* Generate a complete {@link Colors} token set from a single seed color, a
|
|
512
|
+
* {@link ColorScheme} and a {@link ColorCategory}. Produces a light or dark
|
|
513
|
+
* variant of the same palette; `on-*` colors are driven to WCAG AA contrast
|
|
514
|
+
* so text stays legible for any seed.
|
|
515
|
+
*
|
|
516
|
+
* Delegates to the OKLCH engine in `concepts/generation` — all lightness and
|
|
517
|
+
* chroma math is perceptual, and every derived pair passes through the WCAG
|
|
518
|
+
* guard-rail. Accepts the engine's extended config, so callers may also pass
|
|
519
|
+
* soft `targets` (brand-faithful but guard-railed) and a `checks` sink. Use
|
|
520
|
+
* `generateThemes()` for the light+dark pair plus a {@link ContrastReport}.
|
|
521
|
+
*/
|
|
522
|
+
var generatePalette = (config) => generateColors(config);
|
|
523
|
+
var BaseTypography = {
|
|
524
|
+
"display-large": {
|
|
525
|
+
fontFamily: "Red Hat Display",
|
|
526
|
+
fontSize: 57,
|
|
527
|
+
lineHeight: 64,
|
|
528
|
+
fontWeight: "normal",
|
|
529
|
+
letterSpacing: -.25
|
|
530
|
+
},
|
|
531
|
+
"display-medium": {
|
|
532
|
+
fontFamily: "Red Hat Display",
|
|
533
|
+
fontSize: 45,
|
|
534
|
+
lineHeight: 52,
|
|
535
|
+
fontWeight: "normal"
|
|
536
|
+
},
|
|
537
|
+
"display-small": {
|
|
538
|
+
fontFamily: "Red Hat Display",
|
|
539
|
+
fontSize: 36,
|
|
540
|
+
lineHeight: 44,
|
|
541
|
+
fontWeight: "normal"
|
|
542
|
+
},
|
|
543
|
+
"headline-large": {
|
|
544
|
+
fontFamily: "Red Hat Display",
|
|
545
|
+
fontSize: 32,
|
|
546
|
+
lineHeight: 40,
|
|
547
|
+
fontWeight: "normal"
|
|
548
|
+
},
|
|
549
|
+
"headline-medium": {
|
|
550
|
+
fontFamily: "Red Hat Display",
|
|
551
|
+
fontSize: 28,
|
|
552
|
+
lineHeight: 36,
|
|
553
|
+
fontWeight: "normal"
|
|
554
|
+
},
|
|
555
|
+
"headline-small": {
|
|
556
|
+
fontFamily: "Red Hat Display",
|
|
557
|
+
fontSize: 24,
|
|
558
|
+
lineHeight: 32,
|
|
559
|
+
fontWeight: "normal"
|
|
560
|
+
},
|
|
561
|
+
"title-large": {
|
|
562
|
+
fontFamily: "Red Hat Display",
|
|
563
|
+
fontSize: 22,
|
|
564
|
+
lineHeight: 28,
|
|
565
|
+
fontWeight: "normal"
|
|
566
|
+
},
|
|
567
|
+
"title-medium": {
|
|
568
|
+
fontFamily: "Red Hat Display",
|
|
569
|
+
fontSize: 16,
|
|
570
|
+
lineHeight: 24,
|
|
571
|
+
fontWeight: "medium",
|
|
572
|
+
letterSpacing: .15
|
|
573
|
+
},
|
|
574
|
+
"title-small": {
|
|
575
|
+
fontFamily: "Red Hat Display",
|
|
576
|
+
fontWeight: "medium",
|
|
577
|
+
fontSize: 14,
|
|
578
|
+
lineHeight: 20,
|
|
579
|
+
letterSpacing: .1
|
|
580
|
+
},
|
|
581
|
+
"body-1-long": {
|
|
582
|
+
fontFamily: "Roboto",
|
|
583
|
+
fontSize: 16,
|
|
584
|
+
lineHeight: 22
|
|
585
|
+
},
|
|
586
|
+
"body-1-short": {
|
|
587
|
+
fontFamily: "Roboto",
|
|
588
|
+
fontSize: 16,
|
|
589
|
+
lineHeight: 24
|
|
590
|
+
},
|
|
591
|
+
"body-2-long": {
|
|
592
|
+
fontFamily: "Roboto",
|
|
593
|
+
fontSize: 14,
|
|
594
|
+
lineHeight: 18
|
|
595
|
+
},
|
|
596
|
+
"body-2-short": {
|
|
597
|
+
fontFamily: "Roboto",
|
|
598
|
+
fontSize: 14,
|
|
599
|
+
lineHeight: 20
|
|
600
|
+
},
|
|
601
|
+
"subtitle-1": {
|
|
602
|
+
fontFamily: "Red Hat Display",
|
|
603
|
+
fontSize: 16,
|
|
604
|
+
lineHeight: 24,
|
|
605
|
+
letterSpacing: .15
|
|
606
|
+
},
|
|
607
|
+
"subtitle-2": {
|
|
608
|
+
fontFamily: "Red Hat Display",
|
|
609
|
+
fontSize: 14,
|
|
610
|
+
lineHeight: 20,
|
|
611
|
+
fontWeight: "medium",
|
|
612
|
+
letterSpacing: .1
|
|
613
|
+
},
|
|
614
|
+
label: {
|
|
615
|
+
fontFamily: "Roboto",
|
|
616
|
+
fontSize: 14,
|
|
617
|
+
lineHeight: 20
|
|
618
|
+
},
|
|
619
|
+
button: {
|
|
620
|
+
fontFamily: "Red Hat Display",
|
|
621
|
+
fontSize: 14,
|
|
622
|
+
lineHeight: 20,
|
|
623
|
+
fontWeight: "medium",
|
|
624
|
+
textTransform: "capitalize"
|
|
625
|
+
},
|
|
626
|
+
caption: {
|
|
627
|
+
fontFamily: "Roboto",
|
|
628
|
+
fontSize: 12,
|
|
629
|
+
lineHeight: 18,
|
|
630
|
+
letterSpacing: .4
|
|
631
|
+
},
|
|
632
|
+
overline: {
|
|
633
|
+
fontFamily: "Red Hat Display",
|
|
634
|
+
fontSize: 10,
|
|
635
|
+
lineHeight: 18,
|
|
636
|
+
letterSpacing: 1.5,
|
|
637
|
+
textTransform: "uppercase"
|
|
638
|
+
},
|
|
639
|
+
paragraph: {
|
|
640
|
+
fontFamily: "Roboto",
|
|
641
|
+
fontSize: 16,
|
|
642
|
+
lineHeight: 24
|
|
643
|
+
},
|
|
644
|
+
quote: {
|
|
645
|
+
fontFamily: "Roboto",
|
|
646
|
+
fontSize: 16,
|
|
647
|
+
lineHeight: 24
|
|
648
|
+
},
|
|
649
|
+
note: {
|
|
650
|
+
fontFamily: "Roboto",
|
|
651
|
+
fontSize: 14,
|
|
652
|
+
lineHeight: 22,
|
|
653
|
+
fontStyle: "italic"
|
|
654
|
+
},
|
|
655
|
+
badge: {
|
|
656
|
+
fontFamily: "Red Hat Display",
|
|
657
|
+
fontSize: 16,
|
|
658
|
+
lineHeight: 24
|
|
659
|
+
},
|
|
660
|
+
tag: {
|
|
661
|
+
fontFamily: "Red Hat Display",
|
|
662
|
+
fontSize: 15,
|
|
663
|
+
lineHeight: 20,
|
|
664
|
+
fontWeight: 600
|
|
665
|
+
},
|
|
666
|
+
input: {
|
|
667
|
+
fontFamily: "Red Hat Display",
|
|
668
|
+
fontSize: 14,
|
|
669
|
+
lineHeight: 24
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
var BaseShadows = {
|
|
673
|
+
raised: "rgba(0, 0, 0, 0.2) 0px 2px 1px -1px, rgba(0, 0, 0, 0.14) 0px 1px 1px 0px, rgba(0, 0, 0, 0.12) 0px 1px 3px 0px",
|
|
674
|
+
menu: "rgba(0, 0, 0, 0.2) 0px 3px 3px -2px, rgba(0, 0, 0, 0.14) 0px 3px 4px 0px, rgba(0, 0, 0, 0.12) 0px 1px 8px 0px;",
|
|
675
|
+
dialog: "rgba(0, 0, 0, 0.2) 0px 3px 5px -1px, rgba(0, 0, 0, 0.14) 0px 6px 10px 0px, rgba(0, 0, 0, 0.12) 0px 1px 18px 0px",
|
|
676
|
+
warn: "0 0 5px rgba(255, 0, 0, 0.5), inset 0 0 5px rgba(255, 0, 0, 0.3)"
|
|
677
|
+
};
|
|
678
|
+
var BaseSpacing = {
|
|
679
|
+
none: "none",
|
|
680
|
+
xxs: "2px",
|
|
681
|
+
xs: "4px",
|
|
682
|
+
sm: "8px",
|
|
683
|
+
md: "16px",
|
|
684
|
+
lg: "32px",
|
|
685
|
+
xl: "64px"
|
|
686
|
+
};
|
|
687
|
+
var BaseThicknesses = {
|
|
688
|
+
thin: 1,
|
|
689
|
+
standard: 2,
|
|
690
|
+
thick: 4
|
|
691
|
+
};
|
|
692
|
+
var BaseRadii = {
|
|
693
|
+
none: "none",
|
|
694
|
+
xxs: "4px",
|
|
695
|
+
xs: "8px",
|
|
696
|
+
sm: "16px",
|
|
697
|
+
md: "24px",
|
|
698
|
+
lg: "32px",
|
|
699
|
+
max: "999px"
|
|
700
|
+
};
|
|
701
|
+
var buildBorders = (c) => ({
|
|
702
|
+
primary: `1px solid ${c.primary}`,
|
|
703
|
+
secondary: `1px solid ${c.secondary}`,
|
|
704
|
+
tertiary: `1px solid ${c.tertiary}`,
|
|
705
|
+
quaternary: `1px solid ${c.quaternary}`,
|
|
706
|
+
warn: `1px solid ${c.warn}`,
|
|
707
|
+
success: `1px solid ${c.success}`,
|
|
708
|
+
light: `1px solid ${c.outline}`,
|
|
709
|
+
dark: `1px solid ${c["on-background"]}`,
|
|
710
|
+
dotted: `1px dotted ${c["on-background"]}`
|
|
711
|
+
});
|
|
712
|
+
var buildComponents = (c) => ({
|
|
713
|
+
alert: { options: {
|
|
714
|
+
topPosition: 40,
|
|
715
|
+
borderRadius: "sm",
|
|
716
|
+
transitionSpeed: .35,
|
|
717
|
+
elevation: "md"
|
|
718
|
+
} },
|
|
719
|
+
checkbox: { options: { size: 20 } },
|
|
720
|
+
dialog: { options: {
|
|
721
|
+
borderRadius: "lg",
|
|
722
|
+
color: "primary-surface",
|
|
723
|
+
border: "quaternary",
|
|
724
|
+
padding: "sm",
|
|
725
|
+
elevation: "dialog",
|
|
726
|
+
backdrop: {
|
|
727
|
+
background: "rgba(255, 255, 255, 0.6)",
|
|
728
|
+
backdropFilter: "blur(2px)"
|
|
729
|
+
}
|
|
730
|
+
} },
|
|
731
|
+
dialogHeader: { options: {
|
|
732
|
+
borderRadius: "max",
|
|
733
|
+
color: "primary",
|
|
734
|
+
height: 48,
|
|
735
|
+
textRole: "title-large",
|
|
736
|
+
textAlign: "center",
|
|
737
|
+
closeButtonIcon: "close",
|
|
738
|
+
closeButtonSize: "md"
|
|
739
|
+
} },
|
|
740
|
+
dropdown: { options: {
|
|
741
|
+
border: "none",
|
|
742
|
+
borderRadius: "xxs",
|
|
743
|
+
color: "primary-surface",
|
|
744
|
+
shadow: "menu"
|
|
745
|
+
} },
|
|
746
|
+
footer: { options: {
|
|
747
|
+
height: 52,
|
|
748
|
+
color: "primary",
|
|
749
|
+
logoHeight: 18.6,
|
|
750
|
+
logoPadding: "md"
|
|
751
|
+
} },
|
|
752
|
+
input: { options: {
|
|
753
|
+
typeFace: "input",
|
|
754
|
+
color: "primary-surface",
|
|
755
|
+
textColor: "on-primary-surface",
|
|
756
|
+
disabledColor: "disabled-surface",
|
|
757
|
+
disabledTextColor: "on-disabled-surface",
|
|
758
|
+
border: "light",
|
|
759
|
+
borderRadius: "xs",
|
|
760
|
+
errorShadow: "warn",
|
|
761
|
+
errorBorder: "warn",
|
|
762
|
+
height: 32,
|
|
763
|
+
paddingLeft: "sm",
|
|
764
|
+
focusOutline: `2px solid ${c.primary}`,
|
|
765
|
+
focusOutlineOffset: 2
|
|
766
|
+
} },
|
|
767
|
+
multiSelectDropdown: { options: {
|
|
768
|
+
textRole: "input",
|
|
769
|
+
textColor: "on-primary-surface",
|
|
770
|
+
dividerBorder: "light",
|
|
771
|
+
searchInputBorder: "light",
|
|
772
|
+
searchInputBorderRadius: "xxs",
|
|
773
|
+
focusOutline: `2px solid ${c.primary}`,
|
|
774
|
+
focusOutlineOffset: 2
|
|
775
|
+
} },
|
|
776
|
+
badge: { options: { borderRadius: "xxs" } },
|
|
777
|
+
button: {
|
|
778
|
+
fixed: {
|
|
779
|
+
position: "relative",
|
|
780
|
+
overflow: "hidden",
|
|
781
|
+
outline: "0",
|
|
782
|
+
border: "0",
|
|
783
|
+
cursor: "pointer",
|
|
784
|
+
fontFamily: "Euphemia, sans-serif",
|
|
785
|
+
transition: "all 0.28s ease"
|
|
786
|
+
},
|
|
787
|
+
variants: {
|
|
788
|
+
ghost: {
|
|
789
|
+
backgroundColor: "transparent",
|
|
790
|
+
color: "currentcolor",
|
|
791
|
+
"&:hover": { backgroundColor: "rgba(0,0,0,0.06)" }
|
|
792
|
+
},
|
|
793
|
+
primary: {
|
|
794
|
+
backgroundColor: c.primary,
|
|
795
|
+
color: c["on-primary"],
|
|
796
|
+
border: "0",
|
|
797
|
+
"&:hover": { filter: "brightness(0.92)" }
|
|
798
|
+
},
|
|
799
|
+
secondary: {
|
|
800
|
+
backgroundColor: "transparent",
|
|
801
|
+
color: c.secondary,
|
|
802
|
+
border: `1px solid ${c.secondary}`,
|
|
803
|
+
"&:hover": {
|
|
804
|
+
backgroundColor: c.secondary,
|
|
805
|
+
color: c["on-secondary"]
|
|
806
|
+
}
|
|
807
|
+
},
|
|
808
|
+
tertiary: {
|
|
809
|
+
backgroundColor: c.tertiary,
|
|
810
|
+
color: c["on-tertiary"],
|
|
811
|
+
border: "0",
|
|
812
|
+
"&:hover": { filter: "brightness(0.92)" }
|
|
813
|
+
},
|
|
814
|
+
warn: {
|
|
815
|
+
backgroundColor: c.warn,
|
|
816
|
+
color: c["on-warn"],
|
|
817
|
+
border: "0",
|
|
818
|
+
"&:hover": { filter: "brightness(0.92)" }
|
|
819
|
+
},
|
|
820
|
+
success: {
|
|
821
|
+
backgroundColor: c.success,
|
|
822
|
+
color: c["on-success"],
|
|
823
|
+
border: "0",
|
|
824
|
+
"&:hover": { filter: "brightness(0.92)" }
|
|
825
|
+
},
|
|
826
|
+
disabled: {
|
|
827
|
+
backgroundColor: `${c.disabled} !important`,
|
|
828
|
+
color: `${c["on-disabled"]} !important`,
|
|
829
|
+
border: "0"
|
|
830
|
+
}
|
|
831
|
+
},
|
|
832
|
+
sizes: {
|
|
833
|
+
sm: {
|
|
834
|
+
height: 22,
|
|
835
|
+
borderRadius: 11,
|
|
836
|
+
fontSize: 12,
|
|
837
|
+
padding: "0 12px",
|
|
838
|
+
fontFamily: "Euphemia Bold, sans-serif",
|
|
839
|
+
fontWeight: 600
|
|
840
|
+
},
|
|
841
|
+
md: {
|
|
842
|
+
height: 26,
|
|
843
|
+
borderRadius: 13,
|
|
844
|
+
fontSize: 16,
|
|
845
|
+
padding: "0 16px"
|
|
846
|
+
},
|
|
847
|
+
lg: {
|
|
848
|
+
height: 36,
|
|
849
|
+
borderRadius: 18,
|
|
850
|
+
fontSize: 18,
|
|
851
|
+
padding: "0 18px"
|
|
852
|
+
},
|
|
853
|
+
xl: {
|
|
854
|
+
height: 48,
|
|
855
|
+
borderRadius: 24,
|
|
856
|
+
fontSize: 24,
|
|
857
|
+
padding: "0 22px"
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
},
|
|
861
|
+
iconButton: {
|
|
862
|
+
variants: {
|
|
863
|
+
ghost: {
|
|
864
|
+
backgroundColor: "transparent",
|
|
865
|
+
color: "currentcolor"
|
|
866
|
+
},
|
|
867
|
+
primary: {
|
|
868
|
+
backgroundColor: c.primary,
|
|
869
|
+
color: c["on-primary"]
|
|
870
|
+
},
|
|
871
|
+
secondary: {
|
|
872
|
+
backgroundColor: c.secondary,
|
|
873
|
+
color: c["on-secondary"]
|
|
874
|
+
},
|
|
875
|
+
tertiary: {
|
|
876
|
+
backgroundColor: c.tertiary,
|
|
877
|
+
color: c["on-tertiary"]
|
|
878
|
+
},
|
|
879
|
+
warn: {
|
|
880
|
+
backgroundColor: c.warn,
|
|
881
|
+
color: c["on-warn"]
|
|
882
|
+
},
|
|
883
|
+
success: {
|
|
884
|
+
backgroundColor: c.success,
|
|
885
|
+
color: c["on-success"]
|
|
886
|
+
},
|
|
887
|
+
disabled: {
|
|
888
|
+
backgroundColor: "transparent !important",
|
|
889
|
+
color: `${c["on-disabled"]} !important`
|
|
890
|
+
}
|
|
891
|
+
},
|
|
892
|
+
sizes: {
|
|
893
|
+
sm: {
|
|
894
|
+
height: 22,
|
|
895
|
+
minHeight: 22,
|
|
896
|
+
width: 22,
|
|
897
|
+
minWidth: 22,
|
|
898
|
+
fontSize: 18
|
|
899
|
+
},
|
|
900
|
+
md: {
|
|
901
|
+
height: 26,
|
|
902
|
+
minHeight: 26,
|
|
903
|
+
width: 26,
|
|
904
|
+
minWidth: 26,
|
|
905
|
+
fontSize: 22
|
|
906
|
+
},
|
|
907
|
+
lg: {
|
|
908
|
+
height: 36,
|
|
909
|
+
minHeight: 36,
|
|
910
|
+
width: 36,
|
|
911
|
+
minWidth: 36,
|
|
912
|
+
fontSize: 30
|
|
913
|
+
},
|
|
914
|
+
xl: {
|
|
915
|
+
height: 40,
|
|
916
|
+
minHeight: 40,
|
|
917
|
+
width: 40,
|
|
918
|
+
minWidth: 40,
|
|
919
|
+
fontSize: 34
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
},
|
|
923
|
+
progressGauge: {
|
|
924
|
+
fixed: { textFill: c["on-background"] },
|
|
925
|
+
variants: {
|
|
926
|
+
primary: {
|
|
927
|
+
backgroundColor: "#b3d4ea",
|
|
928
|
+
color: c.primary
|
|
929
|
+
},
|
|
930
|
+
secondary: {
|
|
931
|
+
backgroundColor: "#b3e7c2",
|
|
932
|
+
color: c.secondary
|
|
933
|
+
},
|
|
934
|
+
tertiary: {
|
|
935
|
+
backgroundColor: "#ffe2b3",
|
|
936
|
+
color: c.tertiary
|
|
937
|
+
},
|
|
938
|
+
warn: {
|
|
939
|
+
backgroundColor: "#ffc2b3",
|
|
940
|
+
color: c.warn
|
|
941
|
+
},
|
|
942
|
+
success: {
|
|
943
|
+
backgroundColor: "#b3e7c2",
|
|
944
|
+
color: c.success
|
|
945
|
+
}
|
|
946
|
+
},
|
|
947
|
+
sizes: {
|
|
948
|
+
sm: { height: "54px" },
|
|
949
|
+
md: { height: "68px" },
|
|
950
|
+
lg: { height: "82px" },
|
|
951
|
+
xl: { height: "104px" }
|
|
952
|
+
}
|
|
953
|
+
},
|
|
954
|
+
card: {
|
|
955
|
+
fixed: {
|
|
956
|
+
borderStyle: "solid",
|
|
957
|
+
borderWidth: "1px",
|
|
958
|
+
borderRadius: "8px",
|
|
959
|
+
overflow: "hidden"
|
|
960
|
+
},
|
|
961
|
+
variants: {
|
|
962
|
+
primary: {
|
|
963
|
+
borderColor: c.primary,
|
|
964
|
+
backgroundColor: c.background
|
|
965
|
+
},
|
|
966
|
+
secondary: {
|
|
967
|
+
borderColor: c.secondary,
|
|
968
|
+
backgroundColor: c.background
|
|
969
|
+
},
|
|
970
|
+
tertiary: {
|
|
971
|
+
borderColor: c.tertiary,
|
|
972
|
+
backgroundColor: c.background
|
|
973
|
+
},
|
|
974
|
+
warn: {
|
|
975
|
+
borderColor: c.warn,
|
|
976
|
+
backgroundColor: c.background
|
|
977
|
+
},
|
|
978
|
+
success: {
|
|
979
|
+
borderColor: c.success,
|
|
980
|
+
backgroundColor: c.background
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
},
|
|
984
|
+
cardHeader: {
|
|
985
|
+
fixed: { padding: "12px 24px" },
|
|
986
|
+
variants: {
|
|
987
|
+
primary: {
|
|
988
|
+
backgroundColor: c.primary,
|
|
989
|
+
color: c["on-primary"]
|
|
990
|
+
},
|
|
991
|
+
secondary: {
|
|
992
|
+
backgroundColor: c.secondary,
|
|
993
|
+
color: c["on-secondary"]
|
|
994
|
+
},
|
|
995
|
+
tertiary: {
|
|
996
|
+
backgroundColor: c.tertiary,
|
|
997
|
+
color: c["on-tertiary"]
|
|
998
|
+
},
|
|
999
|
+
warn: {
|
|
1000
|
+
backgroundColor: c.warn,
|
|
1001
|
+
color: c["on-warn"]
|
|
1002
|
+
},
|
|
1003
|
+
success: {
|
|
1004
|
+
backgroundColor: c.success,
|
|
1005
|
+
color: c["on-success"]
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
},
|
|
1009
|
+
cardContent: { fixed: { padding: "12px 24px" } },
|
|
1010
|
+
dataSearch: { options: {
|
|
1011
|
+
border: "light",
|
|
1012
|
+
borderRadius: "xs",
|
|
1013
|
+
color: "primary-surface",
|
|
1014
|
+
placeholderColor: "disabled"
|
|
1015
|
+
} },
|
|
1016
|
+
dataTable: { options: {
|
|
1017
|
+
color: "primary-surface",
|
|
1018
|
+
border: "light",
|
|
1019
|
+
borderRadius: "sm",
|
|
1020
|
+
elevation: void 0,
|
|
1021
|
+
headerPadding: "sm",
|
|
1022
|
+
footerPadding: "sm",
|
|
1023
|
+
thTextRole: "headline-small",
|
|
1024
|
+
thColor: "primary-container",
|
|
1025
|
+
thVerticalBorder: "dotted",
|
|
1026
|
+
thHorizontalBorder: "light",
|
|
1027
|
+
thPadding: "sm",
|
|
1028
|
+
tdTextRole: "title-small",
|
|
1029
|
+
tdColor: "primary-surface",
|
|
1030
|
+
tdStickyColor: "primary-container",
|
|
1031
|
+
tdPadding: "sm",
|
|
1032
|
+
tdVerticalBorder: "dotted",
|
|
1033
|
+
tdHorizontalBorder: "light",
|
|
1034
|
+
rowHoverColor: "primary-container",
|
|
1035
|
+
loadingOverlayColor: "scrim",
|
|
1036
|
+
loadingSpinnerColor: "primary",
|
|
1037
|
+
loadingSpinnerSize: 40
|
|
1038
|
+
} },
|
|
1039
|
+
notificationBadge: { options: {
|
|
1040
|
+
borderRadius: "sm",
|
|
1041
|
+
offset: -10
|
|
1042
|
+
} },
|
|
1043
|
+
paginator: { options: {
|
|
1044
|
+
gap: "xs",
|
|
1045
|
+
textRole: "label",
|
|
1046
|
+
inputBorder: "light",
|
|
1047
|
+
inputBorderRadius: "xs",
|
|
1048
|
+
pageBorderRadius: "xs",
|
|
1049
|
+
currentPageBorder: "light",
|
|
1050
|
+
currentPageBorderRadius: "xs"
|
|
1051
|
+
} },
|
|
1052
|
+
snackbar: { options: {
|
|
1053
|
+
bottomPosition: 40,
|
|
1054
|
+
transitionDelay: "0.35s",
|
|
1055
|
+
autoCloseDelay: 35e3
|
|
1056
|
+
} },
|
|
1057
|
+
symbol: { options: {
|
|
1058
|
+
fill: 0,
|
|
1059
|
+
weight: 400,
|
|
1060
|
+
grade: 0,
|
|
1061
|
+
opticalSize: 24
|
|
1062
|
+
} },
|
|
1063
|
+
toggle: { options: { size: 20 } },
|
|
1064
|
+
tooltip: { options: {
|
|
1065
|
+
border: void 0,
|
|
1066
|
+
borderRadius: "xs",
|
|
1067
|
+
shadow: "raised",
|
|
1068
|
+
color: "inverse-surface",
|
|
1069
|
+
typeface: "label"
|
|
1070
|
+
} }
|
|
1071
|
+
});
|
|
1072
|
+
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1073
|
+
var deepMerge = (base, override) => {
|
|
1074
|
+
if (!override) return base;
|
|
1075
|
+
const out = { ...base };
|
|
1076
|
+
for (const [key, value] of Object.entries(override)) out[key] = isRecord(value) && isRecord(out[key]) ? deepMerge(out[key], value) : value;
|
|
1077
|
+
return out;
|
|
1078
|
+
};
|
|
1079
|
+
var createTheme = ({ id, name, colors, icons = {}, radii = BaseRadii, shadows = BaseShadows, borders, components }) => ({
|
|
1080
|
+
id,
|
|
1081
|
+
name,
|
|
1082
|
+
colors,
|
|
1083
|
+
typography: BaseTypography,
|
|
1084
|
+
borders: deepMerge(buildBorders(colors), borders),
|
|
1085
|
+
radii,
|
|
1086
|
+
shadows,
|
|
1087
|
+
spacing: BaseSpacing,
|
|
1088
|
+
thicknesses: BaseThicknesses,
|
|
1089
|
+
icons,
|
|
1090
|
+
components: deepMerge(buildComponents(colors), components)
|
|
1091
|
+
});
|
|
1092
|
+
/**
|
|
1093
|
+
* Seed for the shipped Light/Dark themes. Swap these three values (or call
|
|
1094
|
+
* `generatePalette` with your own) to reskin the entire system — every color
|
|
1095
|
+
* token is derived, so there is nothing else to hand-author.
|
|
1096
|
+
*/
|
|
1097
|
+
var BASE_PALETTE_CONFIG = {
|
|
1098
|
+
seed: "#4F46E5",
|
|
1099
|
+
scheme: "triadic",
|
|
1100
|
+
category: "neutral"
|
|
1101
|
+
};
|
|
1102
|
+
var lightColors = generatePalette({
|
|
1103
|
+
...BASE_PALETTE_CONFIG,
|
|
1104
|
+
mode: "light"
|
|
1105
|
+
});
|
|
1106
|
+
createTheme({
|
|
1107
|
+
id: "BaseTheme",
|
|
1108
|
+
name: "Base Theme",
|
|
1109
|
+
colors: lightColors
|
|
1110
|
+
});
|
|
1111
|
+
/** Radii presets per shape language (PRD §3.5.A). Same keys as `BaseRadii`. */
|
|
1112
|
+
var ShapeRadii = {
|
|
1113
|
+
sharp: {
|
|
1114
|
+
none: "none",
|
|
1115
|
+
xxs: "0px",
|
|
1116
|
+
xs: "0px",
|
|
1117
|
+
sm: "0px",
|
|
1118
|
+
md: "0px",
|
|
1119
|
+
lg: "0px",
|
|
1120
|
+
max: "0px"
|
|
1121
|
+
},
|
|
1122
|
+
modern: {
|
|
1123
|
+
none: "none",
|
|
1124
|
+
xxs: "4px",
|
|
1125
|
+
xs: "8px",
|
|
1126
|
+
sm: "16px",
|
|
1127
|
+
md: "24px",
|
|
1128
|
+
lg: "32px",
|
|
1129
|
+
max: "999px"
|
|
1130
|
+
},
|
|
1131
|
+
playful: {
|
|
1132
|
+
none: "none",
|
|
1133
|
+
xxs: "8px",
|
|
1134
|
+
xs: "16px",
|
|
1135
|
+
sm: "24px",
|
|
1136
|
+
md: "32px",
|
|
1137
|
+
lg: "48px",
|
|
1138
|
+
max: "9999px"
|
|
1139
|
+
}
|
|
1140
|
+
};
|
|
1141
|
+
/** Shortest angular distance between two hue angles, in degrees (0–180). */
|
|
1142
|
+
var hueDistance = (a, b) => {
|
|
1143
|
+
const d = Math.abs(a - b) % 360;
|
|
1144
|
+
return d > 180 ? 360 - d : d;
|
|
1145
|
+
};
|
|
1146
|
+
/**
|
|
1147
|
+
* Classify 2–3 brand hues against {@link ColorScheme} by their angular
|
|
1148
|
+
* distances from the primary hue. Heuristic bands, widest match wins.
|
|
1149
|
+
*/
|
|
1150
|
+
var classifyScheme = (primaryHue, otherHues) => {
|
|
1151
|
+
const distances = otherHues.map((h) => hueDistance(primaryHue, h));
|
|
1152
|
+
if (distances.length === 0) return "analogous";
|
|
1153
|
+
if (distances.every((d) => d < 15)) return "monochromatic";
|
|
1154
|
+
if (distances.every((d) => d <= 65)) return "analogous";
|
|
1155
|
+
if (distances.some((d) => d >= 165)) return "complimentary";
|
|
1156
|
+
if (distances.length > 1 && distances.every((d) => d >= 130)) return "splitComplimentary";
|
|
1157
|
+
return "triadic";
|
|
1158
|
+
};
|
|
1159
|
+
/**
|
|
1160
|
+
* Infer a tonal category from the seed's own chroma, so an unstated "vibe"
|
|
1161
|
+
* preserves the brand's character — vivid stays vivid, muted stays muted.
|
|
1162
|
+
*/
|
|
1163
|
+
var inferCategory = (seedHex) => {
|
|
1164
|
+
const { c } = hexToOklch(seedHex);
|
|
1165
|
+
if (c >= .13) return "jewel";
|
|
1166
|
+
if (c >= .07) return "earth";
|
|
1167
|
+
if (c >= .03) return "pastel";
|
|
1168
|
+
return "neutral";
|
|
1169
|
+
};
|
|
1170
|
+
/**
|
|
1171
|
+
* The theme generation engine (PRD §3.3): brand seed(s) in, complete WCAG-AA
|
|
1172
|
+
* light+dark {@link Colors} pair out, with a machine-readable contrast report.
|
|
1173
|
+
* Pure and deterministic — identical input yields identical output.
|
|
1174
|
+
*/
|
|
1175
|
+
var generateThemes = (input) => {
|
|
1176
|
+
const seeds = (Array.isArray(input.seed) ? input.seed : [input.seed]).slice(0, 3);
|
|
1177
|
+
const [primary, secondary, tertiary] = seeds;
|
|
1178
|
+
const scheme = input.scheme ?? (seeds.length > 1 ? classifyScheme(hexToOklch(primary).h, seeds.slice(1).map((s) => hexToOklch(s).h)) : "analogous");
|
|
1179
|
+
const category = input.vibe ?? inferCategory(primary);
|
|
1180
|
+
const applyVibe = (hex) => {
|
|
1181
|
+
if (!input.vibe) return hex;
|
|
1182
|
+
const color = hexToOklch(hex);
|
|
1183
|
+
return oklchToHex({
|
|
1184
|
+
...color,
|
|
1185
|
+
c: Math.min(color.c, CategoryChroma[input.vibe])
|
|
1186
|
+
});
|
|
1187
|
+
};
|
|
1188
|
+
const targets = { primary: applyVibe(primary) };
|
|
1189
|
+
if (secondary) targets.secondary = applyVibe(secondary);
|
|
1190
|
+
if (tertiary) targets.tertiary = applyVibe(tertiary);
|
|
1191
|
+
const checks = [];
|
|
1192
|
+
const base = {
|
|
1193
|
+
seed: primary,
|
|
1194
|
+
scheme,
|
|
1195
|
+
category,
|
|
1196
|
+
targets,
|
|
1197
|
+
checks
|
|
1198
|
+
};
|
|
1199
|
+
const lightColors = generateColors({
|
|
1200
|
+
...base,
|
|
1201
|
+
mode: "light"
|
|
1202
|
+
});
|
|
1203
|
+
const darkColors = generateColors({
|
|
1204
|
+
...base,
|
|
1205
|
+
mode: "dark"
|
|
1206
|
+
});
|
|
1207
|
+
const worstRatio = checks.reduce((worst, check) => Math.min(worst, check.ratio), 21);
|
|
1208
|
+
return {
|
|
1209
|
+
lightColors,
|
|
1210
|
+
darkColors,
|
|
1211
|
+
radii: input.shape ? ShapeRadii[input.shape] : void 0,
|
|
1212
|
+
report: {
|
|
1213
|
+
checks,
|
|
1214
|
+
worstRatio,
|
|
1215
|
+
pass: checks.every((check) => check.pass)
|
|
1216
|
+
}
|
|
1217
|
+
};
|
|
1218
|
+
};
|
|
1219
|
+
var IDENT = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
1220
|
+
var asKey = (k) => IDENT.test(k) ? k : `'${k}'`;
|
|
1221
|
+
var recordLiteral = (record, indent) => Object.entries(record).map(([k, v]) => `${indent}${asKey(k)}: '${v}',`).join("\n");
|
|
1222
|
+
var bordersLiteral = () => [
|
|
1223
|
+
"/**",
|
|
1224
|
+
" * Named border primitives. These mirror the derived defaults — edit them, or",
|
|
1225
|
+
" * add your own under any token name and point component options (or the",
|
|
1226
|
+
" * `components` overrides below) at it. Every component deriving from a",
|
|
1227
|
+
" * shared token picks up the change.",
|
|
1228
|
+
" */",
|
|
1229
|
+
"const borders = (colors: Colors): Borders => ({",
|
|
1230
|
+
" primary: `1px solid ${colors.primary}`,",
|
|
1231
|
+
" secondary: `1px solid ${colors.secondary}`,",
|
|
1232
|
+
" tertiary: `1px solid ${colors.tertiary}`,",
|
|
1233
|
+
" quaternary: `1px solid ${colors.quaternary}`,",
|
|
1234
|
+
" warn: `1px solid ${colors.warn}`,",
|
|
1235
|
+
" success: `1px solid ${colors.success}`,",
|
|
1236
|
+
" light: `1px solid ${colors.outline}`,",
|
|
1237
|
+
" dark: `1px solid ${colors['on-background']}`,",
|
|
1238
|
+
" dotted: `1px dotted ${colors['on-background']}`,",
|
|
1239
|
+
"});"
|
|
1240
|
+
].join("\n");
|
|
1241
|
+
var themeExport = (exportName, displayName, colorsConst, radii) => [
|
|
1242
|
+
`export const ${exportName}: UniTheme = createTheme({`,
|
|
1243
|
+
` id: '${exportName}',`,
|
|
1244
|
+
` name: '${displayName}',`,
|
|
1245
|
+
` colors: ${colorsConst},`,
|
|
1246
|
+
` borders: borders(${colorsConst}),`,
|
|
1247
|
+
` components: components(${colorsConst}),`,
|
|
1248
|
+
...radii ? [" radii,"] : [],
|
|
1249
|
+
"});"
|
|
1250
|
+
].join("\n");
|
|
1251
|
+
/**
|
|
1252
|
+
* Render a static `uni-theme.ts` from a brand seed — the file the `ng add`
|
|
1253
|
+
* schematic writes and the MCP `generate_uni_theme` tool returns.
|
|
1254
|
+
*
|
|
1255
|
+
* The file is the system's **source of truth**: literal colors, the border
|
|
1256
|
+
* primitives spelled out, and a sparse `components` override section — so a
|
|
1257
|
+
* human (or an AI agent) can retheme by editing tokens in place, with no
|
|
1258
|
+
* runtime generation. Deterministic: same input, same file.
|
|
1259
|
+
*/
|
|
1260
|
+
var emitThemeFile = (input) => {
|
|
1261
|
+
const { darkMode = true, name = "Brand" } = input;
|
|
1262
|
+
const { lightColors, darkColors, radii, report } = generateThemes(input);
|
|
1263
|
+
const id = name.replace(/\W+/g, "") || "Brand";
|
|
1264
|
+
const regenerate = [
|
|
1265
|
+
`--brand=${(Array.isArray(input.seed) ? input.seed : [input.seed]).join(",")}`,
|
|
1266
|
+
input.vibe && `--vibe=${input.vibe}`,
|
|
1267
|
+
input.scheme && `--scheme=${input.scheme}`,
|
|
1268
|
+
input.shape && `--shape=${input.shape}`,
|
|
1269
|
+
!darkMode && "--dark-mode=false"
|
|
1270
|
+
].filter(Boolean).join(" ");
|
|
1271
|
+
const reportSummary = `${report.checks.length} contrast pairs checked · worst ${report.worstRatio}:1 · ${report.pass ? "all AA" : `${report.checks.filter((c) => !c.pass).length} failing`}`;
|
|
1272
|
+
const modes = [{
|
|
1273
|
+
exportName: `${id}Light`,
|
|
1274
|
+
displayName: `${name} Light`,
|
|
1275
|
+
colorsConst: "lightColors",
|
|
1276
|
+
colors: lightColors
|
|
1277
|
+
}, ...darkMode ? [{
|
|
1278
|
+
exportName: `${id}Dark`,
|
|
1279
|
+
displayName: `${name} Dark`,
|
|
1280
|
+
colorsConst: "darkColors",
|
|
1281
|
+
colors: darkColors
|
|
1282
|
+
}] : []];
|
|
1283
|
+
return {
|
|
1284
|
+
content: [
|
|
1285
|
+
"/**",
|
|
1286
|
+
` * ${name} theme for Uni — generated data, yours to edit.`,
|
|
1287
|
+
" *",
|
|
1288
|
+
` * Regenerate colors: ng add @uni-design-system/uni-angular ${regenerate}`,
|
|
1289
|
+
" * (or the `generate-uni-theme` MCP tool). Edits are never overwritten silently —",
|
|
1290
|
+
" * regeneration rewrites this file, so commit before regenerating.",
|
|
1291
|
+
` * ${reportSummary}.`,
|
|
1292
|
+
" */",
|
|
1293
|
+
"import {",
|
|
1294
|
+
" createTheme,",
|
|
1295
|
+
" type Borders,",
|
|
1296
|
+
" type Colors,",
|
|
1297
|
+
" type ComponentThemes,",
|
|
1298
|
+
" type UniTheme,",
|
|
1299
|
+
"} from '@uni-design-system/uni-core';",
|
|
1300
|
+
"",
|
|
1301
|
+
...modes.map(({ colorsConst, colors }) => `const ${colorsConst}: Colors = {\n${recordLiteral(colors, " ")}\n};\n`),
|
|
1302
|
+
bordersLiteral(),
|
|
1303
|
+
"",
|
|
1304
|
+
"/**",
|
|
1305
|
+
" * Sparse component overrides, deep-merged over Uni component defaults: only",
|
|
1306
|
+
" * what you write here changes. Point components at your own primitives, e.g.:",
|
|
1307
|
+
" * button: { variants: { secondary: { border: `2px dashed ${colors.tertiary}` } } },",
|
|
1308
|
+
" * input: { options: { borderRadius: 'max' } },",
|
|
1309
|
+
" */",
|
|
1310
|
+
"const components = (colors: Colors): ComponentThemes => ({});",
|
|
1311
|
+
"",
|
|
1312
|
+
...radii ? [
|
|
1313
|
+
`/** Shape language: '${input.shape}'. */`,
|
|
1314
|
+
`const radii = {\n${recordLiteral(radii, " ")}\n};`,
|
|
1315
|
+
""
|
|
1316
|
+
] : [],
|
|
1317
|
+
...modes.map(({ exportName, displayName, colorsConst }) => `${themeExport(exportName, displayName, colorsConst, !!radii)}\n`),
|
|
1318
|
+
"/** First key wins as the default theme when registered via UNI_THEMES. */",
|
|
1319
|
+
`export const ${id}Themes = { ${modes.map((m) => m.exportName).join(", ")} };`,
|
|
1320
|
+
""
|
|
1321
|
+
].join("\n"),
|
|
1322
|
+
providerSnippet: [
|
|
1323
|
+
`import { UNI_THEMES } from '@uni-design-system/uni-angular';`,
|
|
1324
|
+
`import { ${id}Themes } from './uni-theme';`,
|
|
1325
|
+
"",
|
|
1326
|
+
"// app.config.ts → providers:",
|
|
1327
|
+
`{ provide: UNI_THEMES, useValue: ${id}Themes },`
|
|
1328
|
+
].join("\n"),
|
|
1329
|
+
report,
|
|
1330
|
+
reportSummary
|
|
1331
|
+
};
|
|
1332
|
+
};
|
|
1333
|
+
var GetBoxShadow = ({ offset, blur, opacity }) => {
|
|
1334
|
+
return `0 ${offset}px ${blur}px rgba(0,0,0,0.${opacity})`;
|
|
1335
|
+
};
|
|
1336
|
+
var GetBoxShadows = ({ umbra, penumbra }) => {
|
|
1337
|
+
return GetBoxShadow(umbra) + ", " + GetBoxShadow(penumbra);
|
|
1338
|
+
};
|
|
1339
|
+
var ShadowMap = {
|
|
1340
|
+
pressed: {
|
|
1341
|
+
umbra: {
|
|
1342
|
+
offset: 1,
|
|
1343
|
+
blur: 2,
|
|
1344
|
+
opacity: 24
|
|
1345
|
+
},
|
|
1346
|
+
penumbra: {
|
|
1347
|
+
offset: 1,
|
|
1348
|
+
blur: 3,
|
|
1349
|
+
opacity: 12
|
|
1350
|
+
}
|
|
1351
|
+
},
|
|
1352
|
+
raised: {
|
|
1353
|
+
umbra: {
|
|
1354
|
+
offset: 3,
|
|
1355
|
+
blur: 6,
|
|
1356
|
+
opacity: 23
|
|
1357
|
+
},
|
|
1358
|
+
penumbra: {
|
|
1359
|
+
offset: 3,
|
|
1360
|
+
blur: 6,
|
|
1361
|
+
opacity: 16
|
|
1362
|
+
}
|
|
1363
|
+
},
|
|
1364
|
+
focussed: {
|
|
1365
|
+
umbra: {
|
|
1366
|
+
offset: 6,
|
|
1367
|
+
blur: 6,
|
|
1368
|
+
opacity: 23
|
|
1369
|
+
},
|
|
1370
|
+
penumbra: {
|
|
1371
|
+
offset: 10,
|
|
1372
|
+
blur: 20,
|
|
1373
|
+
opacity: 19
|
|
1374
|
+
}
|
|
1375
|
+
},
|
|
1376
|
+
navigation: {
|
|
1377
|
+
umbra: {
|
|
1378
|
+
offset: 10,
|
|
1379
|
+
blur: 10,
|
|
1380
|
+
opacity: 22
|
|
1381
|
+
},
|
|
1382
|
+
penumbra: {
|
|
1383
|
+
offset: 14,
|
|
1384
|
+
blur: 28,
|
|
1385
|
+
opacity: 25
|
|
1386
|
+
}
|
|
1387
|
+
},
|
|
1388
|
+
modal: {
|
|
1389
|
+
umbra: {
|
|
1390
|
+
offset: 15,
|
|
1391
|
+
blur: 12,
|
|
1392
|
+
opacity: 22
|
|
1393
|
+
},
|
|
1394
|
+
penumbra: {
|
|
1395
|
+
offset: 19,
|
|
1396
|
+
blur: 38,
|
|
1397
|
+
opacity: 30
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
};
|
|
1401
|
+
GetBoxShadows(ShadowMap["pressed"]), GetBoxShadows(ShadowMap["raised"]), GetBoxShadows(ShadowMap["focussed"]), GetBoxShadows(ShadowMap["navigation"]), GetBoxShadows(ShadowMap["modal"]);
|
|
1402
|
+
var DarkTheme = createTheme({
|
|
1403
|
+
id: "DarkTheme",
|
|
1404
|
+
name: "Dark Theme",
|
|
1405
|
+
colors: generatePalette({
|
|
1406
|
+
...BASE_PALETTE_CONFIG,
|
|
1407
|
+
mode: "dark"
|
|
1408
|
+
})
|
|
1409
|
+
});
|
|
1410
|
+
var UniThemes = {
|
|
1411
|
+
LightTheme: createTheme({
|
|
1412
|
+
id: "LightTheme",
|
|
1413
|
+
name: "Light Theme",
|
|
1414
|
+
colors: lightColors
|
|
1415
|
+
}),
|
|
1416
|
+
DarkTheme
|
|
1417
|
+
};
|
|
1418
|
+
Object.keys(UniThemes)[0];
|
|
1419
|
+
//#endregion
|
|
1420
|
+
//#region package.json
|
|
1421
|
+
var version = "5.0.0";
|
|
1422
|
+
//#endregion
|
|
1423
|
+
//#region schematics-src/ng-add/transforms.ts
|
|
1424
|
+
var addDependencies = (packageJsonText, deps) => {
|
|
1425
|
+
const pkg = JSON.parse(packageJsonText);
|
|
1426
|
+
pkg.dependencies ??= {};
|
|
1427
|
+
for (const [name, version] of Object.entries(deps)) if (!pkg.dependencies[name] && !pkg.devDependencies?.[name]) pkg.dependencies[name] = version;
|
|
1428
|
+
const missingForms = !pkg.dependencies["@angular/forms"] && !pkg.devDependencies?.["@angular/forms"];
|
|
1429
|
+
return {
|
|
1430
|
+
text: `${JSON.stringify(pkg, null, 2)}\n`,
|
|
1431
|
+
missingForms
|
|
1432
|
+
};
|
|
1433
|
+
};
|
|
1434
|
+
var afterLastImport = (source, addition) => {
|
|
1435
|
+
const lastImport = [...source.matchAll(/^import .*?;$/gms)].pop();
|
|
1436
|
+
if (!lastImport || lastImport.index === void 0) return `${addition}\n${source}`;
|
|
1437
|
+
const at = lastImport.index + lastImport[0].length;
|
|
1438
|
+
return `${source.slice(0, at)}\n${addition}${source.slice(at)}`;
|
|
1439
|
+
};
|
|
1440
|
+
/** Register `UNI_THEMES` in an app.config.ts source. */
|
|
1441
|
+
var addProviderRegistration = (source, themesExport) => {
|
|
1442
|
+
if (source.includes("UNI_THEMES")) return source;
|
|
1443
|
+
const anchor = source.match(/providers:\s*\[/);
|
|
1444
|
+
if (!anchor || anchor.index === void 0) return null;
|
|
1445
|
+
const at = anchor.index + anchor[0].length;
|
|
1446
|
+
return afterLastImport(`${source.slice(0, at)}\n { provide: UNI_THEMES, useValue: ${themesExport} },${source.slice(at)}`, `import { UNI_THEMES } from '@uni-design-system/uni-angular';\nimport { ${themesExport} } from './uni-theme';`);
|
|
1447
|
+
};
|
|
1448
|
+
var FONT_LINKS = [
|
|
1449
|
+
" <link rel=\"preconnect\" href=\"https://fonts.googleapis.com\" />",
|
|
1450
|
+
" <link rel=\"preconnect\" href=\"https://fonts.gstatic.com\" crossorigin />",
|
|
1451
|
+
" <link href=\"https://fonts.googleapis.com/css2?family=Red+Hat+Display:wght@400;500;600;700&family=Roboto:wght@400;500&display=swap\" rel=\"stylesheet\" />",
|
|
1452
|
+
""
|
|
1453
|
+
].join("\n");
|
|
1454
|
+
/** Add Uni's typeface links (Red Hat Display + Roboto) to index.html. */
|
|
1455
|
+
var addFontLinks = (html) => {
|
|
1456
|
+
if (html.includes("family=Red+Hat+Display")) return html;
|
|
1457
|
+
const at = html.indexOf("</head>");
|
|
1458
|
+
if (at === -1) return null;
|
|
1459
|
+
return html.slice(0, at) + FONT_LINKS + html.slice(at);
|
|
1460
|
+
};
|
|
1461
|
+
var SMOKE_MARKUP = [
|
|
1462
|
+
"<!-- Uni smoke test: remove once the theme renders. -->",
|
|
1463
|
+
"<section style=\"display: flex; gap: 12px; align-items: center; padding: 16px;\">",
|
|
1464
|
+
" <uni-text typeface=\"headline-small\">Uni is wearing your brand</uni-text>",
|
|
1465
|
+
" <button uni-text-button variant=\"primary\" size=\"md\">Primary</button>",
|
|
1466
|
+
" <button uni-text-button variant=\"secondary\" size=\"md\">Secondary</button>",
|
|
1467
|
+
"</section>",
|
|
1468
|
+
"",
|
|
1469
|
+
""
|
|
1470
|
+
].join("\n");
|
|
1471
|
+
/** Prepend the smoke-test markup to the app component template. */
|
|
1472
|
+
var addSmokeMarkup = (html) => html.includes("Uni smoke test") ? html : SMOKE_MARKUP + html;
|
|
1473
|
+
/** Add Uni component classes to a standalone component's `imports: [...]`. */
|
|
1474
|
+
var addComponentImports = (source, symbols) => {
|
|
1475
|
+
const missing = symbols.filter((s) => !source.includes(s));
|
|
1476
|
+
if (missing.length === 0) return source;
|
|
1477
|
+
const anchor = source.match(/imports:\s*\[/);
|
|
1478
|
+
if (!anchor || anchor.index === void 0) return null;
|
|
1479
|
+
const at = anchor.index + anchor[0].length;
|
|
1480
|
+
return afterLastImport(`${source.slice(0, at)}${missing.join(", ")}, ${source.slice(at)}`, `import { ${missing.join(", ")} } from '@uni-design-system/uni-angular';`);
|
|
1481
|
+
};
|
|
1482
|
+
//#endregion
|
|
1483
|
+
//#region schematics-src/ng-add/index.ts
|
|
1484
|
+
var HEX = /^#?[0-9a-fA-F]{6}$/;
|
|
1485
|
+
var projectPaths = (tree, projectName) => {
|
|
1486
|
+
const fallback = {
|
|
1487
|
+
appDir: "src/app",
|
|
1488
|
+
indexHtml: "src/index.html"
|
|
1489
|
+
};
|
|
1490
|
+
const raw = tree.read("angular.json")?.toString();
|
|
1491
|
+
if (!raw) return fallback;
|
|
1492
|
+
try {
|
|
1493
|
+
const projects = JSON.parse(raw).projects ?? {};
|
|
1494
|
+
const name = projectName ?? Object.keys(projects).find((key) => projects[key].projectType !== "library") ?? Object.keys(projects)[0];
|
|
1495
|
+
const sourceRoot = name && projects[name]?.sourceRoot || "src";
|
|
1496
|
+
return {
|
|
1497
|
+
appDir: `${sourceRoot}/app`,
|
|
1498
|
+
indexHtml: `${sourceRoot}/index.html`
|
|
1499
|
+
};
|
|
1500
|
+
} catch {
|
|
1501
|
+
return fallback;
|
|
1502
|
+
}
|
|
1503
|
+
};
|
|
1504
|
+
var firstExisting = (tree, candidates) => candidates.find((path) => tree.exists(path));
|
|
1505
|
+
var write = (tree, path, content) => {
|
|
1506
|
+
if (tree.exists(path)) tree.overwrite(path, content);
|
|
1507
|
+
else tree.create(path, content);
|
|
1508
|
+
};
|
|
1509
|
+
function ngAdd(options) {
|
|
1510
|
+
return (tree, context) => {
|
|
1511
|
+
const seeds = (options.brand ?? "#4F46E5").split(",").map((s) => s.trim()).filter(Boolean).map((s) => s.startsWith("#") ? s : `#${s}`);
|
|
1512
|
+
const invalid = seeds.filter((s) => !HEX.test(s));
|
|
1513
|
+
if (seeds.length === 0 || invalid.length > 0) throw new _angular_devkit_schematics.SchematicsException(`Invalid --brand value${invalid.length ? ` (${invalid.join(", ")})` : ""}. Pass 1–3 six-digit hex colors, comma-separated, e.g. --brand=#0052FF or --brand=#2C3E35,#D4A373.`);
|
|
1514
|
+
const paths = projectPaths(tree, options.project);
|
|
1515
|
+
const emitted = emitThemeFile({
|
|
1516
|
+
seed: seeds.length === 1 ? seeds[0] : seeds,
|
|
1517
|
+
shape: options.shape ?? "modern",
|
|
1518
|
+
darkMode: options.darkMode ?? true,
|
|
1519
|
+
name: "Brand"
|
|
1520
|
+
});
|
|
1521
|
+
const installDeps = (t, ctx) => {
|
|
1522
|
+
const pkgPath = "package.json";
|
|
1523
|
+
const pkgText = t.read(pkgPath)?.toString();
|
|
1524
|
+
if (!pkgText) throw new _angular_devkit_schematics.SchematicsException("No package.json found at the workspace root.");
|
|
1525
|
+
const { text, missingForms } = addDependencies(pkgText, {
|
|
1526
|
+
"@uni-design-system/uni-angular": `~${version}`,
|
|
1527
|
+
"@uni-design-system/uni-core": `~${version}`,
|
|
1528
|
+
"@emotion/css": "^11.0.0"
|
|
1529
|
+
});
|
|
1530
|
+
t.overwrite(pkgPath, text);
|
|
1531
|
+
if (missingForms) ctx.logger.warn("@angular/forms is not installed — Uni input components use Signal Forms. Add it with: ng add @angular/forms");
|
|
1532
|
+
ctx.addTask(new _angular_devkit_schematics_tasks.NodePackageInstallTask());
|
|
1533
|
+
return t;
|
|
1534
|
+
};
|
|
1535
|
+
const writeThemeFile = (t) => {
|
|
1536
|
+
write(t, `${paths.appDir}/uni-theme.ts`, emitted.content);
|
|
1537
|
+
return t;
|
|
1538
|
+
};
|
|
1539
|
+
const registerProvider = (t, ctx) => {
|
|
1540
|
+
const configPath = firstExisting(t, [`${paths.appDir}/app.config.ts`]);
|
|
1541
|
+
const source = configPath && t.read(configPath)?.toString();
|
|
1542
|
+
const updated = source ? addProviderRegistration(source, "BrandThemes") : null;
|
|
1543
|
+
if (configPath && updated) t.overwrite(configPath, updated);
|
|
1544
|
+
else ctx.logger.warn(`Could not register UNI_THEMES automatically. Add this to your providers:\n${emitted.providerSnippet}`);
|
|
1545
|
+
return t;
|
|
1546
|
+
};
|
|
1547
|
+
const addTypefaces = (t, ctx) => {
|
|
1548
|
+
if (options.typography === false) return t;
|
|
1549
|
+
const html = t.read(paths.indexHtml)?.toString();
|
|
1550
|
+
const updated = html && addFontLinks(html);
|
|
1551
|
+
if (html && updated) t.overwrite(paths.indexHtml, updated);
|
|
1552
|
+
else ctx.logger.warn(`Could not add typeface links to ${paths.indexHtml} — add Red Hat Display and Roboto manually (BaseTypography depends on them).`);
|
|
1553
|
+
return t;
|
|
1554
|
+
};
|
|
1555
|
+
const addSmokeTest = (t, ctx) => {
|
|
1556
|
+
if (options.smokeTest === false) return t;
|
|
1557
|
+
const htmlPath = firstExisting(t, [`${paths.appDir}/app.html`, `${paths.appDir}/app.component.html`]);
|
|
1558
|
+
const tsPath = firstExisting(t, [`${paths.appDir}/app.ts`, `${paths.appDir}/app.component.ts`]);
|
|
1559
|
+
const componentSource = tsPath && t.read(tsPath)?.toString();
|
|
1560
|
+
const updatedComponent = componentSource ? addComponentImports(componentSource, ["UniTextComponent", "UniButtonComponent"]) : null;
|
|
1561
|
+
if (!htmlPath || !tsPath || !updatedComponent) {
|
|
1562
|
+
ctx.logger.warn("Could not scaffold the smoke test — drop a <uni-text> and a <button uni-text-button> into any component to verify the theme.");
|
|
1563
|
+
return t;
|
|
1564
|
+
}
|
|
1565
|
+
t.overwrite(tsPath, updatedComponent);
|
|
1566
|
+
t.overwrite(htmlPath, addSmokeMarkup(t.read(htmlPath).toString()));
|
|
1567
|
+
return t;
|
|
1568
|
+
};
|
|
1569
|
+
const summarize = (t, ctx) => {
|
|
1570
|
+
ctx.logger.info(`Uni theme generated: ${emitted.reportSummary}.`);
|
|
1571
|
+
ctx.logger.info(`Theme written to ${paths.appDir}/uni-theme.ts — it is plain data and the source of truth: edit its tokens (colors, border primitives, component overrides) to restyle the app.`);
|
|
1572
|
+
ctx.logger.info("Run `ng serve` — the smoke test section renders in your brand.");
|
|
1573
|
+
return t;
|
|
1574
|
+
};
|
|
1575
|
+
return (0, _angular_devkit_schematics.chain)([
|
|
1576
|
+
installDeps,
|
|
1577
|
+
writeThemeFile,
|
|
1578
|
+
registerProvider,
|
|
1579
|
+
addTypefaces,
|
|
1580
|
+
addSmokeTest,
|
|
1581
|
+
summarize
|
|
1582
|
+
]);
|
|
1583
|
+
};
|
|
1584
|
+
}
|
|
1585
|
+
//#endregion
|
|
1586
|
+
exports.ngAdd = ngAdd;
|