@webmate-studio/builder 0.2.88 → 0.2.90

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@webmate-studio/builder",
3
- "version": "0.2.88",
3
+ "version": "0.2.90",
4
4
  "type": "module",
5
5
  "description": "Webmate Studio Component Builder",
6
6
  "keywords": [
@@ -66,7 +66,8 @@ export function deduplicateCSS(cssArray) {
66
66
  base: new Set(),
67
67
  properties: new Set(),
68
68
  theme: new Set(),
69
- utilities: new Set()
69
+ components: new Set(), // Component utilities (wrapped from utilities layer)
70
+ utilities: new Set() // Design token utilities (should override components)
70
71
  };
71
72
  const regularRules = {
72
73
  charset: [], // @charset declarations
@@ -157,6 +158,9 @@ export function deduplicateCSS(cssArray) {
157
158
  parts.push(...regularRules.imports);
158
159
  }
159
160
 
161
+ // Layer order declaration (MUST be first to define precedence)
162
+ parts.push('@layer base, components, utilities;');
163
+
160
164
  // Tailwind layers in correct order
161
165
  if (tailwindLayers.base.size > 0) {
162
166
  parts.push(`@layer base {\n${Array.from(tailwindLayers.base).join('\n\n')}\n}`);
@@ -167,6 +171,11 @@ export function deduplicateCSS(cssArray) {
167
171
  if (tailwindLayers.theme.size > 0) {
168
172
  parts.push(`@layer theme {\n${Array.from(tailwindLayers.theme).join('\n\n')}\n}`);
169
173
  }
174
+ if (tailwindLayers.components.size > 0) {
175
+ // Sort component utilities by breakpoint before joining
176
+ const sortedComponents = sortUtilityRules(Array.from(tailwindLayers.components));
177
+ parts.push(`@layer components {\n${sortedComponents.join('\n\n')}\n}`);
178
+ }
170
179
  if (tailwindLayers.utilities.size > 0) {
171
180
  // Sort utilities by breakpoint before joining
172
181
  const sortedUtilities = sortUtilityRules(Array.from(tailwindLayers.utilities));
@@ -1010,10 +1010,8 @@ export function generateTailwindConfig(tokens) {
1010
1010
  export function generateCSSFromTokens(tokens) {
1011
1011
  const lines = [];
1012
1012
 
1013
- // Define layer order FIRST (before any other CSS)
1014
- lines.push('/* CSS Layer Order Declaration */');
1015
- lines.push('@layer base, components, utilities;');
1016
- lines.push('');
1013
+ // NOTE: @layer order declaration is now handled by css-deduplicator.js
1014
+ // to ensure it appears only once and in the correct position
1017
1015
  lines.push(':root {');
1018
1016
 
1019
1017
  // Colors
@@ -68,6 +68,33 @@ function stripNonUtilityLayers(css) {
68
68
  return css.trim();
69
69
  }
70
70
 
71
+ /**
72
+ * Wraps utility classes in @layer components, preserving base/theme/properties layers
73
+ * This allows design token utilities (@layer utilities) to override component utilities
74
+ * @param {string} css - Full Tailwind CSS
75
+ * @returns {string} CSS with utilities wrapped in @layer components
76
+ */
77
+ function wrapUtilitiesInComponentsLayer(css) {
78
+ // Extract @layer utilities content
79
+ const utilitiesMatch = css.match(/@layer\s+utilities\s*\{([\s\S]*?)\n\}/);
80
+
81
+ if (!utilitiesMatch) {
82
+ console.log('[Tailwind Generator] No @layer utilities found, returning CSS as-is');
83
+ return css;
84
+ }
85
+
86
+ const utilitiesContent = utilitiesMatch[1].trim();
87
+
88
+ // Replace @layer utilities with @layer components
89
+ const result = css.replace(
90
+ /@layer\s+utilities\s*\{[\s\S]*?\n\}/,
91
+ `@layer components {\n${utilitiesContent}\n}`
92
+ );
93
+
94
+ console.log('[Tailwind Generator] Wrapped utilities in @layer components');
95
+ return result;
96
+ }
97
+
71
98
  /**
72
99
  * Extract Tailwind classes from HTML content
73
100
  * Supports: class="...", class='...', class={...}, and Svelte's class:xxx={...}
@@ -401,23 +428,25 @@ ${themeCSS}
401
428
  let result = await compiler.build(classArray);
402
429
 
403
430
  console.log(`[Tailwind Generator] includeBaseLayers = ${includeBaseLayers}`);
404
- console.log(`[Tailwind Generator] Generated CSS length BEFORE processing: ${result.length}`);
431
+ console.log(`[Tailwind Generator] Generated CSS length: ${result.length}`);
405
432
  console.log(`[Tailwind Generator] CSS contains @layer base: ${result.includes('@layer base')}`);
406
- console.log(`[Tailwind Generator] CSS contains @layer theme: ${result.includes('@layer theme')}`);
433
+ console.log(`[Tailwind Generator] CSS contains @layer utilities: ${result.includes('@layer utilities')}`);
407
434
 
408
- // If includeBaseLayers is false, strip out base/theme/properties layers
435
+ // If includeBaseLayers is false, strip out base/theme/properties layers and return unwrapped utilities
409
436
  if (!includeBaseLayers) {
410
437
  console.log('[Tailwind Generator] Stripping non-utility layers...');
411
438
  result = stripNonUtilityLayers(result);
412
439
  console.log(`[Tailwind Generator] Generated CSS length AFTER stripping: ${result.length}`);
413
- console.log(`[Tailwind Generator] CSS contains @layer base: ${result.includes('@layer base')}`);
414
- }
415
440
 
416
- // ALWAYS wrap component CSS in @layer components
417
- // This ensures utilities from design tokens (@layer utilities) can override them
418
- // Even if base layers are included, component-specific CSS should be in @layer components
419
- console.log('[Tailwind Generator] Wrapping in @layer components...');
420
- result = `@layer components {\n${result}\n}`;
441
+ // Wrap stripped utilities in @layer components
442
+ result = `@layer components {\n${result}\n}`;
443
+ console.log('[Tailwind Generator] Wrapped stripped utilities in @layer components');
444
+ } else {
445
+ // Keep base/theme/properties layers, but wrap utilities in @layer components
446
+ // This preserves CSS custom properties while allowing utilities override
447
+ console.log('[Tailwind Generator] Preserving base/theme/properties, wrapping utilities in @layer components...');
448
+ result = wrapUtilitiesInComponentsLayer(result);
449
+ }
421
450
 
422
451
  return result;
423
452