乱了, 懒得说是什么

This commit is contained in:
CrescentLeaf
2026-01-02 01:27:32 +08:00
parent bc603b8171
commit d4557ca0ae
10 changed files with 60 additions and 20 deletions

View File

@@ -0,0 +1,24 @@
export default class InnerTextContainerElement extends HTMLElement {
static observedAttributes = ['text']
declare textContainer: HTMLDivElement
declare slotContainer: HTMLSlotElement
declare text?: string
constructor() {
super()
this.attachShadow({ mode: 'open' })
}
connectedCallback() {
this.shadowRoot!.appendChild(document.createElement('slot'))
}
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null) {
if (this.textContainer == null) {
this.textContainer = document.createElement('div')
// 注意这里不能加到 shadow
this.appendChild(this.textContainer)
this.textContainer.style.display = 'none'
}
this.textContainer.innerText = newValue || ''
}
}
customElements.define('inner-text-container', InnerTextContainerElement)