class CustomCodeSnippet extends HTMLElement { constructor() { super(); this._title = this.getAttribute('title') || 'Code Snippet'; this._language = this.getAttribute('language') || 'javascript'; this._code = this.innerHTML.trim(); } static get observedAttributes() { return ['title', 'language', 'code']; } attributeChangedCallback(name, oldValue, newValue) { if (oldValue !== newValue) { this[`_${name}`] = newValue; this.render(); } } connectedCallback() { this.render(); } render() { this.attachShadow({ mode: 'open' }); this.shadowRoot.innerHTML = `
${this._title}
${this._language}
${this._code}
`; // Initialize feather icons within the shadow DOM const featherScript = document.createElement('script'); featherScript.src = 'https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js'; this.shadowRoot.appendChild(featherScript); featherScript.onload = () => { if (window.feather) { window.feather.replace({ class: 'snippet-btn-icon' }); } }; } } customElements.define('custom-code-snippet', CustomCodeSnippet);