@iconify/tools 2.0.12 → 2.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/colors/attribs.cjs +30 -0
- package/lib/colors/attribs.d.ts +13 -10
- package/lib/colors/attribs.mjs +7 -13
- package/lib/colors/parse.cjs +269 -0
- package/lib/colors/parse.d.ts +15 -11
- package/lib/colors/parse.mjs +27 -31
- package/lib/colors/validate.cjs +52 -0
- package/lib/colors/validate.d.ts +11 -4
- package/lib/colors/validate.mjs +19 -6
- package/lib/css/parse.cjs +26 -0
- package/lib/css/parse.d.ts +3 -1
- package/lib/css/parse.mjs +8 -6
- package/lib/css/parser/error.cjs +25 -0
- package/lib/css/parser/error.d.ts +4 -2
- package/lib/css/parser/error.mjs +2 -4
- package/lib/css/parser/export.cjs +48 -0
- package/lib/css/parser/export.d.ts +5 -2
- package/lib/css/parser/export.mjs +4 -6
- package/lib/css/parser/strings.cjs +77 -0
- package/lib/css/parser/strings.d.ts +6 -3
- package/lib/css/parser/strings.mjs +4 -6
- package/lib/css/parser/text.cjs +135 -0
- package/lib/css/parser/text.d.ts +8 -5
- package/lib/css/parser/text.mjs +3 -8
- package/lib/css/parser/tokens.cjs +184 -0
- package/lib/css/parser/tokens.d.ts +6 -3
- package/lib/css/parser/tokens.mjs +7 -13
- package/lib/css/parser/tree.cjs +42 -0
- package/lib/css/parser/tree.d.ts +5 -2
- package/lib/css/parser/tree.mjs +2 -4
- package/lib/css/parser/types.cjs +2 -0
- package/lib/css/parser/types.d.ts +13 -11
- package/lib/css/parser/types.mjs +1 -0
- package/lib/download/api/cache.cjs +86 -0
- package/lib/download/api/cache.d.ts +8 -5
- package/lib/download/api/cache.mjs +14 -19
- package/lib/download/api/download.cjs +28 -0
- package/lib/download/api/download.d.ts +5 -2
- package/lib/download/api/download.mjs +8 -9
- package/lib/download/api/index.cjs +51 -0
- package/lib/download/api/index.d.ts +5 -2
- package/lib/download/api/index.mjs +8 -6
- package/lib/download/api/types.cjs +2 -0
- package/lib/download/api/types.d.ts +4 -2
- package/lib/download/api/types.mjs +1 -0
- package/lib/download/git/branch.cjs +22 -0
- package/lib/download/git/branch.d.ts +5 -2
- package/lib/download/git/branch.mjs +5 -5
- package/lib/download/git/hash.cjs +15 -0
- package/lib/download/git/hash.d.ts +5 -2
- package/lib/download/git/hash.mjs +5 -5
- package/lib/download/git/index.cjs +76 -0
- package/lib/download/git/index.d.ts +10 -8
- package/lib/download/git/index.mjs +42 -20
- package/lib/download/git/reset.cjs +41 -0
- package/lib/download/git/reset.d.ts +6 -0
- package/lib/download/git/reset.mjs +37 -0
- package/lib/download/github/hash.cjs +32 -0
- package/lib/download/github/hash.d.ts +5 -2
- package/lib/download/github/hash.mjs +10 -7
- package/lib/download/github/index.cjs +98 -0
- package/lib/download/github/index.d.ts +11 -9
- package/lib/download/github/index.mjs +23 -17
- package/lib/download/github/types.cjs +2 -0
- package/lib/download/github/types.d.ts +3 -1
- package/lib/download/github/types.mjs +1 -0
- package/lib/download/gitlab/hash.cjs +32 -0
- package/lib/download/gitlab/hash.d.ts +5 -2
- package/lib/download/gitlab/hash.mjs +10 -6
- package/lib/download/gitlab/index.cjs +98 -0
- package/lib/download/gitlab/index.d.ts +11 -9
- package/lib/download/gitlab/index.mjs +24 -18
- package/lib/download/gitlab/types.cjs +7 -0
- package/lib/download/gitlab/types.d.ts +4 -2
- package/lib/download/gitlab/types.mjs +3 -5
- package/lib/download/helpers/untar.cjs +14 -0
- package/lib/download/helpers/untar.d.ts +3 -1
- package/lib/download/helpers/untar.mjs +4 -5
- package/lib/download/helpers/unzip.cjs +19 -0
- package/lib/download/helpers/unzip.d.ts +3 -1
- package/lib/download/helpers/unzip.mjs +6 -7
- package/lib/download/index.cjs +64 -0
- package/lib/download/index.d.ts +18 -13
- package/lib/download/index.mjs +46 -19
- package/lib/download/npm/index.cjs +82 -0
- package/lib/download/npm/index.d.ts +10 -8
- package/lib/download/npm/index.mjs +16 -13
- package/lib/download/npm/types.cjs +2 -0
- package/lib/download/npm/types.d.ts +3 -1
- package/lib/download/npm/types.mjs +1 -0
- package/lib/download/npm/version.cjs +23 -0
- package/lib/download/npm/version.d.ts +7 -4
- package/lib/download/npm/version.mjs +8 -10
- package/lib/download/types/modified.cjs +2 -0
- package/lib/download/types/modified.d.ts +3 -1
- package/lib/download/types/modified.mjs +1 -0
- package/lib/download/types/sources.cjs +2 -0
- package/lib/download/types/sources.d.ts +4 -2
- package/lib/download/types/sources.mjs +1 -0
- package/lib/export/directory.cjs +45 -0
- package/lib/export/directory.d.ts +11 -4
- package/lib/export/directory.mjs +8 -8
- package/lib/export/helpers/custom-files.cjs +28 -0
- package/lib/export/helpers/custom-files.d.ts +4 -2
- package/lib/export/helpers/custom-files.mjs +8 -9
- package/lib/export/helpers/prepare.cjs +36 -0
- package/lib/export/helpers/prepare.d.ts +5 -3
- package/lib/export/helpers/prepare.mjs +7 -9
- package/lib/export/helpers/types-version.cjs +22 -0
- package/lib/export/helpers/types-version.d.ts +3 -1
- package/lib/export/helpers/types-version.mjs +15 -37
- package/lib/export/icon-package.cjs +59 -0
- package/lib/export/icon-package.d.ts +12 -5
- package/lib/export/icon-package.mjs +15 -16
- package/lib/export/json-package.cjs +133 -0
- package/lib/export/json-package.d.ts +12 -5
- package/lib/export/json-package.mjs +24 -22
- package/lib/icon-set/index.cjs +589 -0
- package/lib/icon-set/index.d.ts +9 -6
- package/lib/icon-set/index.mjs +47 -57
- package/lib/icon-set/match.cjs +58 -0
- package/lib/icon-set/match.d.ts +10 -3
- package/lib/icon-set/match.mjs +5 -6
- package/lib/icon-set/merge.cjs +83 -0
- package/lib/icon-set/merge.d.ts +9 -2
- package/lib/icon-set/merge.mjs +15 -10
- package/lib/icon-set/props.cjs +28 -0
- package/lib/icon-set/props.d.ts +8 -4
- package/lib/icon-set/props.mjs +9 -12
- package/lib/icon-set/types.cjs +2 -0
- package/lib/icon-set/types.d.ts +19 -17
- package/lib/icon-set/types.mjs +1 -0
- package/lib/import/directory.cjs +76 -0
- package/lib/import/directory.d.ts +11 -5
- package/lib/import/directory.mjs +36 -11
- package/lib/import/figma/index.cjs +105 -0
- package/lib/import/figma/index.d.ts +15 -5
- package/lib/import/figma/index.mjs +40 -13
- package/lib/import/figma/nodes.cjs +86 -0
- package/lib/import/figma/nodes.d.ts +13 -4
- package/lib/import/figma/nodes.mjs +6 -16
- package/lib/import/figma/query.cjs +218 -0
- package/lib/import/figma/query.d.ts +18 -9
- package/lib/import/figma/query.mjs +9 -12
- package/lib/import/figma/types/api.cjs +2 -0
- package/lib/import/figma/types/api.d.ts +8 -7
- package/lib/import/figma/types/api.mjs +1 -0
- package/lib/import/figma/types/nodes.cjs +2 -0
- package/lib/import/figma/types/nodes.d.ts +16 -9
- package/lib/import/figma/types/nodes.mjs +1 -0
- package/lib/import/figma/types/options.cjs +2 -0
- package/lib/import/figma/types/options.d.ts +17 -10
- package/lib/import/figma/types/options.mjs +1 -0
- package/lib/import/figma/types/result.cjs +2 -0
- package/lib/import/figma/types/result.d.ts +12 -5
- package/lib/import/figma/types/result.mjs +1 -0
- package/lib/index.cjs +137 -0
- package/lib/index.d.ts +65 -43
- package/lib/index.mjs +83 -92
- package/lib/misc/bump-version.cjs +17 -0
- package/lib/misc/bump-version.d.ts +3 -1
- package/lib/misc/bump-version.mjs +2 -4
- package/lib/misc/compare-dirs.cjs +75 -0
- package/lib/misc/compare-dirs.d.ts +4 -2
- package/lib/misc/compare-dirs.mjs +12 -12
- package/lib/misc/exec.cjs +25 -0
- package/lib/misc/exec.d.ts +6 -4
- package/lib/misc/exec.mjs +4 -5
- package/lib/misc/keyword.cjs +19 -0
- package/lib/misc/keyword.d.ts +3 -1
- package/lib/misc/keyword.mjs +2 -4
- package/lib/misc/scan.cjs +51 -0
- package/lib/misc/scan.d.ts +7 -6
- package/lib/misc/scan.mjs +6 -7
- package/lib/misc/write-json.cjs +11 -0
- package/lib/misc/write-json.d.ts +3 -1
- package/lib/misc/write-json.mjs +5 -6
- package/lib/optimise/flags.cjs +252 -0
- package/lib/optimise/flags.d.ts +7 -2
- package/lib/optimise/flags.mjs +18 -19
- package/lib/optimise/global-style.cjs +154 -0
- package/lib/optimise/global-style.d.ts +7 -2
- package/lib/optimise/global-style.mjs +68 -47
- package/lib/optimise/scale.cjs +26 -0
- package/lib/optimise/scale.d.ts +7 -2
- package/lib/optimise/scale.mjs +5 -5
- package/lib/optimise/svgo.cjs +83 -0
- package/lib/optimise/svgo.d.ts +10 -6
- package/lib/optimise/svgo.mjs +6 -9
- package/lib/svg/analyse/error.cjs +18 -0
- package/lib/svg/analyse/error.d.ts +5 -2
- package/lib/svg/analyse/error.mjs +2 -4
- package/lib/svg/analyse/types.cjs +2 -0
- package/lib/svg/analyse/types.d.ts +11 -11
- package/lib/svg/analyse/types.mjs +1 -0
- package/lib/svg/analyse.cjs +291 -0
- package/lib/svg/analyse.d.ts +8 -3
- package/lib/svg/analyse.mjs +15 -30
- package/lib/svg/cleanup/attribs.cjs +41 -0
- package/lib/svg/cleanup/attribs.d.ts +7 -2
- package/lib/svg/cleanup/attribs.mjs +6 -12
- package/lib/svg/cleanup/bad-tags.cjs +51 -0
- package/lib/svg/cleanup/bad-tags.d.ts +7 -2
- package/lib/svg/cleanup/bad-tags.mjs +10 -25
- package/lib/svg/cleanup/inline-style.cjs +64 -0
- package/lib/svg/cleanup/inline-style.d.ts +7 -2
- package/lib/svg/cleanup/inline-style.mjs +14 -19
- package/lib/svg/cleanup/root-svg.cjs +81 -0
- package/lib/svg/cleanup/root-svg.d.ts +7 -2
- package/lib/svg/cleanup/root-svg.mjs +7 -18
- package/lib/svg/cleanup/svgo-style.cjs +38 -0
- package/lib/svg/cleanup/svgo-style.d.ts +7 -2
- package/lib/svg/cleanup/svgo-style.mjs +16 -11
- package/lib/svg/cleanup.cjs +32 -0
- package/lib/svg/cleanup.d.ts +7 -2
- package/lib/svg/cleanup.mjs +21 -9
- package/lib/svg/data/attributes.cjs +355 -0
- package/lib/svg/data/attributes.d.ts +27 -25
- package/lib/svg/data/attributes.mjs +90 -115
- package/lib/svg/data/tags.cjs +137 -0
- package/lib/svg/data/tags.d.ts +25 -23
- package/lib/svg/data/tags.mjs +25 -49
- package/lib/svg/index.cjs +130 -0
- package/lib/svg/index.d.ts +16 -5
- package/lib/svg/index.mjs +48 -11
- package/lib/svg/parse-style.cjs +134 -0
- package/lib/svg/parse-style.d.ts +12 -8
- package/lib/svg/parse-style.mjs +11 -9
- package/lib/svg/parse.cjs +42 -0
- package/lib/svg/parse.d.ts +11 -7
- package/lib/svg/parse.mjs +2 -4
- package/package.json +102 -93
- package/lib/colors/attribs.js +0 -26
- package/lib/colors/parse.js +0 -341
- package/lib/colors/validate.js +0 -48
- package/lib/css/parse.js +0 -23
- package/lib/css/parser/error.js +0 -27
- package/lib/css/parser/export.js +0 -69
- package/lib/css/parser/strings.js +0 -93
- package/lib/css/parser/text.js +0 -171
- package/lib/css/parser/tokens.js +0 -200
- package/lib/css/parser/tree.js +0 -44
- package/lib/css/parser/types.js +0 -2
- package/lib/download/api/cache.js +0 -108
- package/lib/download/api/download.js +0 -27
- package/lib/download/api/index.js +0 -52
- package/lib/download/api/types.js +0 -2
- package/lib/download/git/branch.js +0 -22
- package/lib/download/git/hash.js +0 -14
- package/lib/download/git/index.js +0 -63
- package/lib/download/github/hash.js +0 -28
- package/lib/download/github/index.js +0 -116
- package/lib/download/github/types.js +0 -2
- package/lib/download/gitlab/hash.js +0 -27
- package/lib/download/gitlab/index.js +0 -115
- package/lib/download/gitlab/types.js +0 -7
- package/lib/download/helpers/untar.js +0 -14
- package/lib/download/helpers/unzip.js +0 -18
- package/lib/download/index.js +0 -27
- package/lib/download/npm/index.js +0 -91
- package/lib/download/npm/types.js +0 -2
- package/lib/download/npm/version.js +0 -27
- package/lib/download/types/modified.js +0 -2
- package/lib/download/types/sources.js +0 -2
- package/lib/export/directory.js +0 -52
- package/lib/export/helpers/custom-files.js +0 -32
- package/lib/export/helpers/prepare.js +0 -49
- package/lib/export/helpers/types-version.js +0 -12
- package/lib/export/icon-package.js +0 -77
- package/lib/export/json-package.js +0 -151
- package/lib/icon-set/index.js +0 -746
- package/lib/icon-set/match.js +0 -66
- package/lib/icon-set/merge.js +0 -90
- package/lib/icon-set/props.js +0 -33
- package/lib/icon-set/types.js +0 -2
- package/lib/import/directory.js +0 -59
- package/lib/import/figma/index.js +0 -90
- package/lib/import/figma/nodes.js +0 -108
- package/lib/import/figma/query.js +0 -244
- package/lib/import/figma/types/api.js +0 -12
- package/lib/import/figma/types/nodes.js +0 -2
- package/lib/import/figma/types/options.js +0 -2
- package/lib/import/figma/types/result.js +0 -2
- package/lib/index.js +0 -101
- package/lib/misc/bump-version.js +0 -19
- package/lib/misc/compare-dirs.js +0 -84
- package/lib/misc/exec.js +0 -26
- package/lib/misc/keyword.js +0 -31
- package/lib/misc/scan.js +0 -55
- package/lib/misc/write-json.js +0 -11
- package/lib/optimise/flags.js +0 -312
- package/lib/optimise/global-style.js +0 -158
- package/lib/optimise/scale.js +0 -42
- package/lib/optimise/svgo.js +0 -99
- package/lib/svg/analyse/error.js +0 -22
- package/lib/svg/analyse/types.js +0 -2
- package/lib/svg/analyse.js +0 -352
- package/lib/svg/cleanup/attribs.js +0 -51
- package/lib/svg/cleanup/bad-tags.js +0 -65
- package/lib/svg/cleanup/inline-style.js +0 -77
- package/lib/svg/cleanup/root-svg.js +0 -107
- package/lib/svg/cleanup/svgo-style.js +0 -35
- package/lib/svg/cleanup.js +0 -24
- package/lib/svg/data/attributes.js +0 -403
- package/lib/svg/data/tags.js +0 -188
- package/lib/svg/index.js +0 -125
- package/lib/svg/parse-style.js +0 -151
- package/lib/svg/parse.js +0 -49
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const svg_parse = require('./parse.cjs');
|
|
6
|
+
const svg_data_attributes = require('./data/attributes.cjs');
|
|
7
|
+
const svg_data_tags = require('./data/tags.cjs');
|
|
8
|
+
const svg_analyse_error = require('./analyse/error.cjs');
|
|
9
|
+
|
|
10
|
+
async function analyseSVGStructure(svg, options = {}) {
|
|
11
|
+
const fixErrors = options.fixErrors;
|
|
12
|
+
let root = svg.$svg(":root").get(0);
|
|
13
|
+
if (root._parsed) {
|
|
14
|
+
svg.load(svg.toString());
|
|
15
|
+
root = svg.$svg(":root").get(0);
|
|
16
|
+
}
|
|
17
|
+
root._parsed = true;
|
|
18
|
+
const cheerio = svg.$svg;
|
|
19
|
+
const elements = /* @__PURE__ */ new Map();
|
|
20
|
+
const ids = /* @__PURE__ */ Object.create(null);
|
|
21
|
+
let links = [];
|
|
22
|
+
function addID(element, id) {
|
|
23
|
+
if (ids[id]) {
|
|
24
|
+
throw new Error(`Duplicate id "${id}"`);
|
|
25
|
+
}
|
|
26
|
+
element._id = id;
|
|
27
|
+
ids[id] = element._index;
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
function gotElementWithID(element, id, isMask) {
|
|
31
|
+
addID(element, id);
|
|
32
|
+
if (!element._belongsTo) {
|
|
33
|
+
element._belongsTo = [];
|
|
34
|
+
}
|
|
35
|
+
element._belongsTo.push({
|
|
36
|
+
id,
|
|
37
|
+
isMask,
|
|
38
|
+
indexes: /* @__PURE__ */ new Set([element._index])
|
|
39
|
+
});
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
function gotReusableElement(item, isMask) {
|
|
43
|
+
const element = item.element;
|
|
44
|
+
const attribs = element.attribs;
|
|
45
|
+
const index2 = element._index;
|
|
46
|
+
const id = attribs["id"];
|
|
47
|
+
if (typeof id !== "string") {
|
|
48
|
+
const message = `Definition element ${svg_analyse_error.analyseTagError(element)} does not have id`;
|
|
49
|
+
if (fixErrors) {
|
|
50
|
+
item.removeNode = true;
|
|
51
|
+
item.testChildren = false;
|
|
52
|
+
console.warn(message);
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
throw new Error(message);
|
|
56
|
+
}
|
|
57
|
+
if (ids[id] && fixErrors) {
|
|
58
|
+
console.warn(`Duplicate id "${id}"`);
|
|
59
|
+
item.removeNode = true;
|
|
60
|
+
item.testChildren = false;
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
element._reusableElement = {
|
|
64
|
+
id,
|
|
65
|
+
isMask,
|
|
66
|
+
index: index2
|
|
67
|
+
};
|
|
68
|
+
gotElementWithID(element, id, isMask);
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
function gotElementReference(item, id, usedAsMask) {
|
|
72
|
+
const element = item.element;
|
|
73
|
+
const usedByIndex = element._index;
|
|
74
|
+
const link = {
|
|
75
|
+
id,
|
|
76
|
+
usedByIndex,
|
|
77
|
+
usedAsMask
|
|
78
|
+
};
|
|
79
|
+
links.push(link);
|
|
80
|
+
if (!element._linksTo) {
|
|
81
|
+
element._linksTo = [];
|
|
82
|
+
}
|
|
83
|
+
element._linksTo.push(link);
|
|
84
|
+
}
|
|
85
|
+
let index = 0;
|
|
86
|
+
await svg_parse.parseSVG(svg, (item) => {
|
|
87
|
+
const { tagName, parents } = item;
|
|
88
|
+
if (svg_data_tags.styleTag.has(tagName)) {
|
|
89
|
+
item.testChildren = false;
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const element = item.element;
|
|
93
|
+
const attribs = element.attribs;
|
|
94
|
+
index++;
|
|
95
|
+
element._index = index;
|
|
96
|
+
elements.set(index, element);
|
|
97
|
+
if (!parents.length) {
|
|
98
|
+
element._usedAsMask = false;
|
|
99
|
+
element._usedAsPaint = true;
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
element._usedAsMask = false;
|
|
103
|
+
element._usedAsPaint = false;
|
|
104
|
+
const parentItem = parents[0];
|
|
105
|
+
const parentElement = parentItem.element;
|
|
106
|
+
if (svg_data_tags.maskTags.has(tagName)) {
|
|
107
|
+
if (!gotReusableElement(item, true)) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
} else if (svg_data_tags.reusableElementsWithPalette.has(tagName)) {
|
|
111
|
+
if (!gotReusableElement(item, false)) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
} else if (svg_data_tags.defsTag.has(parentItem.tagName)) {
|
|
115
|
+
if (!gotReusableElement(item, false)) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
} else if (!svg_data_tags.defsTag.has(tagName)) {
|
|
119
|
+
element._usedAsMask = parentElement._usedAsMask;
|
|
120
|
+
element._usedAsPaint = parentElement._usedAsPaint;
|
|
121
|
+
element._parentElement = parentElement._index;
|
|
122
|
+
if (!parentElement._childElements) {
|
|
123
|
+
parentElement._childElements = [];
|
|
124
|
+
}
|
|
125
|
+
parentElement._childElements.push(index);
|
|
126
|
+
const parentReusableElement = parentElement._reusableElement;
|
|
127
|
+
if (parentReusableElement) {
|
|
128
|
+
if (element._reusableElement) {
|
|
129
|
+
throw new Error(`Reusable element ${svg_analyse_error.analyseTagError(element)} is inside another reusable element id="${parentReusableElement.id}"`);
|
|
130
|
+
}
|
|
131
|
+
element._reusableElement = parentReusableElement;
|
|
132
|
+
}
|
|
133
|
+
const parentBelongsTo = parentElement._belongsTo;
|
|
134
|
+
if (parentBelongsTo) {
|
|
135
|
+
const list = element._belongsTo || (element._belongsTo = []);
|
|
136
|
+
parentBelongsTo.forEach((item2) => {
|
|
137
|
+
item2.indexes.add(index);
|
|
138
|
+
list.push(item2);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
if (element._id === void 0) {
|
|
142
|
+
const id = attribs["id"];
|
|
143
|
+
if (typeof id === "string") {
|
|
144
|
+
if (ids[id] && fixErrors) {
|
|
145
|
+
console.warn(`Duplicate id "${id}"`);
|
|
146
|
+
cheerio(element).removeAttr("id");
|
|
147
|
+
} else {
|
|
148
|
+
gotElementWithID(element, id, false);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (svg_data_attributes.tagSpecificNonPresentationalAttributes[tagName]?.has("href")) {
|
|
154
|
+
const href = attribs["href"] || attribs["xlink:href"];
|
|
155
|
+
if (typeof href === "string") {
|
|
156
|
+
if (href.slice(0, 1) !== "#") {
|
|
157
|
+
throw new Error(`Invalid link in ${svg_analyse_error.analyseTagError(element)}`);
|
|
158
|
+
}
|
|
159
|
+
const id = href.slice(1);
|
|
160
|
+
gotElementReference(item, id, false);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
Object.keys(attribs).forEach((attr) => {
|
|
164
|
+
let value = attribs[attr];
|
|
165
|
+
if (value.slice(0, 5).toLowerCase() !== "url(#") {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
value = value.slice(5);
|
|
169
|
+
if (value.slice(-1) !== ")") {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const id = value.slice(0, value.length - 1).trim();
|
|
173
|
+
if (svg_data_attributes.urlPresentationalAttributes.has(attr)) {
|
|
174
|
+
gotElementReference(item, id, attr !== "filter");
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (svg_data_attributes.commonColorPresentationalAttributes.has(attr) || svg_data_attributes.markerAttributes.has(attr)) {
|
|
178
|
+
gotElementReference(item, id, false);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
links = links.filter((item) => {
|
|
184
|
+
const id = item.id;
|
|
185
|
+
if (ids[id]) {
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
function fix() {
|
|
189
|
+
const index2 = item.usedByIndex;
|
|
190
|
+
const element = elements.get(index2);
|
|
191
|
+
const tagName = element.tagName;
|
|
192
|
+
function remove() {
|
|
193
|
+
const $element = cheerio(element);
|
|
194
|
+
const parent = element.parent;
|
|
195
|
+
if (parent) {
|
|
196
|
+
if (parent._childElements) {
|
|
197
|
+
parent._childElements = parent._childElements.filter((num) => num !== index2);
|
|
198
|
+
}
|
|
199
|
+
parent._belongsTo?.forEach((list) => {
|
|
200
|
+
list.indexes.delete(index2);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
$element.remove();
|
|
204
|
+
}
|
|
205
|
+
if (element._linksTo) {
|
|
206
|
+
element._linksTo = element._linksTo.filter((item2) => item2.id !== id);
|
|
207
|
+
}
|
|
208
|
+
if (!element.children.length) {
|
|
209
|
+
if (svg_data_tags.useTag.has(tagName)) {
|
|
210
|
+
remove();
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
const matches = /* @__PURE__ */ new Set(["#" + id, "url(#" + id + ")"]);
|
|
215
|
+
const attribs = element.attribs;
|
|
216
|
+
for (const attr in attribs) {
|
|
217
|
+
if (matches.has(attribs[attr])) {
|
|
218
|
+
cheerio(element).removeAttr(attr);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
const message = `Missing element with id="${id}"`;
|
|
223
|
+
if (fixErrors) {
|
|
224
|
+
fix();
|
|
225
|
+
console.warn(message);
|
|
226
|
+
} else {
|
|
227
|
+
throw new Error(message);
|
|
228
|
+
}
|
|
229
|
+
return false;
|
|
230
|
+
});
|
|
231
|
+
function hasChildItem(tree2, child, canThrow) {
|
|
232
|
+
const item = tree2.children.find((item2) => item2.index === child.index && item2.usedAsMask === child.usedAsMask);
|
|
233
|
+
if (item && canThrow) {
|
|
234
|
+
throw new Error("Recursion");
|
|
235
|
+
}
|
|
236
|
+
return !!item;
|
|
237
|
+
}
|
|
238
|
+
const tree = {
|
|
239
|
+
index: 1,
|
|
240
|
+
usedAsMask: false,
|
|
241
|
+
children: []
|
|
242
|
+
};
|
|
243
|
+
function parseTreeItem(tree2, usedItems, inMask) {
|
|
244
|
+
const element = elements.get(tree2.index);
|
|
245
|
+
if (tree2.usedAsMask || inMask) {
|
|
246
|
+
element._usedAsMask = true;
|
|
247
|
+
inMask = true;
|
|
248
|
+
} else {
|
|
249
|
+
element._usedAsPaint = true;
|
|
250
|
+
}
|
|
251
|
+
usedItems = usedItems.slice(0);
|
|
252
|
+
usedItems.push(element._index);
|
|
253
|
+
element._childElements?.forEach((childIndex) => {
|
|
254
|
+
if (usedItems.indexOf(childIndex) !== -1) {
|
|
255
|
+
throw new Error("Recursion");
|
|
256
|
+
}
|
|
257
|
+
const childItem = {
|
|
258
|
+
index: childIndex,
|
|
259
|
+
usedAsMask: false,
|
|
260
|
+
children: [],
|
|
261
|
+
parent: tree2
|
|
262
|
+
};
|
|
263
|
+
tree2.children.push(childItem);
|
|
264
|
+
parseTreeItem(childItem, usedItems, inMask);
|
|
265
|
+
});
|
|
266
|
+
element._linksTo?.forEach((link) => {
|
|
267
|
+
const linkIndex = ids[link.id];
|
|
268
|
+
const usedAsMask = link.usedAsMask;
|
|
269
|
+
const childItem = {
|
|
270
|
+
index: linkIndex,
|
|
271
|
+
usedAsMask,
|
|
272
|
+
children: [],
|
|
273
|
+
parent: tree2
|
|
274
|
+
};
|
|
275
|
+
if (hasChildItem(tree2, childItem, false)) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
tree2.children.push(childItem);
|
|
279
|
+
parseTreeItem(childItem, usedItems, inMask || usedAsMask);
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
parseTreeItem(tree, [0], false);
|
|
283
|
+
return {
|
|
284
|
+
elements,
|
|
285
|
+
ids,
|
|
286
|
+
links,
|
|
287
|
+
tree
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
exports.analyseSVGStructure = analyseSVGStructure;
|
package/lib/svg/analyse.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { SVG } from './index.js';
|
|
2
|
+
import { AnalyseSVGStructureOptions, AnalyseSVGStructureResult } from './analyse/types.js';
|
|
3
|
+
import '@iconify/types';
|
|
4
|
+
import '@iconify/utils/lib/customisations';
|
|
5
|
+
|
|
3
6
|
/**
|
|
4
7
|
* Find all IDs, links, which elements use palette, which items aren't used
|
|
5
8
|
*
|
|
6
9
|
* Before running this function run cleanup functions to change inline style to attributes and fix attributes
|
|
7
10
|
*/
|
|
8
|
-
|
|
11
|
+
declare function analyseSVGStructure(svg: SVG, options?: AnalyseSVGStructureOptions): Promise<AnalyseSVGStructureResult>;
|
|
12
|
+
|
|
13
|
+
export { analyseSVGStructure };
|
package/lib/svg/analyse.mjs
CHANGED
|
@@ -1,19 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
tagSpecificNonPresentationalAttributes,
|
|
7
|
-
urlPresentationalAttributes
|
|
8
|
-
} from "./data/attributes.mjs";
|
|
9
|
-
import {
|
|
10
|
-
defsTag,
|
|
11
|
-
maskTags,
|
|
12
|
-
reusableElementsWithPalette,
|
|
13
|
-
styleTag,
|
|
14
|
-
useTag
|
|
15
|
-
} from "./data/tags.mjs";
|
|
16
|
-
import { analyseTagError } from "./analyse/error.mjs";
|
|
1
|
+
import { parseSVG } from './parse.mjs';
|
|
2
|
+
import { tagSpecificNonPresentationalAttributes, urlPresentationalAttributes, commonColorPresentationalAttributes, markerAttributes } from './data/attributes.mjs';
|
|
3
|
+
import { styleTag, maskTags, reusableElementsWithPalette, defsTag, useTag } from './data/tags.mjs';
|
|
4
|
+
import { analyseTagError } from './analyse/error.mjs';
|
|
5
|
+
|
|
17
6
|
async function analyseSVGStructure(svg, options = {}) {
|
|
18
7
|
const fixErrors = options.fixErrors;
|
|
19
8
|
let root = svg.$svg(":root").get(0);
|
|
@@ -23,8 +12,8 @@ async function analyseSVGStructure(svg, options = {}) {
|
|
|
23
12
|
}
|
|
24
13
|
root._parsed = true;
|
|
25
14
|
const cheerio = svg.$svg;
|
|
26
|
-
const elements = new Map();
|
|
27
|
-
const ids = Object.create(null);
|
|
15
|
+
const elements = /* @__PURE__ */ new Map();
|
|
16
|
+
const ids = /* @__PURE__ */ Object.create(null);
|
|
28
17
|
let links = [];
|
|
29
18
|
function addID(element, id) {
|
|
30
19
|
if (ids[id]) {
|
|
@@ -42,7 +31,7 @@ async function analyseSVGStructure(svg, options = {}) {
|
|
|
42
31
|
element._belongsTo.push({
|
|
43
32
|
id,
|
|
44
33
|
isMask,
|
|
45
|
-
indexes: new Set([element._index])
|
|
34
|
+
indexes: /* @__PURE__ */ new Set([element._index])
|
|
46
35
|
});
|
|
47
36
|
return;
|
|
48
37
|
}
|
|
@@ -91,7 +80,6 @@ async function analyseSVGStructure(svg, options = {}) {
|
|
|
91
80
|
}
|
|
92
81
|
let index = 0;
|
|
93
82
|
await parseSVG(svg, (item) => {
|
|
94
|
-
var _a;
|
|
95
83
|
const { tagName, parents } = item;
|
|
96
84
|
if (styleTag.has(tagName)) {
|
|
97
85
|
item.testChildren = false;
|
|
@@ -158,7 +146,7 @@ async function analyseSVGStructure(svg, options = {}) {
|
|
|
158
146
|
}
|
|
159
147
|
}
|
|
160
148
|
}
|
|
161
|
-
if (
|
|
149
|
+
if (tagSpecificNonPresentationalAttributes[tagName]?.has("href")) {
|
|
162
150
|
const href = attribs["href"] || attribs["xlink:href"];
|
|
163
151
|
if (typeof href === "string") {
|
|
164
152
|
if (href.slice(0, 1) !== "#") {
|
|
@@ -198,14 +186,13 @@ async function analyseSVGStructure(svg, options = {}) {
|
|
|
198
186
|
const element = elements.get(index2);
|
|
199
187
|
const tagName = element.tagName;
|
|
200
188
|
function remove() {
|
|
201
|
-
var _a;
|
|
202
189
|
const $element = cheerio(element);
|
|
203
190
|
const parent = element.parent;
|
|
204
191
|
if (parent) {
|
|
205
192
|
if (parent._childElements) {
|
|
206
193
|
parent._childElements = parent._childElements.filter((num) => num !== index2);
|
|
207
194
|
}
|
|
208
|
-
|
|
195
|
+
parent._belongsTo?.forEach((list) => {
|
|
209
196
|
list.indexes.delete(index2);
|
|
210
197
|
});
|
|
211
198
|
}
|
|
@@ -220,7 +207,7 @@ async function analyseSVGStructure(svg, options = {}) {
|
|
|
220
207
|
return;
|
|
221
208
|
}
|
|
222
209
|
}
|
|
223
|
-
const matches = new Set(["#" + id, "url(#" + id + ")"]);
|
|
210
|
+
const matches = /* @__PURE__ */ new Set(["#" + id, "url(#" + id + ")"]);
|
|
224
211
|
const attribs = element.attribs;
|
|
225
212
|
for (const attr in attribs) {
|
|
226
213
|
if (matches.has(attribs[attr])) {
|
|
@@ -250,7 +237,6 @@ async function analyseSVGStructure(svg, options = {}) {
|
|
|
250
237
|
children: []
|
|
251
238
|
};
|
|
252
239
|
function parseTreeItem(tree2, usedItems, inMask) {
|
|
253
|
-
var _a, _b;
|
|
254
240
|
const element = elements.get(tree2.index);
|
|
255
241
|
if (tree2.usedAsMask || inMask) {
|
|
256
242
|
element._usedAsMask = true;
|
|
@@ -260,7 +246,7 @@ async function analyseSVGStructure(svg, options = {}) {
|
|
|
260
246
|
}
|
|
261
247
|
usedItems = usedItems.slice(0);
|
|
262
248
|
usedItems.push(element._index);
|
|
263
|
-
|
|
249
|
+
element._childElements?.forEach((childIndex) => {
|
|
264
250
|
if (usedItems.indexOf(childIndex) !== -1) {
|
|
265
251
|
throw new Error("Recursion");
|
|
266
252
|
}
|
|
@@ -273,7 +259,7 @@ async function analyseSVGStructure(svg, options = {}) {
|
|
|
273
259
|
tree2.children.push(childItem);
|
|
274
260
|
parseTreeItem(childItem, usedItems, inMask);
|
|
275
261
|
});
|
|
276
|
-
|
|
262
|
+
element._linksTo?.forEach((link) => {
|
|
277
263
|
const linkIndex = ids[link.id];
|
|
278
264
|
const usedAsMask = link.usedAsMask;
|
|
279
265
|
const childItem = {
|
|
@@ -297,6 +283,5 @@ async function analyseSVGStructure(svg, options = {}) {
|
|
|
297
283
|
tree
|
|
298
284
|
};
|
|
299
285
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
};
|
|
286
|
+
|
|
287
|
+
export { analyseSVGStructure };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const svg_data_attributes = require('../data/attributes.cjs');
|
|
6
|
+
const svg_data_tags = require('../data/tags.cjs');
|
|
7
|
+
const svg_parse = require('../parse.cjs');
|
|
8
|
+
|
|
9
|
+
async function removeBadAttributes(svg) {
|
|
10
|
+
await svg_parse.parseSVG(svg, (item) => {
|
|
11
|
+
const tagName = item.tagName;
|
|
12
|
+
const attribs = item.element.attribs;
|
|
13
|
+
const $element = item.$element;
|
|
14
|
+
Object.keys(attribs).forEach((attr) => {
|
|
15
|
+
if (attr.slice(0, 2) === "on" || svg_data_attributes.badAttributes.has(attr) || svg_data_attributes.badSoftwareAttributes.has(attr) || svg_data_attributes.badAttributePrefixes.has(attr.split("-").shift())) {
|
|
16
|
+
$element.removeAttr(attr);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (svg_data_tags.defsTag.has(tagName) && !svg_data_attributes.tagSpecificPresentationalAttributes[tagName].has(attr)) {
|
|
20
|
+
$element.removeAttr(attr);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const nsParts = attr.split(":");
|
|
24
|
+
if (nsParts.length > 1) {
|
|
25
|
+
const namespace = nsParts.shift();
|
|
26
|
+
const newAttr = nsParts.join(":");
|
|
27
|
+
switch (namespace) {
|
|
28
|
+
case "xlink": {
|
|
29
|
+
if (attribs[newAttr] === void 0) {
|
|
30
|
+
$element.attr(newAttr, attribs[attr]);
|
|
31
|
+
}
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
$element.removeAttr(attr);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
exports.removeBadAttributes = removeBadAttributes;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { SVG } from '../index.js';
|
|
2
|
+
import '@iconify/types';
|
|
3
|
+
import '@iconify/utils/lib/customisations';
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
6
|
* Remove useless attributes
|
|
4
7
|
*/
|
|
5
|
-
|
|
8
|
+
declare function removeBadAttributes(svg: SVG): Promise<void>;
|
|
9
|
+
|
|
10
|
+
export { removeBadAttributes };
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
badSoftwareAttributes,
|
|
6
|
-
tagSpecificPresentationalAttributes
|
|
7
|
-
} from "../data/attributes.mjs";
|
|
8
|
-
import { defsTag } from "../data/tags.mjs";
|
|
9
|
-
import { parseSVG } from "../parse.mjs";
|
|
1
|
+
import { badAttributes, badSoftwareAttributes, badAttributePrefixes, tagSpecificPresentationalAttributes } from '../data/attributes.mjs';
|
|
2
|
+
import { defsTag } from '../data/tags.mjs';
|
|
3
|
+
import { parseSVG } from '../parse.mjs';
|
|
4
|
+
|
|
10
5
|
async function removeBadAttributes(svg) {
|
|
11
6
|
await parseSVG(svg, (item) => {
|
|
12
7
|
const tagName = item.tagName;
|
|
@@ -38,6 +33,5 @@ async function removeBadAttributes(svg) {
|
|
|
38
33
|
});
|
|
39
34
|
});
|
|
40
35
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
};
|
|
36
|
+
|
|
37
|
+
export { removeBadAttributes };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const svg_parse = require('../parse.cjs');
|
|
6
|
+
const svg_data_tags = require('../data/tags.cjs');
|
|
7
|
+
|
|
8
|
+
const requiredParentTags = /* @__PURE__ */ new Map();
|
|
9
|
+
requiredParentTags.set(/* @__PURE__ */ new Set(["feComponentTransfer"]), svg_data_tags.feComponentTransferChildTag);
|
|
10
|
+
requiredParentTags.set(/* @__PURE__ */ new Set(["feMerge"]), svg_data_tags.feMergeChildTags);
|
|
11
|
+
requiredParentTags.set(svg_data_tags.feLightningTags, svg_data_tags.feLightningChildTags);
|
|
12
|
+
requiredParentTags.set(svg_data_tags.filterTag, svg_data_tags.filterChildTags);
|
|
13
|
+
requiredParentTags.set(svg_data_tags.gradientTags, svg_data_tags.gradientChildTags);
|
|
14
|
+
requiredParentTags.set(/* @__PURE__ */ new Set(["animateMotion"]), svg_data_tags.animateMotionChildTags);
|
|
15
|
+
async function checkBadTags(svg) {
|
|
16
|
+
await svg_parse.parseSVG(svg, (item) => {
|
|
17
|
+
const tagName = item.tagName;
|
|
18
|
+
const $element = item.$element;
|
|
19
|
+
if (tagName === "svg") {
|
|
20
|
+
if (item.parents.length) {
|
|
21
|
+
throw new Error(`Unexpected element: <${tagName}>`);
|
|
22
|
+
}
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (svg_data_tags.unsupportedTags.has(tagName)) {
|
|
26
|
+
$element.remove();
|
|
27
|
+
item.testChildren = false;
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (svg_data_tags.badTags.has(tagName) || !svg_data_tags.allValidTags.has(tagName)) {
|
|
31
|
+
const parts = tagName.split(":");
|
|
32
|
+
if (parts.length > 1) {
|
|
33
|
+
$element.remove();
|
|
34
|
+
item.testChildren = false;
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
throw new Error(`Unexpected element: <${tagName}>`);
|
|
38
|
+
}
|
|
39
|
+
const parentTagName = item.parents[0]?.tagName;
|
|
40
|
+
for (const [parents, children] of requiredParentTags) {
|
|
41
|
+
if (children.has(tagName)) {
|
|
42
|
+
if (!parents.has(parentTagName)) {
|
|
43
|
+
throw new Error(`Element <${tagName}> has wrong parent element`);
|
|
44
|
+
}
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
exports.checkBadTags = checkBadTags;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { SVG } from '../index.js';
|
|
2
|
+
import '@iconify/types';
|
|
3
|
+
import '@iconify/utils/lib/customisations';
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
6
|
* Test for bag tags
|
|
4
7
|
*/
|
|
5
|
-
|
|
8
|
+
declare function checkBadTags(svg: SVG): Promise<void>;
|
|
9
|
+
|
|
10
|
+
export { checkBadTags };
|
|
@@ -1,29 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
feComponentTransferChildTag,
|
|
8
|
-
feLightningChildTags,
|
|
9
|
-
feLightningTags,
|
|
10
|
-
feMergeChildTags,
|
|
11
|
-
filterChildTags,
|
|
12
|
-
filterTag,
|
|
13
|
-
gradientChildTags,
|
|
14
|
-
gradientTags,
|
|
15
|
-
unsupportedTags
|
|
16
|
-
} from "../data/tags.mjs";
|
|
17
|
-
var requiredParentTags = new Map();
|
|
18
|
-
requiredParentTags.set(new Set(["feComponentTransfer"]), feComponentTransferChildTag);
|
|
19
|
-
requiredParentTags.set(new Set(["feMerge"]), feMergeChildTags);
|
|
1
|
+
import { parseSVG } from '../parse.mjs';
|
|
2
|
+
import { feComponentTransferChildTag, feMergeChildTags, feLightningTags, feLightningChildTags, filterTag, filterChildTags, gradientTags, gradientChildTags, animateMotionChildTags, unsupportedTags, badTags, allValidTags } from '../data/tags.mjs';
|
|
3
|
+
|
|
4
|
+
const requiredParentTags = /* @__PURE__ */ new Map();
|
|
5
|
+
requiredParentTags.set(/* @__PURE__ */ new Set(["feComponentTransfer"]), feComponentTransferChildTag);
|
|
6
|
+
requiredParentTags.set(/* @__PURE__ */ new Set(["feMerge"]), feMergeChildTags);
|
|
20
7
|
requiredParentTags.set(feLightningTags, feLightningChildTags);
|
|
21
8
|
requiredParentTags.set(filterTag, filterChildTags);
|
|
22
9
|
requiredParentTags.set(gradientTags, gradientChildTags);
|
|
23
|
-
requiredParentTags.set(new Set(["animateMotion"]), animateMotionChildTags);
|
|
10
|
+
requiredParentTags.set(/* @__PURE__ */ new Set(["animateMotion"]), animateMotionChildTags);
|
|
24
11
|
async function checkBadTags(svg) {
|
|
25
12
|
await parseSVG(svg, (item) => {
|
|
26
|
-
var _a;
|
|
27
13
|
const tagName = item.tagName;
|
|
28
14
|
const $element = item.$element;
|
|
29
15
|
if (tagName === "svg") {
|
|
@@ -46,7 +32,7 @@ async function checkBadTags(svg) {
|
|
|
46
32
|
}
|
|
47
33
|
throw new Error(`Unexpected element: <${tagName}>`);
|
|
48
34
|
}
|
|
49
|
-
const parentTagName =
|
|
35
|
+
const parentTagName = item.parents[0]?.tagName;
|
|
50
36
|
for (const [parents, children] of requiredParentTags) {
|
|
51
37
|
if (children.has(tagName)) {
|
|
52
38
|
if (!parents.has(parentTagName)) {
|
|
@@ -57,6 +43,5 @@ async function checkBadTags(svg) {
|
|
|
57
43
|
}
|
|
58
44
|
});
|
|
59
45
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
};
|
|
46
|
+
|
|
47
|
+
export { checkBadTags };
|