mirror of
https://github.com/andy-stack/vaultkeeper-ai.git
synced 2026-07-22 16:30:27 +00:00
Migrate attachment storage from base64-in-JSON to separate binary files with SHA-256 naming, add automatic garbage collection, implement lazy loading via getBase64() and getMimeType() methods, normalize text MIME types, add image resizing, and update all AI provider integrations. Fix small issue that caused the chat area to scroll down on message streaming end even when scrolled up.
35 lines
No EOL
1.2 KiB
TypeScript
35 lines
No EOL
1.2 KiB
TypeScript
export class HTMLService {
|
|
|
|
public clearElement(element: HTMLElement) {
|
|
element.empty();
|
|
}
|
|
|
|
public setHTMLContent(container: HTMLElement, htmlString: string) {
|
|
this.clearElement(container);
|
|
const fragment = this.parseHTMLString(htmlString);
|
|
container.appendChild(fragment);
|
|
}
|
|
|
|
public parseHTMLString(htmlString: string): DocumentFragment {
|
|
const parser = new DOMParser();
|
|
const fragment = document.createDocumentFragment();
|
|
const doc = parser.parseFromString(htmlString, "text/html");
|
|
|
|
// Transfer all nodes from the parsed body to the fragment
|
|
while (doc.body.firstChild) {
|
|
fragment.appendChild(doc.body.firstChild);
|
|
}
|
|
|
|
return fragment;
|
|
}
|
|
|
|
// Creates a temporary container, parses HTML, and returns the container.
|
|
// Useful for parsing HTML when you need to traverse the resulting DOM structure.
|
|
public parseHTMLToContainer(htmlString: string): HTMLDivElement {
|
|
const container = document.createElement("div");
|
|
const fragment = this.parseHTMLString(htmlString);
|
|
container.appendChild(fragment);
|
|
return container;
|
|
}
|
|
|
|
} |