feat: base html sheet

This commit is contained in:
Matthieu CAILLEAUX
2022-04-26 21:11:35 +02:00
parent 986d50a5eb
commit b16967c351
16 changed files with 309 additions and 45 deletions

View File

@@ -21,6 +21,34 @@ export class Image extends Box {
return doc;
}
public renderHtml(
doc: Document,
parent: HTMLElement,
cssRules: string[],
sheet: HTMLStyleElement
): Document {
const img = doc.createElement('img');
img.src = this.imageData;
const css = `img-${this.w ?? 0}-${this.h ?? 0}`;
img.classList.add(`img`);
img.classList.add(css);
if (!cssRules.includes(css)) {
cssRules.push(css);
let rule = '';
if (this.w > 0) {
rule += `width: ${this.w}px;`;
}
if (this.h > 0) {
rule += `height: ${this.h}px;`;
}
if (rule.length > 0) {
sheet.innerHTML += ` .${css} { ${rule} }`;
}
}
parent.append(img);
return doc;
}
public getElements(): AbstractElement[] {
return [this];
}