@webmate-studio/builder 0.2.20 → 0.2.21

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 +22 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webmate-studio/builder",
3
- "version": "0.2.20",
3
+ "version": "0.2.21",
4
4
  "type": "module",
5
5
  "description": "Webmate Studio Component Builder",
6
6
  "keywords": [
@@ -32,8 +32,11 @@ export function cleanComponentHTML(html, islands = []) {
32
32
  }
33
33
 
34
34
  /**
35
- * Transform PascalCase island elements to data-island attributes
36
- * Example: <SwiperTest title={title} /> → <div data-island="swipertest" data-island-props='{"title":"{title}"}'></div>
35
+ * Transform PascalCase island elements to Custom Elements (Web Components)
36
+ * Example: <SwiperTest title={title} /> → <swiper-test title="{title}"></swiper-test>
37
+ *
38
+ * Islands with <svelte:options customElement> self-register as Custom Elements,
39
+ * so we convert to kebab-case tags with inline props.
37
40
  *
38
41
  * @param {string} html - Original HTML
39
42
  * @param {Array<string>} availableIslands - List of available island names
@@ -48,8 +51,16 @@ function transformIslandsToDataAttributes(html, availableIslands = []) {
48
51
  return match; // Not an island, keep as-is
49
52
  }
50
53
 
51
- // Parse attributes to JSON props
52
- const props = {};
54
+ // Convert island name to kebab-case for Custom Element tag
55
+ // SwiperTest swiper-test
56
+ // MyAwesomeComponent → my-awesome-component
57
+ const kebabTag = tagName
58
+ .replace(/([A-Z])/g, '-$1')
59
+ .toLowerCase()
60
+ .replace(/^-/, '');
61
+
62
+ // Parse attributes and convert to HTML attributes
63
+ const attrs = [];
53
64
 
54
65
  // Match prop={value} or prop="value" patterns
55
66
  const attrPattern = /([a-z][a-zA-Z0-9]*)\s*=\s*(?:\{([^}]+)\}|"([^"]*)"|'([^']*)')/g;
@@ -62,17 +73,15 @@ function transformIslandsToDataAttributes(html, availableIslands = []) {
62
73
 
63
74
  // If it was in curly braces, keep the braces for runtime evaluation
64
75
  // Otherwise it's a literal string
65
- props[propName] = attrMatch[2] ? `{${propValue}}` : propValue;
66
- }
76
+ const value = attrMatch[2] ? `{${propValue}}` : propValue;
67
77
 
68
- // Convert island name to lowercase for data-island attribute
69
- const islandName = tagName.toLowerCase();
70
-
71
- // Serialize props to JSON (escape quotes)
72
- const propsJson = JSON.stringify(props).replace(/"/g, '&quot;');
78
+ // Add as HTML attribute
79
+ attrs.push(`${propName}="${value}"`);
80
+ }
73
81
 
74
- // Generate data-island div
75
- return `<div data-island="${islandName}" data-island-props="${propsJson}"></div>`;
82
+ // Generate Custom Element tag
83
+ const attrsString = attrs.length > 0 ? ' ' + attrs.join(' ') : '';
84
+ return `<${kebabTag}${attrsString}></${kebabTag}>`;
76
85
  });
77
86
  }
78
87