export default class Image extends HTMLImageElement {
static genSVG(width: number, height: number, color: string) {
return `
`;
}
static toBase64(svgXml: string): string {
return `data:image/svg+xml;base64,${btoa(svgXml)}`;
}
constructor() {
super();
setTimeout(this.init, 0);
}
get width(): number {
return Number(this.getAttribute('width')) || 150;
}
get height(): number {
return Number(this.getAttribute('height')) || 150;
}
get color(): string {
return this.getAttribute('color') || '#ccc';
}
init = () => {
const svg = Image.genSVG(this.width, this.height, this.color);
this.src = Image.toBase64(svg);
};
}