@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 +15 -3
- package/package.json +1 -1
- package/src/build.js +16 -14
- package/src/html-cleaner.js +27 -28
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
|
-
|
|
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
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
|
-
//
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
|
99
|
-
encodeEntities: false,
|
|
100
|
-
selfClosingTags: true
|
|
101
|
-
});
|
|
103
|
+
return html;
|
|
102
104
|
}
|
|
103
105
|
|
|
104
106
|
/**
|
package/src/html-cleaner.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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
|
|
22
|
-
|
|
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>
|
|
25
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
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
|
-
|
|
184
|
-
|
|
181
|
+
while ((match = styleTagPattern.exec(html)) !== null) {
|
|
182
|
+
css += match[2] + '\n';
|
|
183
|
+
stylesToRemove.push(match[0]);
|
|
185
184
|
}
|
|
186
185
|
|
|
187
|
-
//
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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(),
|