feat: fancyBackgrounds in svg

This commit is contained in:
Arnošt Pleskot 2023-08-11 12:00:14 +02:00
parent 94f20566d1
commit e8cc787edc
No known key found for this signature in database
4 changed files with 106 additions and 16 deletions

View file

@ -123,3 +123,24 @@ export const normalizeSVG = async (SVGString: string) => {
return svg.outerHTML;
}
};
export const loadSVGElement = (filePath: string) => {
return new Promise<SVGSVGElement>((resolve, reject) => {
fetch(filePath)
.then((response) => response.text())
.then((svgString) => {
const parser = new DOMParser();
const svgDoc = parser.parseFromString(svgString, "image/svg+xml");
const svgElement = svgDoc.documentElement;
if (svgElement instanceof SVGSVGElement) {
resolve(svgElement);
} else {
reject(new Error("Parsed element is not an SVGSVGElement"));
}
})
.catch((error) => {
reject(error);
});
});
};