File size: 19,774 Bytes
f88ef49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HTML/CSS to MAUI XAML Converter</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/atom-one-dark.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/languages/xml.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/languages/css.min.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        .editor-container {
            height: calc(100vh - 180px);
        }
        .editor-panel {
            height: 100%;
            overflow: auto;
        }
        .hljs {
            background: transparent !important;
        }
        .tab-button {
            transition: all 0.2s ease;
        }
        .tab-button.active {
            border-bottom: 3px solid #3b82f6;
            color: #3b82f6;
        }
        .copy-btn {
            opacity: 0;
            transition: opacity 0.2s ease;
        }
        .code-block:hover .copy-btn {
            opacity: 1;
        }
        .gradient-bg {
            background: linear-gradient(135deg, #6b46c1 0%, #3b82f6 100%);
        }
    </style>
</head>
<body class="bg-gray-100">
    <div class="gradient-bg text-white py-6 px-4 shadow-lg">
        <div class="container mx-auto">
            <div class="flex items-center justify-between">
                <div>
                    <h1 class="text-3xl font-bold"><i class="fas fa-code mr-2"></i>HTML/CSS to MAUI XAML</h1>
                    <p class="text-blue-100 mt-1">Convert your web UI to .NET MAUI XAML instantly</p>
                </div>
                <div class="flex space-x-2">
                    <button id="convertBtn" class="bg-white text-blue-600 px-6 py-2 rounded-lg font-semibold hover:bg-blue-50 transition flex items-center">
                        <i class="fas fa-sync-alt mr-2"></i> Convert
                    </button>
                    <button id="clearBtn" class="bg-blue-800 text-white px-4 py-2 rounded-lg font-semibold hover:bg-blue-700 transition flex items-center">
                        <i class="fas fa-trash-alt mr-2"></i> Clear
                    </button>
                </div>
            </div>
        </div>
    </div>

    <div class="container mx-auto px-4 mt-6">
        <div class="bg-white rounded-xl shadow-lg overflow-hidden">
            <div class="flex border-b">
                <button class="tab-button active px-6 py-3 font-medium text-gray-700" data-tab="input">
                    <i class="fas fa-code mr-2"></i>Input
                </button>
                <button class="tab-button px-6 py-3 font-medium text-gray-500" data-tab="output">
                    <i class="fas fa-file-code mr-2"></i>Output
                </button>
                <button class="tab-button px-6 py-3 font-medium text-gray-500" data-tab="preview">
                    <i class="fas fa-eye mr-2"></i>Preview
                </button>
            </div>

            <div class="editor-container flex">
                <!-- Input Panel -->
                <div id="input-panel" class="editor-panel w-1/2 border-r p-4">
                    <div class="mb-4">
                        <div class="flex justify-between items-center mb-2">
                            <h3 class="font-semibold text-gray-700"><i class="fas fa-html5 mr-2 text-orange-500"></i>HTML</h3>
                            <button class="copy-btn text-sm bg-gray-100 px-2 py-1 rounded" onclick="copyCode('html-editor')">
                                <i class="fas fa-copy mr-1"></i>Copy
                            </button>
                        </div>
                        <div class="relative">
                            <textarea id="html-editor" class="w-full h-64 p-3 font-mono text-sm border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="Paste your HTML here...">&lt;div class="p-4 bg-blue-100 rounded-lg"&gt;
  &lt;h1 class="text-2xl font-bold text-blue-800"&gt;Hello MAUI!&lt;/h1&gt;
  &lt;p class="text-blue-600 mt-2"&gt;This will be converted to XAML&lt;/p&gt;
  &lt;button class="mt-4 px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700"&gt;Click Me&lt;/button&gt;
&lt;/div&gt;</textarea>
                        </div>
                    </div>
                    <div>
                        <div class="flex justify-between items-center mb-2">
                            <h3 class="font-semibold text-gray-700"><i class="fas fa-css3-alt mr-2 text-blue-500"></i>CSS</h3>
                            <button class="copy-btn text-sm bg-gray-100 px-2 py-1 rounded" onclick="copyCode('css-editor')">
                                <i class="fas fa-copy mr-1"></i>Copy
                            </button>
                        </div>
                        <div class="relative">
                            <textarea id="css-editor" class="w-full h-32 p-3 font-mono text-sm border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="Paste your CSS here (optional)..."></textarea>
                        </div>
                    </div>
                </div>

                <!-- Output Panel -->
                <div id="output-panel" class="editor-panel w-1/2 p-4 hidden">
                    <div class="flex justify-between items-center mb-2">
                        <h3 class="font-semibold text-gray-700"><i class="fab fa-microsoft mr-2 text-purple-500"></i>MAUI XAML Output</h3>
                        <button class="copy-btn text-sm bg-gray-100 px-2 py-1 rounded" onclick="copyCode('xaml-output')">
                            <i class="fas fa-copy mr-1"></i>Copy
                        </button>
                    </div>
                    <div class="relative">
                        <pre id="xaml-output" class="p-3 bg-gray-50 rounded-lg h-full overflow-auto"><code class="language-xml">Your XAML output will appear here...</code></pre>
                    </div>
                </div>

                <!-- Preview Panel -->
                <div id="preview-panel" class="editor-panel w-1/2 p-4 hidden">
                    <div class="flex justify-between items-center mb-2">
                        <h3 class="font-semibold text-gray-700"><i class="fas fa-mobile-alt mr-2 text-green-500"></i>MAUI Preview</h3>
                        <div class="flex space-x-2">
                            <button id="ios-btn" class="text-sm bg-gray-100 px-2 py-1 rounded">
                                <i class="fab fa-apple mr-1"></i>iOS
                            </button>
                            <button id="android-btn" class="text-sm bg-gray-100 px-2 py-1 rounded">
                                <i class="fab fa-android mr-1"></i>Android
                            </button>
                        </div>
                    </div>
                    <div class="bg-gray-50 rounded-lg h-full overflow-auto flex items-center justify-center p-6">
                        <div id="preview-content" class="w-full max-w-md">
                            <div class="text-center text-gray-500">
                                <i class="fas fa-mobile-alt text-4xl mb-2"></i>
                                <p>Preview will appear here after conversion</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="mt-6 bg-white rounded-xl shadow-lg p-6">
            <h2 class="text-xl font-semibold text-gray-800 mb-4"><i class="fas fa-lightbulb mr-2 text-yellow-500"></i>Conversion Tips</h2>
            <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                <div class="bg-blue-50 p-4 rounded-lg">
                    <h3 class="font-medium text-blue-800 mb-2"><i class="fas fa-check-circle mr-2"></i>Supported</h3>
                    <ul class="text-sm text-blue-700 space-y-1">
                        <li>Basic HTML elements (div, span, etc.)</li>
                        <li>Tailwind-like classes (p-4, bg-blue-500)</li>
                        <li>Common CSS properties</li>
                        <li>Flexbox layouts</li>
                    </ul>
                </div>
                <div class="bg-yellow-50 p-4 rounded-lg">
                    <h3 class="font-medium text-yellow-800 mb-2"><i class="fas fa-exclamation-triangle mr-2"></i>Limited</h3>
                    <ul class="text-sm text-yellow-700 space-y-1">
                        <li>Complex CSS selectors</li>
                        <li>CSS Grid (use StackLayout instead)</li>
                        <li>CSS animations</li>
                        <li>Pseudo-classes (:hover, etc.)</li>
                    </ul>
                </div>
                <div class="bg-purple-50 p-4 rounded-lg">
                    <h3 class="font-medium text-purple-800 mb-2"><i class="fas fa-info-circle mr-2"></i>Best Practices</h3>
                    <ul class="text-sm text-purple-700 space-y-1">
                        <li>Use simple, flat HTML structures</li>
                        <li>Prefer Tailwind-like utility classes</li>
                        <li>Test in MAUI after conversion</li>
                        <li>Adjust margins/padding as needed</li>
                    </ul>
                </div>
            </div>
        </div>
    </div>

    <footer class="bg-gray-800 text-white py-6 mt-8">
        <div class="container mx-auto px-4 text-center">
            <p>HTML/CSS to MAUI XAML Converter Tool</p>
            <p class="text-gray-400 text-sm mt-2">Convert web UI components to native MAUI XAML with ease</p>
        </div>
    </footer>

    <script>
        // Initialize syntax highlighting
        hljs.highlightAll();

        // Tab switching
        const tabs = document.querySelectorAll('.tab-button');
        const panels = {
            'input': document.getElementById('input-panel'),
            'output': document.getElementById('output-panel'),
            'preview': document.getElementById('preview-panel')
        };

        tabs.forEach(tab => {
            tab.addEventListener('click', () => {
                // Update tab styles
                tabs.forEach(t => t.classList.remove('active', 'text-blue-600'));
                tab.classList.add('active', 'text-blue-600');
                
                // Show the selected panel
                const tabName = tab.getAttribute('data-tab');
                Object.values(panels).forEach(panel => panel.classList.add('hidden'));
                panels[tabName].classList.remove('hidden');
            });
        });

        // Copy code function
        function copyCode(elementId) {
            const element = document.getElementById(elementId);
            element.select();
            document.execCommand('copy');
            
            // Show feedback
            const originalText = element.nextElementSibling?.innerText;
            if (element.nextElementSibling) {
                element.nextElementSibling.innerHTML = '<i class="fas fa-check mr-1"></i>Copied!';
                setTimeout(() => {
                    element.nextElementSibling.innerHTML = originalText;
                }, 2000);
            }
        }

        // Convert HTML/CSS to MAUI XAML
        document.getElementById('convertBtn').addEventListener('click', () => {
            const html = document.getElementById('html-editor').value;
            const css = document.getElementById('css-editor').value;
            
            // Simple conversion logic (this would be more complex in a real app)
            let xaml = convertToXaml(html, css);
            
            // Display the XAML output
            const outputElement = document.getElementById('xaml-output');
            outputElement.innerHTML = hljs.highlight(xaml, {language: 'xml'}).value;
            
            // Update preview
            updatePreview(html, css);
            
            // Switch to output tab
            tabs[1].click();
        });

        // Clear all inputs
        document.getElementById('clearBtn').addEventListener('click', () => {
            document.getElementById('html-editor').value = '';
            document.getElementById('css-editor').value = '';
            document.getElementById('xaml-output').innerHTML = '<code class="language-xml">Your XAML output will appear here...</code>';
            document.getElementById('preview-content').innerHTML = `
                <div class="text-center text-gray-500">
                    <i class="fas fa-mobile-alt text-4xl mb-2"></i>
                    <p>Preview will appear here after conversion</p>
                </div>
            `;
        });

        // Simple conversion function (simplified for demo)
        function convertToXaml(html, css) {
            // This is a simplified conversion - a real converter would be much more sophisticated
            let xaml = `<?xml version="1.0" encoding="utf-8" ?>\n<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"\n             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"\n             x:Class="YourNamespace.YourPage">\n\n`;
            
            // Convert HTML to XAML
            let convertedHtml = html
                .replace(/class="/g, 'StyleClass="')
                .replace(/<div/g, '<VerticalStackLayout')
                .replace(/<\/div>/g, '</VerticalStackLayout>')
                .replace(/<span/g, '<Label')
                .replace(/<\/span>/g, '</Label>')
                .replace(/<button/g, '<Button')
                .replace(/<\/button>/g, '</Button>')
                .replace(/<h1/g, '<Label FontSize="24" FontAttributes="Bold"')
                .replace(/<h2/g, '<Label FontSize="20" FontAttributes="Bold"')
                .replace(/<h3/g, '<Label FontSize="18" FontAttributes="Bold"')
                .replace(/<p/g, '<Label')
                .replace(/<\/p>/g, '</Label>');
            
            // Add converted HTML to XAML
            xaml += `    ${convertedHtml}\n\n`;
            
            // Add resources for styles if CSS is provided
            if (css.trim()) {
                xaml += `    <ContentPage.Resources>\n        <ResourceDictionary>\n`;
                
                // Simple CSS to XAML style conversion (very basic)
                const styles = css.split('}').filter(rule => rule.trim());
                styles.forEach(rule => {
                    const [selector, properties] = rule.split('{');
                    if (selector && properties) {
                        const styleName = selector.trim().replace('.', '').replace(/\s+/g, '');
                        xaml += `            <Style x:Key="${styleName}" TargetType="View">\n`;
                        
                        const props = properties.split(';').filter(p => p.trim());
                        props.forEach(prop => {
                            const [key, value] = prop.split(':').map(p => p.trim());
                            if (key && value) {
                                // Convert CSS properties to XAML
                                if (key === 'background-color' || key === 'background') {
                                    xaml += `                <Setter Property="BackgroundColor" Value="${convertColor(value)}" />\n`;
                                } else if (key === 'color') {
                                    xaml += `                <Setter Property="TextColor" Value="${convertColor(value)}" />\n`;
                                } else if (key === 'font-size') {
                                    xaml += `                <Setter Property="FontSize" Value="${value.replace('px', '')}" />\n`;
                                } else if (key === 'font-weight') {
                                    xaml += `                <Setter Property="FontAttributes" Value="${value === 'bold' ? 'Bold' : 'None'}" />\n`;
                                } else if (key === 'margin') {
                                    xaml += `                <Setter Property="Margin" Value="${value.replace(' ', ',')}" />\n`;
                                } else if (key === 'padding') {
                                    xaml += `                <Setter Property="Padding" Value="${value.replace(' ', ',')}" />\n`;
                                }
                            }
                        });
                        
                        xaml += `            </Style>\n`;
                    }
                });
                
                xaml += `        </ResourceDictionary>\n    </ContentPage.Resources>\n`;
            }
            
            xaml += `</ContentPage>`;
            
            return xaml;
        }

        // Helper function to convert CSS colors to XAML colors
        function convertColor(cssColor) {
            if (cssColor.startsWith('#')) {
                return cssColor;
            } else if (cssColor.startsWith('rgb(')) {
                return `#${cssColor.match(/\d+/g).map(v => parseInt(v).toString(16).padStart(2, '0')).join('')}`;
            } else {
                // Map common color names
                const colorMap = {
                    'red': '#FF0000',
                    'blue': '#0000FF',
                    'green': '#008000',
                    'black': '#000000',
                    'white': '#FFFFFF',
                    'gray': '#808080',
                    'yellow': '#FFFF00',
                    'orange': '#FFA500',
                    'purple': '#800080'
                };
                return colorMap[cssColor] || '#000000';
            }
        }

        // Update preview panel
        function updatePreview(html, css) {
            const previewContent = document.getElementById('preview-content');
            
            // Create a style element for the CSS
            const style = document.createElement('style');
            style.textContent = css;
            
            // Create a container for the preview
            previewContent.innerHTML = `
                <div class="p-4">
                    ${html}
                </div>
            `;
            
            // Add the style to the preview
            previewContent.appendChild(style);
        }

        // Platform toggle buttons
        document.getElementById('ios-btn').addEventListener('click', () => {
            const preview = document.getElementById('preview-content');
            preview.className = 'ios-preview bg-white rounded-3xl p-6 shadow-lg w-full max-w-xs mx-auto border-8 border-gray-800';
        });

        document.getElementById('android-btn').addEventListener('click', () => {
            const preview = document.getElementById('preview-content');
            preview.className = 'android-preview bg-white rounded-xl p-6 shadow-lg w-full max-w-xs mx-auto border-4 border-green-500';
        });
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <a href="https://enzostvs-deepsite.hf.space" style="color: #fff;" target="_blank" >DeepSite</a> <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;"></p></body>
</html>