2024-01-12 04:17:51 +08:00
|
|
|
export class pre extends HTMLPreElement {
|
|
|
|
constructor() {
|
|
|
|
super()
|
|
|
|
}
|
|
|
|
static text(text) {
|
|
|
|
const pre = new this()
|
|
|
|
pre.textContent = text
|
|
|
|
return pre
|
|
|
|
}
|
|
|
|
w(width) {
|
|
|
|
this.style.width = `${width}px`
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
h(height) {
|
|
|
|
this.style.height = `${height}px`
|
2024-01-12 02:05:28 +08:00
|
|
|
return this
|
|
|
|
}
|
2024-01-12 04:17:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export class div extends HTMLDivElement {
|
|
|
|
constructor({ width = 0, height = 0 }) {
|
|
|
|
super()
|
|
|
|
this.style.width = `${width}px`
|
|
|
|
this.style.height = `${height}px`
|
|
|
|
}
|
2024-01-12 02:05:28 +08:00
|
|
|
|
2024-01-12 04:17:51 +08:00
|
|
|
static w(width) {
|
|
|
|
return new this({ width })
|
|
|
|
}
|
2024-01-12 02:05:28 +08:00
|
|
|
static h(height) {
|
2024-01-12 04:17:51 +08:00
|
|
|
return new this({ height })
|
|
|
|
}
|
|
|
|
|
|
|
|
w(width) {
|
|
|
|
this.style.width = `${width}px`
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
h(height) {
|
|
|
|
this.style.height = `${height}px`
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
text(text) {
|
|
|
|
this.textContent = text
|
2024-01-12 02:05:28 +08:00
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
static get onclick() {
|
|
|
|
console.log('onclick event')
|
|
|
|
return {
|
2024-01-12 02:18:19 +08:00
|
|
|
stop: function (event) {
|
2024-01-12 02:05:28 +08:00
|
|
|
console.log(`Stop event: ${event}`)
|
|
|
|
return div
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static get onkeydown() {
|
|
|
|
console.log('onkeydown event')
|
|
|
|
return {
|
2024-01-12 02:18:19 +08:00
|
|
|
esc: function () {
|
2024-01-12 02:05:28 +08:00
|
|
|
console.log('esc event')
|
|
|
|
return {
|
2024-01-12 02:18:19 +08:00
|
|
|
keydown: function () {
|
2024-01-12 02:05:28 +08:00
|
|
|
console.log('keydown event')
|
|
|
|
return div
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static classList(classes) {
|
|
|
|
console.log(`Classes: ${classes}`)
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
}
|
2024-01-12 02:18:19 +08:00
|
|
|
|
2024-01-12 04:17:51 +08:00
|
|
|
customElements.define('my-div', div, { extends: 'div' })
|
|
|
|
customElements.define('my-pre', pre, { extends: 'pre' })
|
2024-01-12 02:18:19 +08:00
|
|
|
|
2024-01-12 04:17:51 +08:00
|
|
|
//
|
|
|
|
//export class button extends div { }
|
|
|
|
//export class span extends div { }
|
|
|
|
//
|
|
|
|
//export class header extends div { }
|
|
|
|
//export class footer extends div { }
|
|
|
|
//export class main extends div { }
|
|
|
|
//
|
2024-01-12 02:18:19 +08:00
|
|
|
|
2024-01-12 04:17:51 +08:00
|
|
|
export default { div, pre }
|