esm-styles 0.2.5 → 0.2.6

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/dist/lib/build.js CHANGED
@@ -163,6 +163,8 @@ export async function build(configPath = 'esm-styles.config.js') {
163
163
  }
164
164
  }
165
165
  // 4. Process each floor (replaces legacy layers)
166
+ const importFloors = config.importFloors || floors.map((f) => f.source);
167
+ // Track unique layer names in order of first appearance (for imported floors only)
166
168
  const uniqueLayers = [];
167
169
  // Track output files for each floor
168
170
  const floorFiles = [];
@@ -178,29 +180,41 @@ export async function build(configPath = 'esm-styles.config.js') {
178
180
  });
179
181
  let wrappedCss = css;
180
182
  if (layer) {
181
- wrappedCss = `@layer ${layer} {\n${css}\n}`;
183
+ // add layer to order in any case, even if the floor is not imported
182
184
  if (!uniqueLayers.includes(layer)) {
183
185
  uniqueLayers.push(layer);
184
186
  }
187
+ wrappedCss = `@layer ${layer} {\n${css}\n}`;
185
188
  }
186
189
  await fs.writeFile(outputFile, wrappedCss, 'utf8');
187
- floorFiles.push({ file: `${source}.css`, layer });
190
+ floorFiles.push({ file: `${source}.css`, layer, source });
188
191
  cssFiles.push({ floor: source, file: `${source}.css`, layer });
189
192
  }
190
193
  // 5. Create main CSS file
191
194
  const mainCssPath = path.join(outputPath, mainCssFile);
195
+ // Type guard for cssFiles entries with type 'global' or 'media'
196
+ function isGlobalOrMedia(f) {
197
+ return ((f.type === 'global' || f.type === 'media') && typeof f.file === 'string');
198
+ }
192
199
  // Compose imports for variable sets
193
- const varImports = cssFiles
194
- .filter((f) => f.type === 'global' || f.type === 'media')
195
- .map((f) => {
200
+ function toImportStatement(f) {
196
201
  if (f.mediaQuery) {
197
202
  return `@import '${f.file}' ${f.mediaQuery};`;
198
203
  }
199
204
  return `@import '${f.file}';`;
200
- })
205
+ }
206
+ const varImports = cssFiles.filter(isGlobalOrMedia)
207
+ .map(toImportStatement)
201
208
  .join('\n');
202
- // Compose imports for floors (in order)
203
- const floorImports = floorFiles.map((f) => `@import '${f.file}';`).join('\n');
209
+ // Compose imports for floors (in order, only those in importFloors)
210
+ function isImportedFloor(f) {
211
+ return importFloors.includes(f.source);
212
+ }
213
+ function importStatement(f) {
214
+ return `@import '${f.file}';`;
215
+ }
216
+ const importedFloorFiles = floorFiles.filter(isImportedFloor);
217
+ const floorImports = importedFloorFiles.map(importStatement).join('\n');
204
218
  const mainCss = [
205
219
  uniqueLayers.length ? `@layer ${uniqueLayers.join(', ')};` : '',
206
220
  floorImports,
@@ -85,6 +85,9 @@ export default {
85
85
  // Output
86
86
  mainCssFile: 'styles.css',
87
87
 
88
+ // floors to include in the main CSS file
89
+ importFloors: ['defaults', 'components', 'layout'],
90
+
88
91
  // CSS Variables configuration
89
92
  globalVariables: 'global',
90
93
  globalRootSelector: ':root',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esm-styles",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "A library for working with ESM styles",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",