anubis-ui 1.2.24 → 1.2.26

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/README.md CHANGED
@@ -80,7 +80,7 @@ css: [
80
80
 
81
81
  6. Enjoy
82
82
 
83
- > **Note**: Generated CSS variables (from colors and export-variations) are available for custom styling:
83
+ > **Note**: Generated CSS variables (from colors and export) are available for custom styling:
84
84
  > ```css
85
85
  > .custom-class {
86
86
  > background: var(--primary-low);
@@ -116,7 +116,8 @@ For every config you want to change, add the corresponding section in your confi
116
116
  "qol": [
117
117
  {
118
118
  "prefix": "bg",
119
- "declaration": "background: ${color}"
119
+ "declaration": "background: ${color}",
120
+ "export": "all"
120
121
  }
121
122
  ],
122
123
 
@@ -128,7 +129,16 @@ For every config you want to change, add the corresponding section in your confi
128
129
  "variations": {
129
130
  "default": "4px",
130
131
  "thin": "2px"
131
- }
132
+ },
133
+ "export": "variation"
134
+ },
135
+ {
136
+ "prefix": "rounded",
137
+ "declaration": "border-radius: ${value}",
138
+ "variations": {
139
+ "default": "8px",
140
+ "lg": "12px"
141
+ },
132
142
  }
133
143
  ],
134
144
 
@@ -243,21 +253,24 @@ QoL utilities include:
243
253
  1. `prefix` - The class name prefix
244
254
  2. `declaration` - CSS rule using `${value}` placeholder for variations
245
255
  3. `variations` - Key-value pairs of variation names and their CSS values
246
- 4. `standalone` (optional) - Allows usage without variation (uses `default` value)
247
- 5. `export-variations` (optional) - Generates CSS variables for all variations
248
-
249
- **The `standalone` flag**:
250
- - `standalone: true` → Can use `rounded` or `rounded-lg` (both valid)
251
- - `standalone: false` or omitted → Must use `border-solid` (requires variation)
256
+ 4. `export` (optional) - Controls how variations are exported as CSS variables
252
257
 
253
- **The `export-variations` flag**:
254
- - `export-variations: true` → Generates `--size-xs`, `--size-md`, etc. as CSS variables
258
+ **The `export` flag**:
259
+ - `export: "variation"` → Generates CSS variables every variations
260
+ - `export: "all"` → Generates classes for every possible color
255
261
  - These can be used in custom CSS: `font-size: var(--size-xl)`
256
262
 
263
+ **Color support**:
264
+ - Use `${color}` in declaration to indicate the utility requires a color
265
+ - Colors are automatically injected as CSS variables: `var(--{color})`
266
+
267
+ **Standalone usage**:
268
+ - Utilities with a `default` variation and no color requirement can be used without specifying a variation (e.g., `rounded` uses `rounded-default`)
269
+
257
270
  Example usage:
258
271
  ```html
259
- <div class="rounded-lg smooth-slow border-dashed" />
260
- <div class="rounded smooth blur" /> <!-- Standalone rules with default values -->
272
+ <div class="bg-primary-low border-neutral-medium hover:shadow-wide rounded-lg" />
273
+ <div class="rounded smooth blur" /> <!-- Uses default variations -->
261
274
  <p class="size-2xl weight-bold">Typography utilities</p>
262
275
  ```
263
276
 
@@ -380,7 +393,7 @@ Examples:
380
393
  | size | `font-size: {value} !important;` |
381
394
  | weight | `font-weight: {value} !important;` |
382
395
 
383
- **Note**: When `export-variations: true` is set, `{value}` becomes `var(--{prefix}-{variation})` instead of the direct value.
396
+ **Note**: When `export: "variation"` is set, `{value}` becomes `var(--{prefix}-{variation})` instead of the direct value.
384
397
 
385
398
  ## Architecture
386
399
 
@@ -410,7 +423,7 @@ Examples:
410
423
 
411
424
  5. **CSS Output** (`src/tools/fileStuff/css.file.ts`)
412
425
  - Generates color CSS variables with light/dark theme support
413
- - Generates variation CSS variables (from `export-variations: true`)
426
+ - Generates variation CSS variables (from `export: "variation"` or `export: "all"`)
414
427
  - Writes final CSS rules
415
428
  - Outputs to `src/css/_anubis.scss`
416
429
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anubis-ui",
3
- "version": "1.2.24",
3
+ "version": "1.2.26",
4
4
  "description": "Class-based css generator",
5
5
  "main": "index.js",
6
6
  "keywords": [
@@ -1,11 +1,13 @@
1
1
  [
2
2
  {
3
3
  "prefix": "bg",
4
- "declaration": "background: ${color}"
4
+ "declaration": "background: ${color}",
5
+ "export": "all"
5
6
  },
6
7
  {
7
8
  "prefix": "text",
8
- "declaration": "color: ${color}"
9
+ "declaration": "color: ${color}",
10
+ "export": "all"
9
11
  },
10
12
  {
11
13
  "prefix": "text",
@@ -113,7 +115,7 @@
113
115
  {
114
116
  "prefix": "size",
115
117
  "declaration": "font-size: ${value} !important",
116
- "export-variations": true,
118
+ "export": "variation",
117
119
  "variations": {
118
120
  "2xs": "10px",
119
121
  "xs": "12px",
@@ -134,7 +136,7 @@
134
136
  {
135
137
  "prefix": "weight",
136
138
  "declaration": "font-weight: ${value} !important",
137
- "export-variations": true,
139
+ "export": "variation",
138
140
  "variations": {
139
141
  "thin": "100",
140
142
  "extra-light": "200",
@@ -1,9 +1,9 @@
1
1
  import { IColor } from './color.interface';
2
- import { IPreset } from './preset.interface';
2
+ import { IUtility } from './preset.interface';
3
3
  import { IFileConfig } from './files.interface';
4
4
 
5
5
  export interface IEnvConfig {
6
- utilities: IPreset[];
6
+ utilities: IUtility[];
7
7
  files: IFileConfig;
8
8
 
9
9
  /** User-given classes to force the css rule creation */
@@ -2,7 +2,7 @@ export interface IVariation {
2
2
  [key: string]: string;
3
3
  }
4
4
 
5
- export interface IPreset {
5
+ export interface IUtility {
6
6
  // [key: string]: string
7
7
  prefix: string;
8
8
  declaration: string;
@@ -12,11 +12,11 @@ export interface IPreset {
12
12
 
13
13
  /**
14
14
  * Controls how variations are exported as SCSS variables:
15
- * - true: export only variations that are used in the codebase
16
- * - "always": export all variations regardless of usage
17
- * - undefined/false: do not export variations
15
+ * - "variation": export every variations
16
+ * - "all": export every possible color class (utility prefix + every colors)
17
+ * - undefined: do not export variations
18
18
  */
19
- 'export-variations'?: boolean | 'always';
19
+ 'export'?: 'variations' | 'all';
20
20
 
21
21
  /** List of every possible variations */
22
22
  variations: IVariation;
@@ -37,7 +37,7 @@ const init = () => {
37
37
  } else {
38
38
  const filePath = path.join(anubisConfigFolder, `${file}.config.json`)
39
39
  const fileExists = fs.existsSync(filePath)
40
- if (!fileExists) { return }
40
+ if (!fileExists) { continue }
41
41
 
42
42
  const configContent = fs.readFileSync(filePath, { encoding: 'utf-8' })
43
43
  if (!configContent) { continue }
@@ -45,9 +45,11 @@ const init = () => {
45
45
  configToUse = JSON.parse(configContent)
46
46
  }
47
47
 
48
+ config[file as keyof typeof config] = configToUse
49
+
48
50
  switch (file) {
49
51
  case 'colors':
50
- validateColors(config[file])
52
+ validateColors(config.colors)
51
53
  break
52
54
 
53
55
  case 'force':
@@ -57,8 +59,6 @@ const init = () => {
57
59
  }
58
60
  break
59
61
  }
60
-
61
- config[file as keyof typeof config] = configToUse
62
62
  }
63
63
 
64
64
  return config
@@ -67,11 +67,14 @@ const init = async () => {
67
67
  config.colors
68
68
  )}`;
69
69
 
70
- // Get all variations that should be exported (export-variations: true)
71
- const allExportVariations = getAllExportVariations();
70
+ // Get all variations that should be exported (export: "variations")
71
+ const exportVariations = getExportVariations();
72
72
 
73
73
  // Merge used variations with all export variations (all export variations take priority)
74
- const finalVariations = { ...variationsFromRules, ...allExportVariations };
74
+ const finalVariations = {
75
+ ...variationsFromRules,
76
+ ...exportVariations
77
+ };
75
78
 
76
79
  // Generate CSS variables for variations
77
80
  const variationsCss = Object.entries(finalVariations)
@@ -95,7 +98,13 @@ const getUniqueClasses = async (files: string[]): Promise<string[]> => {
95
98
  await pLimit(files, extractClasses, MAX_CONCURRENT_FILE_READS)
96
99
  ).flat();
97
100
 
98
- const classes = [...extractedClasses, ...config.force].sort();
101
+ const exportClasses = getExportAllClasses()
102
+
103
+ const classes = [
104
+ ...extractedClasses,
105
+ ...exportClasses,
106
+ ...config.force,
107
+ ].sort();
99
108
 
100
109
  const uniqueClasses = Array.from(new Set(classes));
101
110
  return uniqueClasses;
@@ -116,7 +125,7 @@ const buildClassDetectionRegex = (): RegExp => {
116
125
  const hasDefaultVariation = hasVariations && variations.includes('default')
117
126
  const needColor = declaration.includes('${color}')
118
127
 
119
- /** If variation has default key, it's considered as a standalone - can be used solo */
128
+ /** If variation has default key and doesn't need color, can be used solo */
120
129
  if (hasVariations && hasDefaultVariation && !needColor) {
121
130
  return `${prefix}`
122
131
  }
@@ -137,8 +146,8 @@ const buildClassDetectionRegex = (): RegExp => {
137
146
 
138
147
  /** Get cached regex or build a new one if config changed */
139
148
  const getClassDetectionRegex = (): RegExp => {
140
- const { states, qol, utilitys } = config;
141
- const configHash = JSON.stringify({ states, qol, utilitys });
149
+ const { states, utilities } = config;
150
+ const configHash = JSON.stringify({ states, utilities });
142
151
 
143
152
  if (cachedRegex && cachedConfigHash === configHash) {
144
153
  return cachedRegex;
@@ -162,23 +171,45 @@ const extractClasses = async (filePath: string): Promise<string[]> => {
162
171
  return matches;
163
172
  };
164
173
 
165
- /** Get all variations from utilitys with export-variations: true */
166
- const getAllExportVariations = (): Record<string, string> => {
167
- const allExportVariations: Record<string, string> = {};
168
- const allUtilities = [...config.utilities];
174
+ /** Get all variations from utilities with export: "all" */
175
+ const getExportAllClasses = (): string[] => {
176
+ const possiblesClasses: string[] = [];
177
+
178
+ const utilities = [...config.utilities];
179
+ const colors = Object.keys(config.colors);
180
+
181
+ for (const utility of utilities) {
182
+ const exportValue = utility['export'];
183
+ // Pour "all", exporter toutes les possibilités de couleurs
184
+ if (exportValue === 'all') {
185
+ possiblesClasses.push(
186
+ ...colors.map(c => `${utility.prefix}-${c}`)
187
+ )
188
+ }
189
+ }
190
+
191
+ return possiblesClasses;
192
+ };
193
+
194
+ /** Get all variations from utilities with export: "variations" */
195
+ const getExportVariations = (): Record<string, string> => {
196
+ const exportAllVariations: Record<string, string> = {};
197
+ const utilities = [...config.utilities];
169
198
 
170
- for (const utility of allUtilities) {
171
- if (utility['export-variations'] === true && utility.variations) {
199
+ for (const utility of utilities) {
200
+ const exportValue = utility['export'];
201
+ // Pour "variations", exporter toutes les variations
202
+ if (exportValue === 'variations' && utility.variations) {
172
203
  for (const [variantName, variantValue] of Object.entries(
173
204
  utility.variations
174
205
  )) {
175
206
  const variableName = `${utility.prefix}-${variantName}`;
176
- allExportVariations[variableName] = variantValue as string;
207
+ exportAllVariations[variableName] = variantValue as string;
177
208
  }
178
209
  }
179
210
  }
180
211
 
181
- return allExportVariations;
212
+ return exportAllVariations;
182
213
  };
183
214
 
184
215
  export { init };
@@ -120,8 +120,7 @@ const getUtilityInfos = ({
120
120
  }) => {
121
121
  /**
122
122
  * Find utility variations matching the prefix from the config
123
- * Since a prefix can be in multiple utilitys and qol, filter every matching prefixes
124
- * TODO fix first default occurence getting picked when duplicate
123
+ * Since a prefix can be in multiple utilities, filter every matching prefixes
125
124
  */
126
125
  const possibleUtility = [...config.utilities].filter(
127
126
  p => p.prefix === prefix
@@ -251,8 +250,8 @@ const buildRuleInfo = ({
251
250
  let variantInfo = undefined;
252
251
 
253
252
  // Vérifier si on doit exporter les variations en tant que variables CSS
254
- const exportVariations = utility['export-variations'];
255
- const useVariables = exportVariations === true;
253
+ const exportVariations = utility['export'];
254
+ const useVariables = exportVariations === 'variations' || exportVariations === 'all';
256
255
 
257
256
  if (variationName && variationName !== 'default') {
258
257
  const variablePrefix = prefix;
@@ -61,7 +61,7 @@ const COLOR_COMMENT = `/**
61
61
 
62
62
  const VARIANT_COMMENT = `/**
63
63
  * These css variables are generated automatically when Anubis
64
- * detects that they are used in preset/qol in your config.
64
+ * detects that they are used in utilities in your config.
65
65
  *
66
66
  * It allows you to write custom css/scss classes in your web
67
67
  * components like:
@@ -72,7 +72,7 @@ const VARIANT_COMMENT = `/**
72
72
  * }
73
73
  *
74
74
  * (You can also force the generation of all variants from a
75
- * preset/qol by setting the 'export-variations' to 'true')
75
+ * utility by setting the 'export' to 'variations')
76
76
  */`;
77
77
 
78
78
  const CLASS_COMMENT = `/**