File size: 4,218 Bytes
e9fb731
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
class CustomImageGenerator extends HTMLElement {
    constructor() {
        super();
        this.attachShadow({ mode: 'open' });
    }

    connectedCallback() {
        this.render();
    }

    static get observedAttributes() {
        return ['image-data'];
    }

    attributeChangedCallback(name, oldValue, newValue) {
        if (oldValue !== newValue) {
            this.render();
        }
    }

    render() {
        const imageData = this.getAttribute('image-data') || '';
        const hasImage = imageData !== '';

        this.shadowRoot.innerHTML = `
            <style>
                :host {
                    display: block;
                }
                
                .header {
                    display: flex;
                    align-items: center;
                    margin-bottom: 1.5rem;
                }
                
                .header i {
                    margin-right: 0.75rem;
                    color: #3b82f6;
                }
                
                .header h2 {
                    font-size: 1.25rem;
                    font-weight: 600;
                    color: #1e293b;
                }
                
                .image-container {
                    background-color: #f8fafc;
                    border-radius: 0.5rem;
                    padding: 1.5rem;
                    border: 1px solid #e2e8f0;
                    min-height: 300px;
                    display: flex;
                    flex-direction: column;
                    align-items: center;
                    justify-content: center;
                }
                
                .generated-image {
                    max-width: 100%;
                    border-radius: 0.375rem;
                    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
                }
                
                .placeholder {
                    text-align: center;
                    color: #64748b;
                }
                
                .placeholder i {
                    font-size: 3rem;
                    margin-bottom: 1rem;
                    color: #cbd5e1;
                }
                
                .image-actions {
                    display: flex;
                    margin-top: 1.5rem;
                    gap: 0.75rem;
                }
                
                .action-button {
                    padding: 0.5rem 1rem;
                    background-color: #3b82f6;
                    color: white;
                    border: none;
                    border-radius: 0.375rem;
                    cursor: pointer;
                    display: flex;
                    align-items: center;
                }
                
                .action-button i {
                    margin-right: 0.5rem;
                }
                
                .action-button.secondary {
                    background-color: #e2e8f0;
                    color: #1e293b;
                }
            </style>
            
            <div class="header">
                <i data-feather="image"></i>
                <h2>Visualisation du Thème</h2>
            </div>
            
            <div class="image-container">
                ${hasImage ? 
                    `<img src="${imageData}" alt="Generated theme preview" class="generated-image">` : 
                    `<div class="placeholder">
                        <i data-feather="image"></i>
                        <p>Générez un thème pour voir la prévisualisation</p>
                    </div>`
                }
            </div>
            
            ${hasImage ? `
            <div class="image-actions">
                <button class="action-button">
                    <i data-feather="download"></i>
                    Télécharger
                </button>
                <button class="action-button secondary">
                    <i data-feather="refresh-cw"></i>
                    Régénérer
                </button>
            </div>
            ` : ''}
        `;
        
        feather.replace();
    }
}

customElements.define('custom-image-generator', CustomImageGenerator);