import { $ } from 'mdui/jq' customElements.define('chat-file', class extends HTMLElement { static observedAttributes = ['href', 'name'] declare anchor: HTMLAnchorElement declare span: HTMLSpanElement constructor() { super() this.attachShadow({ mode: 'open' }) } update() { if (this.anchor == null) return this.anchor.href = $(this).attr('href') as string this.anchor.download = $(this).attr('href') as string this.span.textContent = $(this).attr("name") as string } attributeChangedCallback(_name: string, _oldValue: unknown, _newValue: unknown) { this.update() } connectedCallback() { this.anchor = new DOMParser().parseFromString(` `, 'text/html').body.firstChild as HTMLAnchorElement this.span = $(this.anchor).find('span').get(0) this.anchor.style.textDecoration = 'none' this.anchor.style.color = 'inherit' this.anchor.onclick = (e) => { e.stopPropagation() } this.shadowRoot!.appendChild(this.anchor) this.update() } })