@webmate-studio/builder 0.2.172 → 0.2.174

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/html-cleaner.js +18 -18
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.174",
4
4
  "type": "module",
5
5
  "description": "Webmate Studio Component Builder",
6
6
  "keywords": [
@@ -81,18 +81,23 @@ function transformIslandsToDataAttributes(html, availableIslands = [], component
81
81
  return kebabTag;
82
82
  }
83
83
 
84
- // Parse attributes string into HTML attributes
84
+ // Parse attributes string into a data-island-props JSON attribute.
85
+ // This preserves camelCase prop names (HTML attributes are case-insensitive
86
+ // and get lowercased by the browser, breaking camelCase like bgGray → bggray).
85
87
  function parseAttrs(attrsString) {
86
- const attrs = [];
87
- const attrPattern = /([a-z][a-zA-Z0-9]*)\s*=\s*(?:\{([^}]+)\}|"([^"]*)"|'([^']*)')/g;
88
+ const props = {};
89
+ const attrPattern = /([a-zA-Z][a-zA-Z0-9]*)\s*=\s*(?:\{([^}]+)\}|"([^"]*)"|'([^']*)')/g;
88
90
  let attrMatch;
89
91
  while ((attrMatch = attrPattern.exec(attrsString)) !== null) {
90
92
  const propName = attrMatch[1];
91
93
  const propValue = attrMatch[2] || attrMatch[3] || attrMatch[4];
92
- const value = attrMatch[2] ? `{${propValue}}` : propValue;
93
- attrs.push(`${propName}="${value}"`);
94
+ // For {expression} values, wrap in braces to signal runtime evaluation
95
+ props[propName] = attrMatch[2] ? `{${propValue}}` : propValue;
94
96
  }
95
- return attrs.length > 0 ? ' ' + attrs.join(' ') : '';
97
+ if (Object.keys(props).length === 0) return '';
98
+ // Encode as JSON in data-island-props (preserves camelCase)
99
+ const json = JSON.stringify(props).replace(/"/g, '"');
100
+ return ` data-island-props="${json}"`;
96
101
  }
97
102
 
98
103
  // 1. Self-closing: <ComponentName attrs... />
@@ -234,6 +239,9 @@ export function extractStyles(html) {
234
239
  * @returns {string} Scoped CSS
235
240
  */
236
241
  export function scopeCSS(css, scopeAttr) {
242
+ // Strip CSS comments first to avoid parsing them as selectors
243
+ css = css.replace(/\/\*[\s\S]*?\*\//g, '');
244
+
237
245
  const scope = `[data-wmc-${scopeAttr}]`;
238
246
 
239
247
  // Element-only selectors that should be dropped (they target outside the component)
@@ -375,19 +383,11 @@ export function extractAndScopeStyles(html, componentId) {
375
383
  const suffix = getComponentSuffix(componentId);
376
384
  const scopedCss = scopeCSS(css, suffix);
377
385
 
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})`);
386
+ console.log(`[HTML Cleaner] Extracted and scoped ${css.split('\n').length} lines of component CSS (scope: data-wmc-${suffix})`);
388
387
 
389
388
  return {
390
- html: scopedHtml,
391
- scopedCss
389
+ html: cleanHtml,
390
+ scopedCss,
391
+ scopeAttribute: `data-wmc-${suffix}`
392
392
  };
393
393
  }