@aleph-alpha/config-css 0.22.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@aleph-alpha/config-css",
3
3
  "license": "Apache-2.0",
4
- "version": "0.22.0",
4
+ "version": "1.1.0",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
7
7
  "prettier": "@aleph-alpha/prettier-config-frontend",
@@ -25,7 +25,7 @@
25
25
  "style-dictionary": "^4.0.1",
26
26
  "vite-plugin-dts": "^4.0.0",
27
27
  "@aleph-alpha/eslint-config-frontend": "0.5.0",
28
- "@aleph-alpha/prettier-config-frontend": "0.4.0"
28
+ "@aleph-alpha/prettier-config-frontend": "2.1.0"
29
29
  },
30
30
  "scripts": {
31
31
  "transform:global": "npx token-transformer ./tokens.json ./transformed-tokens/global.json global,\"Spark Border Radius/Mode 1\",\"Spark Spacings/Mode 1\",\"Spark Text/Mode 1\" \"Spark Colors/Light mode/primitives\" --throwErrorWhenNotResolved",
package/sd.config.js CHANGED
@@ -38,7 +38,10 @@ StyleDictionary.registerTransform({
38
38
  return token.type === 'typography';
39
39
  },
40
40
  transform: function (token) {
41
- return token.name.split('-').splice(1, token.name.split('-').length).join('-');
41
+ return token.name
42
+ .split('-')
43
+ .splice(1, token.name.split('-').length)
44
+ .join('-');
42
45
  },
43
46
  });
44
47
 
@@ -85,7 +88,9 @@ StyleDictionary.registerTransform({
85
88
 
86
89
  const css = {};
87
90
  keys.forEach((key) => {
88
- const newKey = key.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase();
91
+ const newKey = key
92
+ .replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2')
93
+ .toLowerCase();
89
94
 
90
95
  if (allowedKeys.includes(newKey)) {
91
96
  css[newKey] = value[key];
@@ -110,7 +115,8 @@ StyleDictionary.registerTransform({
110
115
  if (!value) return;
111
116
 
112
117
  if (value['font-family']) {
113
- value['font-family'] = `var(--custom-font-family, ${value['font-family']})`;
118
+ value['font-family'] =
119
+ `var(--custom-font-family, ${value['font-family']})`;
114
120
  }
115
121
 
116
122
  return value;
package/src/index.ts CHANGED
@@ -16,6 +16,19 @@ type Theme = {
16
16
  boxShadow?: Record<keyof typeof boxShadowsSet, string>;
17
17
  };
18
18
 
19
+ const formatVarBlock = (
20
+ set: Record<string, string>,
21
+ options: { prefix?: string; lowercaseKey?: boolean } = {},
22
+ ): string => {
23
+ const { prefix = '', lowercaseKey = false } = options;
24
+ return Object.entries(set)
25
+ .map(([key, value]) => {
26
+ const cssKey = lowercaseKey ? key.toLowerCase() : key;
27
+ return `--${prefix}${cssKey}: ${value};`;
28
+ })
29
+ .join('\n ');
30
+ };
31
+
19
32
  /**
20
33
  * This preset is used to add the aleph alpha specific utilities for tokens from the design system.
21
34
  * Only the dark theme tokens are not included.
@@ -27,6 +40,25 @@ const tokenPreset: Preset<Theme> = definePreset<Theme>(() => {
27
40
  {
28
41
  getCSS() {
29
42
  return `
43
+ /*
44
+ * Design-system tokens as CSS custom properties.
45
+ *
46
+ * Mirrors the entries already registered in \`theme\` (colors, spacing,
47
+ * box-shadow), so consumers can reach the same tokens from raw CSS,
48
+ * inline \`:style\` bindings, and \`:global()\` overrides — not just
49
+ * from utility classes. Light/dark switching cascades automatically:
50
+ * any \`var(--<token>)\` under \`html.dark\` resolves to the dark value
51
+ * without needing parallel rules.
52
+ */
53
+ :root {
54
+ ${formatVarBlock(lightModeSet)}
55
+ ${formatVarBlock(spacingsSet, { prefix: 'spacing-', lowercaseKey: true })}
56
+ ${formatVarBlock(boxShadowsSet, { prefix: 'shadow-' })}
57
+ }
58
+ html.dark {
59
+ ${formatVarBlock(darkModeSet)}
60
+ }
61
+
30
62
  html {
31
63
  -webkit-font-smoothing: antialiased;
32
64
  -moz-osx-font-smoothing: grayscale;
@@ -106,7 +138,10 @@ const tokenPreset: Preset<Theme> = definePreset<Theme>(() => {
106
138
  },
107
139
  },
108
140
  ],
109
- rules: [...Object.entries(typographySet), ['h-screen', { height: '100vh' }]],
141
+ rules: [
142
+ ...Object.entries(typographySet),
143
+ ['h-screen', { height: '100vh' }],
144
+ ],
110
145
  theme: {
111
146
  colors: lightModeSet,
112
147
  spacing: spacingsSet,
@@ -12,7 +12,10 @@ import { inter500 } from './assets/fonts/inter500.woff2';
12
12
  import { inter600 } from './assets/fonts/inter600.woff2';
13
13
  import { inter700 } from './assets/fonts/inter700.woff2';
14
14
 
15
- const normalizeEmbeddedFontDataUri = (fontDataUri: string, mimeType = 'font/woff2') => {
15
+ const normalizeEmbeddedFontDataUri = (
16
+ fontDataUri: string,
17
+ mimeType = 'font/woff2',
18
+ ) => {
16
19
  const normalizedUri = fontDataUri.trim();
17
20
  const legacyPrefixes = [
18
21
  'data:@file/octet-stream;base64,',
@@ -21,7 +24,9 @@ const normalizeEmbeddedFontDataUri = (fontDataUri: string, mimeType = 'font/woff
21
24
  'data:%40file/binary;base64,',
22
25
  ];
23
26
 
24
- const matchedPrefix = legacyPrefixes.find((prefix) => normalizedUri.startsWith(prefix));
27
+ const matchedPrefix = legacyPrefixes.find((prefix) =>
28
+ normalizedUri.startsWith(prefix),
29
+ );
25
30
  if (matchedPrefix) {
26
31
  return `data:${mimeType};base64,${normalizedUri.slice(matchedPrefix.length)}`;
27
32
  }
@@ -32,7 +32,9 @@ const args = process.argv.slice(2);
32
32
 
33
33
  if (args.length < 2) {
34
34
  console.log('Usage: node convert-fonts.js <input.woff2> <output.ts>');
35
- console.log('Example: node convert-fonts.js montserrat600.woff2 montserrat600.woff2.ts');
35
+ console.log(
36
+ 'Example: node convert-fonts.js montserrat600.woff2 montserrat600.woff2.ts',
37
+ );
36
38
  process.exit(1);
37
39
  }
38
40