@aleph-alpha/ui-library 2.8.3 → 2.9.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/config.d.ts +7 -0
- package/config.js +48 -11
- package/docs/public-docs/quick-start.md +5 -0
- package/package.json +3 -3
package/config.d.ts
CHANGED
|
@@ -47,6 +47,12 @@ export interface UiLibraryThemeOptions {
|
|
|
47
47
|
* @default 'html.dark'
|
|
48
48
|
*/
|
|
49
49
|
darkSelector?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Font size emitted on the root selector to control the UI library rem base.
|
|
52
|
+
* String values are used as-is (for example, '100%', '16px', '62.5%').
|
|
53
|
+
* Number values are treated as pixels.
|
|
54
|
+
*/
|
|
55
|
+
rootFontSize?: string | number;
|
|
50
56
|
}
|
|
51
57
|
|
|
52
58
|
/**
|
|
@@ -295,6 +301,7 @@ export interface UiLibraryConfigOptions extends UiLibraryPresetOptions {
|
|
|
295
301
|
* export default defineUiLibraryConfig({
|
|
296
302
|
* extend: { light: { primary: '#ff5500' } },
|
|
297
303
|
* darkSelector: 'html.dark',
|
|
304
|
+
* rootFontSize: '100%',
|
|
298
305
|
* })
|
|
299
306
|
* ```
|
|
300
307
|
*/
|
package/config.js
CHANGED
|
@@ -481,6 +481,16 @@ const mergeThemes = (base, extend) => {
|
|
|
481
481
|
};
|
|
482
482
|
};
|
|
483
483
|
|
|
484
|
+
const normalizeRootFontSize = (value) => {
|
|
485
|
+
if (value == null) return undefined;
|
|
486
|
+
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
487
|
+
return `${value}px`;
|
|
488
|
+
}
|
|
489
|
+
if (typeof value !== 'string') return undefined;
|
|
490
|
+
const trimmed = value.trim();
|
|
491
|
+
return trimmed || undefined;
|
|
492
|
+
};
|
|
493
|
+
|
|
484
494
|
const isAccessibleThemeMode = (options = {}) =>
|
|
485
495
|
getUiLibraryThemeMode(options) === UI_LIBRARY_REFERENCE_THEME_SETS.accessible;
|
|
486
496
|
|
|
@@ -642,6 +652,7 @@ export const defineThemeConfig = (config) => config;
|
|
|
642
652
|
export const presetUiLibraryTheme = (theme, options = {}) => {
|
|
643
653
|
const rootSelector = options.rootSelector ?? ':root';
|
|
644
654
|
const darkSelector = options.darkSelector ?? 'html.dark';
|
|
655
|
+
const rootFontSize = normalizeRootFontSize(options.rootFontSize);
|
|
645
656
|
|
|
646
657
|
const opacityDefaults = `
|
|
647
658
|
*,
|
|
@@ -654,19 +665,23 @@ export const presetUiLibraryTheme = (theme, options = {}) => {
|
|
|
654
665
|
--un-shadow-opacity: 1;
|
|
655
666
|
}`.trim();
|
|
656
667
|
|
|
657
|
-
const toCssBlock = (selector, vars) => {
|
|
668
|
+
const toCssBlock = (selector, vars, extraDeclarations = []) => {
|
|
658
669
|
const entries = Object.entries(vars || {}).filter(
|
|
659
670
|
([k]) => k && typeof k === 'string',
|
|
660
671
|
);
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
.map(([k, v]) => ` --${k}: ${normalizeShadcnVarValue(v)};`)
|
|
664
|
-
|
|
672
|
+
const lines = [
|
|
673
|
+
...extraDeclarations,
|
|
674
|
+
...entries.map(([k, v]) => ` --${k}: ${normalizeShadcnVarValue(v)};`),
|
|
675
|
+
].join('\n');
|
|
676
|
+
if (!lines) return '';
|
|
665
677
|
return `${selector} {\n${lines}\n}\n`;
|
|
666
678
|
};
|
|
667
679
|
|
|
668
|
-
const css =
|
|
669
|
-
|
|
680
|
+
const css = `${opacityDefaults}\n${toCssBlock(
|
|
681
|
+
rootSelector,
|
|
682
|
+
theme.light,
|
|
683
|
+
rootFontSize ? [` font-size: ${rootFontSize};`] : [],
|
|
684
|
+
)}${toCssBlock(darkSelector, theme.dark)}`.trim();
|
|
670
685
|
|
|
671
686
|
return definePreset(() => ({
|
|
672
687
|
name: '@aleph-alpha/ui-library-theme',
|
|
@@ -1000,6 +1015,7 @@ export const presetUiLibraryUtils = () =>
|
|
|
1000
1015
|
* export default defineUiLibraryConfig({
|
|
1001
1016
|
* extend: { light: { primary: '#ff5500' } },
|
|
1002
1017
|
* darkSelector: 'html.dark',
|
|
1018
|
+
* rootFontSize: '100%',
|
|
1003
1019
|
* })
|
|
1004
1020
|
* ```
|
|
1005
1021
|
*/
|
|
@@ -1007,6 +1023,7 @@ export const defineUiLibraryConfig = (options = {}) => {
|
|
|
1007
1023
|
const {
|
|
1008
1024
|
darkSelector,
|
|
1009
1025
|
rootSelector,
|
|
1026
|
+
rootFontSize,
|
|
1010
1027
|
extend,
|
|
1011
1028
|
theme,
|
|
1012
1029
|
includeAllTokens,
|
|
@@ -1019,6 +1036,7 @@ export const defineUiLibraryConfig = (options = {}) => {
|
|
|
1019
1036
|
const themeOptions = {};
|
|
1020
1037
|
if (darkSelector !== undefined) themeOptions.darkSelector = darkSelector;
|
|
1021
1038
|
if (rootSelector !== undefined) themeOptions.rootSelector = rootSelector;
|
|
1039
|
+
if (rootFontSize !== undefined) themeOptions.rootFontSize = rootFontSize;
|
|
1022
1040
|
if (extend !== undefined) themeOptions.extend = extend;
|
|
1023
1041
|
if (theme !== undefined) themeOptions.theme = theme;
|
|
1024
1042
|
if (includeAllTokens !== undefined)
|
|
@@ -1059,9 +1077,20 @@ const fontWeightMap = {
|
|
|
1059
1077
|
Light: '300',
|
|
1060
1078
|
};
|
|
1061
1079
|
|
|
1062
|
-
/** Design-tool sizes are px;
|
|
1080
|
+
/** Design-tool sizes are px; rem token values resolve against a 16px base. */
|
|
1063
1081
|
const ROOT_FONT_SIZE_PX = 16;
|
|
1064
1082
|
|
|
1083
|
+
const formatPx = (value) => {
|
|
1084
|
+
const rounded = Math.round(value * 10000) / 10000;
|
|
1085
|
+
return `${rounded}px`;
|
|
1086
|
+
};
|
|
1087
|
+
|
|
1088
|
+
const numericDesignPxToPx = (raw) => {
|
|
1089
|
+
const n = typeof raw === 'number' ? raw : parseFloat(String(raw).trim());
|
|
1090
|
+
if (!Number.isFinite(n)) return null;
|
|
1091
|
+
return formatPx(n);
|
|
1092
|
+
};
|
|
1093
|
+
|
|
1065
1094
|
const numericDesignPxToRem = (raw) => {
|
|
1066
1095
|
const n = typeof raw === 'number' ? raw : parseFloat(String(raw).trim());
|
|
1067
1096
|
if (!Number.isFinite(n)) return null;
|
|
@@ -1070,16 +1099,24 @@ const numericDesignPxToRem = (raw) => {
|
|
|
1070
1099
|
return `${rounded}rem`;
|
|
1071
1100
|
};
|
|
1072
1101
|
|
|
1073
|
-
|
|
1102
|
+
const remToPx = (raw) => {
|
|
1103
|
+
const n = parseFloat(String(raw).trim());
|
|
1104
|
+
if (!Number.isFinite(n)) return null;
|
|
1105
|
+
return formatPx(n * ROOT_FONT_SIZE_PX);
|
|
1106
|
+
};
|
|
1107
|
+
|
|
1108
|
+
/** Token Studio may export dimensions as strings; font-size output is always px. */
|
|
1074
1109
|
const normalizeFontSizeForCss = (value) => {
|
|
1075
1110
|
if (value == null) return value;
|
|
1076
1111
|
if (typeof value === 'number' && Number.isFinite(value))
|
|
1077
|
-
return
|
|
1112
|
+
return numericDesignPxToPx(value);
|
|
1078
1113
|
if (typeof value === 'string') {
|
|
1079
1114
|
const t = value.trim();
|
|
1080
1115
|
if (/^(calc|var|--)/i.test(t)) return t;
|
|
1116
|
+
if (/^-?\d+(\.\d+)?rem$/i.test(t)) return remToPx(t) ?? t;
|
|
1117
|
+
if (/^-?\d+(\.\d+)?px$/i.test(t)) return t;
|
|
1081
1118
|
if (/[a-z%]/i.test(t)) return t;
|
|
1082
|
-
if (/^\d+(\.\d+)?$/.test(t)) return
|
|
1119
|
+
if (/^\d+(\.\d+)?$/.test(t)) return numericDesignPxToPx(t) ?? t;
|
|
1083
1120
|
}
|
|
1084
1121
|
return value;
|
|
1085
1122
|
};
|
|
@@ -59,6 +59,8 @@ import { defineUiLibraryConfig } from '@aleph-alpha/ui-library/config'
|
|
|
59
59
|
export default defineUiLibraryConfig({
|
|
60
60
|
// Override specific theme variables
|
|
61
61
|
extend: { light: { primary: '#ff5500' } },
|
|
62
|
+
// Configure the root rem base used by typography and spacing utilities
|
|
63
|
+
rootFontSize: '100%',
|
|
62
64
|
// Add your own presets
|
|
63
65
|
presets: [myCustomPreset()],
|
|
64
66
|
})
|
|
@@ -74,6 +76,9 @@ export default defineUiLibraryConfig({
|
|
|
74
76
|
// Root and dark selectors used for generated CSS variables
|
|
75
77
|
rootSelector: ':root',
|
|
76
78
|
darkSelector: 'html.dark',
|
|
79
|
+
// Root font-size for the rem base. Strings are used as CSS values;
|
|
80
|
+
// numbers are treated as px.
|
|
81
|
+
rootFontSize: '100%',
|
|
77
82
|
// Include all token vars like --background-surface-secondary
|
|
78
83
|
includeAllTokens: true,
|
|
79
84
|
// Extend token-derived theme values
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aleph-alpha/ui-library",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/system/lib.js",
|
|
@@ -79,8 +79,8 @@
|
|
|
79
79
|
"vue-tsc": "^2.2.12",
|
|
80
80
|
"wait-on": "9.0.3",
|
|
81
81
|
"@aleph-alpha/eslint-config-frontend": "0.6.0",
|
|
82
|
-
"@aleph-alpha/
|
|
83
|
-
"@aleph-alpha/
|
|
82
|
+
"@aleph-alpha/prettier-config-frontend": "2.1.0",
|
|
83
|
+
"@aleph-alpha/tsconfig-frontend": "0.6.0"
|
|
84
84
|
},
|
|
85
85
|
"peerDependencies": {
|
|
86
86
|
"@unocss/preset-wind4": ">=66.0.0",
|