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
|
2024-04-11 03:12:50 +08:00
|
|
|
pre.style.backgroundColor = '#eee'
|
|
|
|
pre.style.padding = '1rem'
|
2024-01-12 04:17:51 +08:00
|
|
|
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 })
|
|
|
|
}
|
2024-04-11 03:12:50 +08:00
|
|
|
static absolute(absolute) {
|
|
|
|
return new this({ absolute })
|
|
|
|
}
|
2024-01-12 04:17:51 +08:00
|
|
|
|
|
|
|
w(width) {
|
|
|
|
this.style.width = `${width}px`
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
h(height) {
|
|
|
|
this.style.height = `${height}px`
|
|
|
|
return this
|
|
|
|
}
|
2024-04-11 03:12:50 +08:00
|
|
|
absolute({ top, left, right, bottom }) {
|
|
|
|
this.style.position = 'absolute'
|
|
|
|
if (top) this.style.top = top + 'px'
|
|
|
|
if (left) this.style.left = left + 'px'
|
|
|
|
if (right) this.style.right = right + 'px'
|
|
|
|
if (bottom) this.style.bottom = bottom + 'px'
|
|
|
|
return this
|
|
|
|
}
|
2024-01-12 04:17:51 +08:00
|
|
|
text(text) {
|
|
|
|
this.textContent = text
|
2024-01-12 02:05:28 +08:00
|
|
|
return this
|
|
|
|
}
|
2024-04-11 03:12:50 +08:00
|
|
|
click(callback) {
|
|
|
|
this.onclick = callback
|
|
|
|
return this
|
2024-01-12 02:05:28 +08:00
|
|
|
}
|
2024-04-11 03:12:50 +08:00
|
|
|
//static get onclick() {
|
|
|
|
// console.log('onclick event')
|
|
|
|
// return {
|
|
|
|
// stop: function (event) {
|
|
|
|
// console.log(`Stop event: ${event}`)
|
|
|
|
// return div
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|
2024-01-12 02:05:28 +08:00
|
|
|
|
|
|
|
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 }
|