File size: 1,785 Bytes
657ff42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
class CodeExplainer extends HTMLElement {
  constructor() {
    super();
    this.attachShadow({ mode: 'open' });
    this.code = '';
    this.explanation = '';
  }

  connectedCallback() {
    this.render();
  }

  setCode(code, explanation) {
    this.code = code;
    this.explanation = explanation;
    this.render();
  }

  render() {
    this.shadowRoot.innerHTML = `
      <style>
        :host {
          display: block;
          width: 100%;
          height: 100%;
          background: var(--bg-color, #1e293b);
          color: var(--text-color, #f8fafc);
          padding: 1rem;
          box-sizing: border-box;
          overflow-y: auto;
        }
        h3 {
          margin: 0 0 1rem 0;
          font-size: 1.125rem;
          font-weight: 600;
        }
        .code-block {
          background: #0f172a;
          border-radius: 0.5rem;
          padding: 1rem;
          font-family: 'Courier New', monospace;
          font-size: 0.875rem;
          margin-bottom: 1rem;
          border: 1px solid #334155;
          white-space: pre-wrap;
        }
        .comment {
          color: #64748b;
        }
        .explanation {
          background: rgba(255, 255, 255, 0.05);
          border-radius: 0.5rem;
          padding: 1rem;
          font-size: 0.875rem;
          line-height: 1.5;
        }
      </style>
      <h3>Explication du code</h3>
      ${this.code ? `
        <div class="explanation">${this.explanation || "La Baleine a généré ce code, voici les explications :"}</div>
        <pre class="code-block">${this.code}</pre>
      ` : `
        <div class="explanation">Sélectionnez un projet ou générez du code pour voir les explications ici.</div>
      `}
    `;
  }
}

customElements.define('code-explainer', CodeExplainer);