@webmate-studio/builder 0.2.28 → 0.2.30

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/build-service.js CHANGED
@@ -219,11 +219,23 @@ async function buildComponent(payload) {
219
219
  console.log(`[Build Service] ✓ Transformed HTML: ${islandNames.length} island(s) → Custom Elements`);
220
220
  }
221
221
 
222
- // Generate CSS
222
+ // Generate CSS from HTML + Islands
223
223
  let css = '';
224
- if (transformedHtml) {
224
+ if (transformedHtml || bundledIslands.length > 0) {
225
225
  console.log('[Build Service] Generating CSS...');
226
- const cssResult = await generateComponentCSS(transformedHtml, {
226
+
227
+ // Combine HTML and island content for CSS scanning
228
+ let contentToScan = transformedHtml || '';
229
+
230
+ // Add island content (they contain Tailwind classes too!)
231
+ if (bundledIslands.length > 0) {
232
+ for (const island of bundledIslands) {
233
+ contentToScan += '\n' + island.content;
234
+ }
235
+ console.log(`[Build Service] Including ${bundledIslands.length} island(s) for CSS scanning`);
236
+ }
237
+
238
+ const cssResult = await generateComponentCSS(contentToScan, {
227
239
  designTokens: null,
228
240
  minify: true
229
241
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webmate-studio/builder",
3
- "version": "0.2.28",
3
+ "version": "0.2.30",
4
4
  "type": "module",
5
5
  "description": "Webmate Studio Component Builder",
6
6
  "keywords": [
package/src/build.js CHANGED
@@ -81,24 +81,26 @@ async function installComponentDependencies(componentDir, componentName) {
81
81
  * @returns {string} HTML with scoping attribute
82
82
  */
83
83
  function addScopingAttribute(html, componentName) {
84
- const dom = parseDocument(html);
85
84
  const scopeId = `wm-${componentName.toLowerCase().replace(/[^a-z0-9]/g, '-')}`;
86
85
 
87
- // Find first element (skip text nodes and comments)
88
- const rootElement = DomUtils.findOne((elem) => elem.type === 'tag', dom.children, true);
89
-
90
- if (rootElement) {
91
- // Add data-wm-component attribute
92
- if (!rootElement.attribs) {
93
- rootElement.attribs = {};
94
- }
95
- rootElement.attribs['data-wm-component'] = scopeId;
86
+ // Use regex to add attribute to first HTML element
87
+ // This preserves the original HTML syntax (including unquoted class: directives)
88
+ // Pattern: Match first opening tag, capture tag name and attributes, insert our attribute
89
+ const match = html.match(/^(\s*)(<([a-zA-Z][a-zA-Z0-9-]*)(\s+[^>]*)?(\/?)>)/);
90
+
91
+ if (match) {
92
+ const whitespace = match[1];
93
+ const fullTag = match[2];
94
+ const tagName = match[3];
95
+ const existingAttrs = match[4] || '';
96
+ const selfClosing = match[5] || '';
97
+
98
+ // Insert data-wm-component attribute
99
+ const newTag = `<${tagName} data-wm-component="${scopeId}"${existingAttrs}${selfClosing}>`;
100
+ return whitespace + newTag + html.substring(match[0].length);
96
101
  }
97
102
 
98
- return render(dom, {
99
- encodeEntities: false,
100
- selfClosingTags: true
101
- });
103
+ return html;
102
104
  }
103
105
 
104
106
  /**
@@ -11,24 +11,28 @@ import render from 'dom-serializer';
11
11
  * @returns {string} Cleaned HTML without wm: attributes
12
12
  */
13
13
  export function cleanComponentHTML(html, islands = []) {
14
- // Transform PascalCase island elements to data-island FIRST (before parsing)
14
+ // Transform PascalCase island elements to data-island FIRST
15
15
  if (islands && islands.length > 0) {
16
16
  html = transformIslandsToDataAttributes(html, islands);
17
17
  }
18
18
 
19
- const dom = parseDocument(html);
19
+ // Remove wm: attributes using regex (avoids htmlparser2 breaking class: directives)
20
+ // Remove metadata attributes: wm:component, wm:prop, wm:props, wm:schema, wm:description
21
+ html = html.replace(/\s+wm:(component|prop|props|schema|description)="[^"]*"/g, '');
22
+ html = html.replace(/\s+wm:(component|prop|props|schema|description)='[^']*'/g, '');
23
+ html = html.replace(/\s+wm:(component|prop|props|schema|description)=\{[^}]*\}/g, '');
24
+ html = html.replace(/\s+wm:(component|prop|props|schema|description)/g, '');
20
25
 
21
- // Remove all wm: attributes from all elements
22
- removeWmAttributes(dom);
26
+ // Remove standalone 'wm' attribute
27
+ html = html.replace(/\s+wm="[^"]*"/g, '');
28
+ html = html.replace(/\s+wm='[^']*'/g, '');
29
+ html = html.replace(/\s+wm(?=\s|>|\/)/g, '');
23
30
 
24
- // Remove <script wm:schema> tags
25
- removeSchemaScripts(dom);
31
+ // Remove <script wm:schema>, <script wm:description>, <script wm:props>, <script wm="">
32
+ html = html.replace(/<script[^>]*\s+wm:(schema|description|props)[^>]*>[\s\S]*?<\/script>/gi, '');
33
+ html = html.replace(/<script[^>]*\s+wm=""[^>]*>[\s\S]*?<\/script>/gi, '');
26
34
 
27
- // Serialize back to HTML
28
- return render(dom, {
29
- encodeEntities: false,
30
- selfClosingTags: true
31
- });
35
+ return html;
32
36
  }
33
37
 
34
38
  /**
@@ -167,28 +171,23 @@ function removeSchemaScripts(dom) {
167
171
  * @returns {Object} { html: string, css: string }
168
172
  */
169
173
  export function extractStyles(html) {
170
- const dom = parseDocument(html);
171
174
  let css = '';
172
175
 
173
- // Find all <style> tags
174
- const styleTags = DomUtils.findAll(
175
- (elem) => elem.name === 'style',
176
- dom.children
177
- );
178
-
179
- for (const styleTag of styleTags) {
180
- const styleContent = DomUtils.textContent(styleTag);
181
- css += styleContent + '\n';
176
+ // Extract all <style> tags using regex (avoids htmlparser2 breaking class: directives)
177
+ const styleTagPattern = /<style(\s[^>]*)?>(.*)(?:<\/style>)/gis;
178
+ let match;
179
+ const stylesToRemove = [];
182
180
 
183
- // Remove style tag from DOM
184
- DomUtils.removeElement(styleTag);
181
+ while ((match = styleTagPattern.exec(html)) !== null) {
182
+ css += match[2] + '\n';
183
+ stylesToRemove.push(match[0]);
185
184
  }
186
185
 
187
- // Serialize remaining HTML
188
- const cleanHtml = render(dom, {
189
- encodeEntities: false,
190
- selfClosingTags: true
191
- });
186
+ // Remove all <style> tags from HTML
187
+ let cleanHtml = html;
188
+ for (const styleTag of stylesToRemove) {
189
+ cleanHtml = cleanHtml.replace(styleTag, '');
190
+ }
192
191
 
193
192
  return {
194
193
  html: cleanHtml.trim(),