@aleph-alpha/config-css 1.0.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": "1.0.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": "2.0.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/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;