MCPcopy
hub / github.com/clientIO/joint / parseFromSVGString

Function parseFromSVGString

packages/joint-decorators/src/parser.ts:22–46  ·  view source on GitHub ↗
(str: string)

Source from the content-addressed store, hash-verified

20}
21
22export function parseFromSVGString(str: string): SVGParserResult {
23
24 const parser = new DOMParser();
25 const type = 'text/html';
26 const document = parser.parseFromString(`<svg>${str.trim()}</svg>`, type);
27 const svg = document.querySelector('svg');
28 let root: Element;
29 if (svg.childElementCount === 1 && svg.firstElementChild.tagName === 'g') {
30 root = svg.firstElementChild;
31 } else {
32 root = svg;
33 }
34
35 const markup: dia.MarkupJSON = [];
36 const attrs = {};
37 const bindings: SVGParserBinding[] = [];
38
39 build(root, { selector: 'root', children: markup }, attrs, bindings);
40
41 return {
42 markup,
43 attrs,
44 bindings
45 };
46}
47
48// regex to identify whitespace:
49const spaceRegex = /[^\S\r\n]+/g;

Callers 1

ModelFunction · 0.90

Calls 1

buildFunction · 0.70

Tested by

no test coverage detected