@webmate-studio/builder 0.2.87 → 0.2.89

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.87",
3
+ "version": "0.2.89",
4
4
  "type": "module",
5
5
  "description": "Webmate Studio Component Builder",
6
6
  "keywords": [
@@ -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,20 +428,24 @@ ${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 stripping: ${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
440
 
415
- // Wrap in @layer components (btn, etc. are components, not utilities)
416
- // Utilities from design tokens (@layer utilities) can then override them
441
+ // Wrap stripped utilities in @layer components
417
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);
418
449
  }
419
450
 
420
451
  return result;