class CodeVisualizer extends HTMLElement { constructor() { super(); this.attachShadow({ mode: 'open' }); this.code = ''; this.canvas = null; this.ctx = null; } connectedCallback() { this.render(); } setCode(code) { this.code = code; this.render(); this.visualizeCode(); } visualizeCode() { if (!this.code) return; try { // Create a temporary style element to apply the CSS const style = document.createElement('style'); style.textContent = this.code; document.head.appendChild(style); // Create a preview element to visualize the styles const preview = document.createElement('div'); preview.style.width = '100%'; preview.style.height = '100%'; preview.style.position = 'relative'; preview.innerHTML = `

Prévisualisation du thème

`; this.shadowRoot.getElementById('preview-container').innerHTML = ''; this.shadowRoot.getElementById('preview-container').appendChild(preview); // Remove the temporary style after visualization setTimeout(() => document.head.removeChild(style), 100); } catch (e) { console.error('Error visualizing code:', e); } } render() { this.shadowRoot.innerHTML = `

Visualisation

${this.code ? '' : `
Générer du code pour voir la visualisation ici
`}
`; } } customElements.define('code-visualizer', CodeVisualizer);