UNPKG

1.16 kBJavaScriptView Raw
1Object.defineProperty(exports, "__esModule", { value: true });
2var getVectorDefinitions = function (document) {
3 var map = new Map();
4 for (var _i = 0, _a = Array.from(document.querySelectorAll("svg > defs > *[id!='']")); _i < _a.length; _i++) {
5 var definition = _a[_i];
6 var identifier = definition.getAttribute('id');
7 if (identifier) {
8 map.set(identifier, definition.children.item(0));
9 }
10 }
11 return map;
12};
13exports.inlineVectorGraphics = function (document) {
14 var definitions = getVectorDefinitions(document);
15 var links = Array.from(document.querySelectorAll('svg > use'));
16 for (var _i = 0, links_1 = links; _i < links_1.length; _i++) {
17 var link = links_1[_i];
18 var identifier = link.getAttribute('xlink:href');
19 var matchingDefinition = definitions.get(identifier.split(/[#\/]/g).pop());
20 if (matchingDefinition == null) {
21 console.warn("Cannot find matching SVG definition for " + identifier);
22 continue;
23 }
24 link.parentElement.replaceChild(matchingDefinition.cloneNode(true), link);
25 }
26};
27//# sourceMappingURL=svg.js.map
\No newline at end of file