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

Function build

packages/joint-decorators/src/parser.ts:61–150  ·  view source on GitHub ↗
(node: Element, markup: Partial<dia.MarkupNodeJSON>, attrs: dia.Cell.Attributes, bindings: SVGParserBinding[])

Source from the content-addressed store, hash-verified

59let idCounter = 0;
60
61function build(node: Element, markup: Partial<dia.MarkupNodeJSON>, attrs: dia.Cell.Attributes, bindings: SVGParserBinding[]) {
62
63 const { tagName, attributes } = node;
64
65 let selector = markup.selector;
66 if (!selector) {
67 const selectorAttribute = attributes.getNamedItem('@selector');
68 selector = (selectorAttribute ? selectorAttribute.value : util.guid({}));
69 }
70
71 let groupSelector = markup.groupSelector;
72 if (!groupSelector) {
73 const groupSelectorAttribute = attributes.getNamedItem('@group-selector');
74 if (groupSelectorAttribute) {
75 groupSelector = groupSelectorAttribute.value.split(',').map(s => s.trim());
76 }
77 }
78
79 markup.selector = selector;
80 markup.groupSelector = groupSelector;
81 markup.tagName = tagName;
82
83 if (node.childElementCount === 0) {
84 const { textContent } = node;
85 if (cbRegex.test(textContent.replace(spaceRegex, ''))) {
86 if (tagName === 'text') {
87 node.setAttribute(':text', textContent);
88 } else {
89 throw new Error(`Text Interpolation within <${tagName}> is not supported yet.`);
90 }
91 } else if (textContent) {
92 if (tagName === 'text') {
93 node.setAttribute('text', textContent);
94 } else {
95 markup.textContent = textContent;
96 }
97 }
98 }
99 const nodeAttrs: attributes.SVGAttributes = {};
100
101 Array.from(attributes).forEach(nodeAttribute => {
102 const { name, value } = nodeAttribute;
103 if (name.startsWith('@')) {
104 // noop
105 } else if (name.startsWith(':')) {
106 const parseExpression = (id: string, attribute: string, context: string) => {
107 const path = attribute;
108
109 const [triggers, pathToBinding] = parsePathToBinding(path);
110
111 const binding: SVGParserBinding = {
112 ...pathToBinding,
113 id,
114 path: [`${selector}`, name.slice(1)],
115 expression: context,
116 triggers
117 };
118

Callers 1

parseFromSVGStringFunction · 0.70

Calls 4

parseExpressionFunction · 0.85
mapMethod · 0.80
keysMethod · 0.80
testMethod · 0.45

Tested by

no test coverage detected