31 lines
867 B
Plaintext
31 lines
867 B
Plaintext
|
function splitSVGDefs(content, tag = "defs") {
|
||
|
let defs = "";
|
||
|
const index = content.indexOf("<" + tag);
|
||
|
while (index >= 0) {
|
||
|
const start = content.indexOf(">", index);
|
||
|
const end = content.indexOf("</" + tag);
|
||
|
if (start === -1 || end === -1) {
|
||
|
break;
|
||
|
}
|
||
|
const endEnd = content.indexOf(">", end);
|
||
|
if (endEnd === -1) {
|
||
|
break;
|
||
|
}
|
||
|
defs += content.slice(start + 1, end).trim();
|
||
|
content = content.slice(0, index).trim() + content.slice(endEnd + 1);
|
||
|
}
|
||
|
return {
|
||
|
defs,
|
||
|
content
|
||
|
};
|
||
|
}
|
||
|
function mergeDefsAndContent(defs, content) {
|
||
|
return defs ? "<defs>" + defs + "</defs>" + content : content;
|
||
|
}
|
||
|
function wrapSVGContent(body, start, end) {
|
||
|
const split = splitSVGDefs(body);
|
||
|
return mergeDefsAndContent(split.defs, start + split.content + end);
|
||
|
}
|
||
|
|
||
|
export { mergeDefsAndContent, splitSVGDefs, wrapSVGContent };
|