js/page/filesize.js

30 lines
548 B
JavaScript

import {text, html} from '../skooma.js'
import element from "/element.js"
element(class FileSize extends HTMLElement {
static attributes = {file: true}
constructor() {
super()
this.attachShadow({mode: "open"})
}
connectedCallback() {
this.update()
}
fileChanged() {
this.update()
}
update() {
if (this.file) {
fetch(this.file)
.then(response=>response.arrayBuffer())
.then(buffer => buffer.byteLength)
.then(length => {
this.shadowRoot.replaceChildren(text`(${length} Bytes unminified)`)
})
}
}
})