* 将所有的 custom element 以正确的方式重新编写 * 可以正确解析 Markdown 文本, 图片, 斜体文本元素且不会杂糅了 * 通过 DOM 操作使得所有的文本聚合在一起, 并且取消了消息自带的填充边距, 删除了原本消息内无法正常工作的 "无边框显示模式" * 添加新的 custom-element: chat-text 和 chat-text-container
30 lines
915 B
TypeScript
30 lines
915 B
TypeScript
import { $ } from 'mdui'
|
|
|
|
customElements.define('chat-text', class extends HTMLElement {
|
|
declare span: HTMLSpanElement
|
|
static observedAttributes = ['underline', 'em']
|
|
constructor() {
|
|
super()
|
|
|
|
this.attachShadow({ mode: 'open' })
|
|
}
|
|
connectedCallback() {
|
|
const shadow = this.shadowRoot as ShadowRoot
|
|
|
|
this.span = document.createElement('span')
|
|
this.span.style.whiteSpace = 'pre-wrap'
|
|
this.span.style.fontSynthesis = 'style weight'
|
|
shadow.appendChild(this.span)
|
|
|
|
this.update()
|
|
}
|
|
attributeChangedCallback(_name: string, _oldValue: unknown, _newValue: unknown) {
|
|
this.update()
|
|
}
|
|
update() {
|
|
this.span.textContent = this.textContent
|
|
this.span.style.textDecoration = $(this).attr('underline') ? 'underline' : ''
|
|
this.span.style.fontStyle = $(this).attr('em') ? 'italic' : ''
|
|
}
|
|
})
|