@webmate-studio/builder 0.2.172 → 0.2.173

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.172",
3
+ "version": "0.2.173",
4
4
  "type": "module",
5
5
  "description": "Webmate Studio Component Builder",
6
6
  "keywords": [
@@ -234,6 +234,9 @@ export function extractStyles(html) {
234
234
  * @returns {string} Scoped CSS
235
235
  */
236
236
  export function scopeCSS(css, scopeAttr) {
237
+ // Strip CSS comments first to avoid parsing them as selectors
238
+ css = css.replace(/\/\*[\s\S]*?\*\//g, '');
239
+
237
240
  const scope = `[data-wmc-${scopeAttr}]`;
238
241
 
239
242
  // Element-only selectors that should be dropped (they target outside the component)
@@ -375,19 +378,11 @@ export function extractAndScopeStyles(html, componentId) {
375
378
  const suffix = getComponentSuffix(componentId);
376
379
  const scopedCss = scopeCSS(css, suffix);
377
380
 
378
- // Add data-wmc-{hash} attribute to the first root element
379
- const scopeAttr = `data-wmc-${suffix}`;
380
- const rootTagMatch = cleanHtml.match(/^(\s*<\w+)/);
381
- let scopedHtml = cleanHtml;
382
- if (rootTagMatch) {
383
- const firstTag = rootTagMatch[1];
384
- scopedHtml = cleanHtml.replace(firstTag, `${firstTag} ${scopeAttr}`);
385
- }
386
-
387
- console.log(`[HTML Cleaner] Extracted and scoped ${css.split('\n').length} lines of component CSS (scope: ${scopeAttr})`);
381
+ console.log(`[HTML Cleaner] Extracted and scoped ${css.split('\n').length} lines of component CSS (scope: data-wmc-${suffix})`);
388
382
 
389
383
  return {
390
- html: scopedHtml,
391
- scopedCss
384
+ html: cleanHtml,
385
+ scopedCss,
386
+ scopeAttribute: `data-wmc-${suffix}`
392
387
  };
393
388
  }