esm-styles 0.2.8 → 0.3.1

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
@@ -108,8 +108,15 @@ export default {
108
108
  outputPath: 'css',
109
109
  sourceFilesSuffix: '.styles.mjs',
110
110
 
111
- // Input layers
112
- layers: ['defaults', 'components', 'layout'],
111
+ // Input floors (replaces layers)
112
+ floors: [
113
+ { source: 'defaults', layer: 'defaults' },
114
+ { source: 'components', layer: 'components' },
115
+ { source: 'layout', layer: 'layout' },
116
+ ],
117
+
118
+ // Specify which floors to include in main CSS
119
+ importFloors: ['defaults', 'components', 'layout'],
113
120
 
114
121
  // Output
115
122
  mainCssFile: 'styles.css',
@@ -417,15 +424,28 @@ export default {
417
424
 
418
425
  ## Advanced Features
419
426
 
420
- ### Layering
427
+ ### Layering with Floors
421
428
 
422
- Organize your styles in layers for better control over specificity:
429
+ Organize your styles in floors for better control over specificity and output:
423
430
 
424
431
  ```js
425
- // defaults.styles.mjs, components.styles.mjs, layout.styles.mjs
432
+ // Configuration example
433
+ floors: [
434
+ { source: 'defaults', layer: 'defaults' },
435
+ { source: 'components', layer: 'components' },
436
+ { source: 'layout', layer: 'layout' },
437
+ { source: 'utilities' }, // No layer wrapper
438
+ { source: 'overrides', outputPath: 'special' }, // Custom output path
439
+ ]
426
440
  ```
427
441
 
428
- The build process wraps each in an appropriate layer and generates a main CSS file with proper import order.
442
+ Each floor can:
443
+
444
+ - Be wrapped in a CSS layer (optional)
445
+ - Have a custom output path (optional)
446
+ - Be included or excluded from the main CSS file via `importFloors`
447
+
448
+ The build process wraps floors in their respective layers and generates a main CSS file with proper import order.
429
449
 
430
450
  ### CSS Variable Inheritance
431
451
 
package/dist/build.js CHANGED
File without changes
package/dist/lib/build.js CHANGED
@@ -177,9 +177,15 @@ export async function build(configPath = 'esm-styles.config.js') {
177
177
  // Track output files for each floor
178
178
  const floorFiles = [];
179
179
  for (const floor of floors) {
180
- const { source, layer } = floor;
180
+ const { source, layer, outputPath: floorOutputPath } = floor;
181
181
  const inputFile = path.join(sourcePath, `${source}${suffix}`);
182
- const outputFile = path.join(outputPath, `${source}.css`);
182
+ // Use floor's outputPath if provided, otherwise use default
183
+ const floorOutputDir = floorOutputPath
184
+ ? path.join(basePath, floorOutputPath)
185
+ : outputPath;
186
+ // Ensure the output directory exists
187
+ await fs.mkdir(floorOutputDir, { recursive: true });
188
+ const outputFile = path.join(floorOutputDir, `${source}.css`);
183
189
  const fileUrl = pathToFileUrl(inputFile).href + `?update=${Date.now()}`;
184
190
  const stylesObj = (await import(fileUrl)).default;
185
191
  const css = getCss(stylesObj, {
@@ -196,8 +202,17 @@ export async function build(configPath = 'esm-styles.config.js') {
196
202
  wrappedCss = `${comment}@layer ${layer} {\n${css}\n}`;
197
203
  }
198
204
  await fs.writeFile(outputFile, wrappedCss, 'utf8');
199
- floorFiles.push({ file: `${source}.css`, layer, source });
200
- cssFiles.push({ floor: source, file: `${source}.css`, layer });
205
+ // Calculate relative path from default output directory for imports
206
+ const relativePath = floorOutputPath
207
+ ? path.relative(outputPath, outputFile)
208
+ : `${source}.css`;
209
+ floorFiles.push({
210
+ file: relativePath,
211
+ layer,
212
+ source,
213
+ outputPath: floorOutputPath,
214
+ });
215
+ cssFiles.push({ floor: source, file: relativePath, layer });
201
216
  }
202
217
  // 5. Create main CSS file
203
218
  const mainCssPath = path.join(outputPath, mainCssFile);
package/doc/ai-guide.md CHANGED
@@ -31,7 +31,7 @@ button {
31
31
  p: { fontSize: '16px' }, // -> p { font-size: 16px; }
32
32
 
33
33
  // Non-HTML tags become class selectors
34
- header: { display: 'flex' }, // -> .header { display: flex; }
34
+ heading: { display: 'flex' }, // -> .heading { display: flex; }
35
35
  card: { padding: '20px' } // -> .card { padding: 20px; }
36
36
  }
37
37
  ```
@@ -91,6 +91,28 @@ button {
91
91
  }
92
92
  ```
93
93
 
94
+ ### ⚠️ CRITICAL: Ampersand (&) Syntax is NOT Supported
95
+
96
+ ```js
97
+ // ❌ WRONG: These will NOT work (common mistake from SCSS/Sass)
98
+ {
99
+ button: {
100
+ '&:hover': { opacity: 0.9 }, // ❌ Ampersand not supported
101
+ '&.active': { color: 'red' }, // ❌ Will not work
102
+ '&[disabled]': { opacity: 0.5 } // ❌ Will not work
103
+ }
104
+ }
105
+
106
+ // ✅ CORRECT: Use direct selectors instead
107
+ {
108
+ button: {
109
+ ':hover': { opacity: 0.9 }, // ✅ Direct pseudo-class
110
+ active: { color: 'red' }, // ✅ Class name (if not HTML tag)
111
+ '[disabled]': { opacity: 0.5 } // ✅ Direct attribute selector
112
+ }
113
+ }
114
+ ```
115
+
94
116
  ### Multiple Selectors
95
117
 
96
118
  ```js
@@ -184,7 +206,12 @@ export default {
184
206
  basePath: './src/styles',
185
207
  sourcePath: 'source',
186
208
  outputPath: 'css',
187
- layers: ['base', 'components', 'utilities'],
209
+ floors: [
210
+ { source: 'base', layer: 'base' },
211
+ { source: 'components', layer: 'components' },
212
+ { source: 'utilities', layer: 'utilities' },
213
+ ],
214
+ importFloors: ['base', 'components', 'utilities'],
188
215
  mainCssFile: 'styles.css',
189
216
 
190
217
  // Media shorthand definitions
@@ -120,6 +120,12 @@ Represents a set of CSS property declarations.
120
120
  The `esm-styles.config.js` file exports a configuration object with the following structure:
121
121
 
122
122
  ```typescript
123
+ interface FloorConfig {
124
+ source: string
125
+ layer?: string
126
+ outputPath?: string
127
+ }
128
+
123
129
  interface ESMStylesConfig {
124
130
  // Paths
125
131
  basePath: string
@@ -128,7 +134,8 @@ interface ESMStylesConfig {
128
134
  sourceFilesSuffix?: string
129
135
 
130
136
  // Input
131
- layers: string[]
137
+ floors: FloorConfig[]
138
+ importFloors?: string[]
132
139
 
133
140
  // Output
134
141
  mainCssFile: string
@@ -146,19 +153,28 @@ interface ESMStylesConfig {
146
153
 
147
154
  #### Properties
148
155
 
149
- | Property | Type | Description | Default |
150
- | -------------------- | -------- | ----------------------------- | ------------- |
151
- | `basePath` | string | Base directory for styles | - |
152
- | `sourcePath` | string | Source files directory | - |
153
- | `outputPath` | string | Output CSS directory | - |
154
- | `sourceFilesSuffix` | string | Suffix for source files | '.styles.mjs' |
155
- | `layers` | string[] | Array of layer names | - |
156
- | `mainCssFile` | string | Output CSS file name | - |
157
- | `globalVariables` | string | Global variables file name | - |
158
- | `globalRootSelector` | string | Root selector for variables | ':root' |
159
- | `media` | object | Media types and variables | - |
160
- | `mediaSelectors` | object | Media selector configurations | - |
161
- | `mediaQueries` | object | Named media query shorthands | - |
156
+ | Property | Type | Description | Default |
157
+ | -------------------- | ------------- | ---------------------------------- | ------------- |
158
+ | `basePath` | string | Base directory for styles | - |
159
+ | `sourcePath` | string | Source files directory | - |
160
+ | `outputPath` | string | Output CSS directory | - |
161
+ | `sourceFilesSuffix` | string | Suffix for source files | '.styles.mjs' |
162
+ | `floors` | FloorConfig[] | Array of floor configurations | - |
163
+ | `importFloors` | string[] | Floor names to include in main CSS | - |
164
+ | `mainCssFile` | string | Output CSS file name | - |
165
+ | `globalVariables` | string | Global variables file name | - |
166
+ | `globalRootSelector` | string | Root selector for variables | ':root' |
167
+ | `media` | object | Media types and variables | - |
168
+ | `mediaSelectors` | object | Media selector configurations | - |
169
+ | `mediaQueries` | object | Named media query shorthands | - |
170
+
171
+ #### FloorConfig Properties
172
+
173
+ | Property | Type | Description | Default |
174
+ | ------------ | ------ | -------------------------------------------- | ------- |
175
+ | `source` | string | Source file name (without suffix) | - |
176
+ | `layer` | string | CSS layer name to wrap the floor styles in | - |
177
+ | `outputPath` | string | Custom output path for this floor's CSS file | - |
162
178
 
163
179
  ### Media Selectors
164
180