import openImageViewer from "../openImageViewer.ts"
import { snackbar } from "../snackbar.ts"
import { $ } from 'mdui/jq'
customElements.define('chat-image', class extends HTMLElement {
constructor() {
super()
}
connectedCallback() {
this.style.display = 'block'
const e = new Image()
e.style.maxWidth = "100%"
e.style.maxHeight = "90%"
e.style.marginTop = '5px'
e.style.marginBottom = '5px'
e.style.borderRadius = "var(--mdui-shape-corner-medium)"
e.alt = $(this).attr('alt') || ""
e.onerror = () => {
const src = $(this).attr('src')
$(this).html(``)
$(this).attr('alt', '无法加载: ' + $(this).attr('alt'))
$(this).on('click', () => {
snackbar({
message: `图片 (${src}) 无法加载!`,
placement: 'top'
})
})
}
e.src = $(this).attr('src') as string
e.onclick = (event) => {
event.stopPropagation()
openImageViewer($(this).attr('src') as string)
}
this.appendChild(e)
}
})
document.body.appendChild(new DOMParser().parseFromString(`
`, 'text/html').body.firstChild as Node)