@iconify/tools 2.0.9 → 2.0.13
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/parse.d.ts +19 -3
- package/lib/colors/parse.js +109 -40
- package/lib/colors/parse.mjs +86 -39
- package/lib/colors/validate.js +5 -2
- package/lib/colors/validate.mjs +3 -1
- package/lib/download/git/index.js +12 -0
- package/lib/download/git/index.mjs +7 -0
- package/lib/download/git/reset.d.ts +4 -0
- package/lib/download/git/reset.js +16 -0
- package/lib/download/git/reset.mjs +13 -0
- package/lib/export/json-package.js +6 -1
- package/lib/export/json-package.mjs +4 -1
- package/lib/icon-set/index.js +11 -25
- package/lib/icon-set/index.mjs +13 -25
- package/lib/icon-set/merge.js +0 -1
- package/lib/icon-set/merge.mjs +1 -2
- package/lib/icon-set/props.d.ts +1 -1
- package/lib/icon-set/props.js +3 -2
- package/lib/icon-set/props.mjs +2 -2
- package/lib/icon-set/types.d.ts +3 -1
- package/lib/import/figma/nodes.js +3 -5
- package/lib/import/figma/nodes.mjs +3 -5
- package/lib/index.d.ts +3 -0
- package/lib/index.js +7 -1
- package/lib/index.mjs +6 -0
- package/lib/optimise/flags.js +9 -0
- package/lib/optimise/flags.mjs +8 -0
- package/lib/optimise/global-style.d.ts +5 -0
- package/lib/optimise/global-style.js +158 -0
- package/lib/optimise/global-style.mjs +129 -0
- package/lib/svg/analyse/error.d.ts +5 -0
- package/lib/svg/analyse/error.js +22 -0
- package/lib/svg/analyse/error.mjs +16 -0
- package/lib/svg/analyse/types.d.ts +89 -0
- package/lib/svg/analyse/types.js +2 -0
- package/lib/svg/analyse/types.mjs +0 -0
- package/lib/svg/analyse.d.ts +8 -0
- package/lib/svg/analyse.js +352 -0
- package/lib/svg/analyse.mjs +302 -0
- package/lib/svg/cleanup/attribs.d.ts +1 -1
- package/lib/svg/cleanup/attribs.js +8 -0
- package/lib/svg/cleanup/attribs.mjs +8 -1
- package/lib/svg/cleanup/bad-tags.d.ts +1 -1
- package/lib/svg/cleanup/bad-tags.js +0 -2
- package/lib/svg/cleanup/bad-tags.mjs +0 -3
- package/lib/svg/cleanup/inline-style.d.ts +1 -1
- package/lib/svg/cleanup/root-svg.d.ts +1 -1
- package/lib/svg/cleanup/root-svg.js +4 -2
- package/lib/svg/cleanup/root-svg.mjs +3 -3
- package/lib/svg/cleanup/svgo-style.d.ts +1 -1
- package/lib/svg/data/attributes.js +1 -1
- package/lib/svg/data/attributes.mjs +1 -1
- package/lib/svg/data/tags.d.ts +15 -7
- package/lib/svg/data/tags.js +20 -9
- package/lib/svg/data/tags.mjs +11 -6
- package/lib/svg/parse-style.d.ts +7 -7
- package/lib/svg/parse-style.js +27 -7
- package/lib/svg/parse-style.mjs +26 -7
- package/package.json +22 -2
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
// src/svg/analyse.ts
|
|
2
|
+
import { parseSVG } from "./parse.mjs";
|
|
3
|
+
import {
|
|
4
|
+
commonColorPresentationalAttributes,
|
|
5
|
+
markerAttributes,
|
|
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";
|
|
17
|
+
async function analyseSVGStructure(svg, options = {}) {
|
|
18
|
+
const fixErrors = options.fixErrors;
|
|
19
|
+
let root = svg.$svg(":root").get(0);
|
|
20
|
+
if (root._parsed) {
|
|
21
|
+
svg.load(svg.toString());
|
|
22
|
+
root = svg.$svg(":root").get(0);
|
|
23
|
+
}
|
|
24
|
+
root._parsed = true;
|
|
25
|
+
const cheerio = svg.$svg;
|
|
26
|
+
const elements = new Map();
|
|
27
|
+
const ids = Object.create(null);
|
|
28
|
+
let links = [];
|
|
29
|
+
function addID(element, id) {
|
|
30
|
+
if (ids[id]) {
|
|
31
|
+
throw new Error(`Duplicate id "${id}"`);
|
|
32
|
+
}
|
|
33
|
+
element._id = id;
|
|
34
|
+
ids[id] = element._index;
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
function gotElementWithID(element, id, isMask) {
|
|
38
|
+
addID(element, id);
|
|
39
|
+
if (!element._belongsTo) {
|
|
40
|
+
element._belongsTo = [];
|
|
41
|
+
}
|
|
42
|
+
element._belongsTo.push({
|
|
43
|
+
id,
|
|
44
|
+
isMask,
|
|
45
|
+
indexes: new Set([element._index])
|
|
46
|
+
});
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
function gotReusableElement(item, isMask) {
|
|
50
|
+
const element = item.element;
|
|
51
|
+
const attribs = element.attribs;
|
|
52
|
+
const index2 = element._index;
|
|
53
|
+
const id = attribs["id"];
|
|
54
|
+
if (typeof id !== "string") {
|
|
55
|
+
const message = `Definition element ${analyseTagError(element)} does not have id`;
|
|
56
|
+
if (fixErrors) {
|
|
57
|
+
item.removeNode = true;
|
|
58
|
+
item.testChildren = false;
|
|
59
|
+
console.warn(message);
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
throw new Error(message);
|
|
63
|
+
}
|
|
64
|
+
if (ids[id] && fixErrors) {
|
|
65
|
+
console.warn(`Duplicate id "${id}"`);
|
|
66
|
+
item.removeNode = true;
|
|
67
|
+
item.testChildren = false;
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
element._reusableElement = {
|
|
71
|
+
id,
|
|
72
|
+
isMask,
|
|
73
|
+
index: index2
|
|
74
|
+
};
|
|
75
|
+
gotElementWithID(element, id, isMask);
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
function gotElementReference(item, id, usedAsMask) {
|
|
79
|
+
const element = item.element;
|
|
80
|
+
const usedByIndex = element._index;
|
|
81
|
+
const link = {
|
|
82
|
+
id,
|
|
83
|
+
usedByIndex,
|
|
84
|
+
usedAsMask
|
|
85
|
+
};
|
|
86
|
+
links.push(link);
|
|
87
|
+
if (!element._linksTo) {
|
|
88
|
+
element._linksTo = [];
|
|
89
|
+
}
|
|
90
|
+
element._linksTo.push(link);
|
|
91
|
+
}
|
|
92
|
+
let index = 0;
|
|
93
|
+
await parseSVG(svg, (item) => {
|
|
94
|
+
var _a;
|
|
95
|
+
const { tagName, parents } = item;
|
|
96
|
+
if (styleTag.has(tagName)) {
|
|
97
|
+
item.testChildren = false;
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const element = item.element;
|
|
101
|
+
const attribs = element.attribs;
|
|
102
|
+
index++;
|
|
103
|
+
element._index = index;
|
|
104
|
+
elements.set(index, element);
|
|
105
|
+
if (!parents.length) {
|
|
106
|
+
element._usedAsMask = false;
|
|
107
|
+
element._usedAsPaint = true;
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
element._usedAsMask = false;
|
|
111
|
+
element._usedAsPaint = false;
|
|
112
|
+
const parentItem = parents[0];
|
|
113
|
+
const parentElement = parentItem.element;
|
|
114
|
+
if (maskTags.has(tagName)) {
|
|
115
|
+
if (!gotReusableElement(item, true)) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
} else if (reusableElementsWithPalette.has(tagName)) {
|
|
119
|
+
if (!gotReusableElement(item, false)) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
} else if (defsTag.has(parentItem.tagName)) {
|
|
123
|
+
if (!gotReusableElement(item, false)) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
} else if (!defsTag.has(tagName)) {
|
|
127
|
+
element._usedAsMask = parentElement._usedAsMask;
|
|
128
|
+
element._usedAsPaint = parentElement._usedAsPaint;
|
|
129
|
+
element._parentElement = parentElement._index;
|
|
130
|
+
if (!parentElement._childElements) {
|
|
131
|
+
parentElement._childElements = [];
|
|
132
|
+
}
|
|
133
|
+
parentElement._childElements.push(index);
|
|
134
|
+
const parentReusableElement = parentElement._reusableElement;
|
|
135
|
+
if (parentReusableElement) {
|
|
136
|
+
if (element._reusableElement) {
|
|
137
|
+
throw new Error(`Reusable element ${analyseTagError(element)} is inside another reusable element id="${parentReusableElement.id}"`);
|
|
138
|
+
}
|
|
139
|
+
element._reusableElement = parentReusableElement;
|
|
140
|
+
}
|
|
141
|
+
const parentBelongsTo = parentElement._belongsTo;
|
|
142
|
+
if (parentBelongsTo) {
|
|
143
|
+
const list = element._belongsTo || (element._belongsTo = []);
|
|
144
|
+
parentBelongsTo.forEach((item2) => {
|
|
145
|
+
item2.indexes.add(index);
|
|
146
|
+
list.push(item2);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
if (element._id === void 0) {
|
|
150
|
+
const id = attribs["id"];
|
|
151
|
+
if (typeof id === "string") {
|
|
152
|
+
if (ids[id] && fixErrors) {
|
|
153
|
+
console.warn(`Duplicate id "${id}"`);
|
|
154
|
+
cheerio(element).removeAttr("id");
|
|
155
|
+
} else {
|
|
156
|
+
gotElementWithID(element, id, false);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if ((_a = tagSpecificNonPresentationalAttributes[tagName]) == null ? void 0 : _a.has("href")) {
|
|
162
|
+
const href = attribs["href"] || attribs["xlink:href"];
|
|
163
|
+
if (typeof href === "string") {
|
|
164
|
+
if (href.slice(0, 1) !== "#") {
|
|
165
|
+
throw new Error(`Invalid link in ${analyseTagError(element)}`);
|
|
166
|
+
}
|
|
167
|
+
const id = href.slice(1);
|
|
168
|
+
gotElementReference(item, id, false);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
Object.keys(attribs).forEach((attr) => {
|
|
172
|
+
let value = attribs[attr];
|
|
173
|
+
if (value.slice(0, 5).toLowerCase() !== "url(#") {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
value = value.slice(5);
|
|
177
|
+
if (value.slice(-1) !== ")") {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
const id = value.slice(0, value.length - 1).trim();
|
|
181
|
+
if (urlPresentationalAttributes.has(attr)) {
|
|
182
|
+
gotElementReference(item, id, attr !== "filter");
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (commonColorPresentationalAttributes.has(attr) || markerAttributes.has(attr)) {
|
|
186
|
+
gotElementReference(item, id, false);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
links = links.filter((item) => {
|
|
192
|
+
const id = item.id;
|
|
193
|
+
if (ids[id]) {
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
function fix() {
|
|
197
|
+
const index2 = item.usedByIndex;
|
|
198
|
+
const element = elements.get(index2);
|
|
199
|
+
const tagName = element.tagName;
|
|
200
|
+
function remove() {
|
|
201
|
+
var _a;
|
|
202
|
+
const $element = cheerio(element);
|
|
203
|
+
const parent = element.parent;
|
|
204
|
+
if (parent) {
|
|
205
|
+
if (parent._childElements) {
|
|
206
|
+
parent._childElements = parent._childElements.filter((num) => num !== index2);
|
|
207
|
+
}
|
|
208
|
+
(_a = parent._belongsTo) == null ? void 0 : _a.forEach((list) => {
|
|
209
|
+
list.indexes.delete(index2);
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
$element.remove();
|
|
213
|
+
}
|
|
214
|
+
if (element._linksTo) {
|
|
215
|
+
element._linksTo = element._linksTo.filter((item2) => item2.id !== id);
|
|
216
|
+
}
|
|
217
|
+
if (!element.children.length) {
|
|
218
|
+
if (useTag.has(tagName)) {
|
|
219
|
+
remove();
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
const matches = new Set(["#" + id, "url(#" + id + ")"]);
|
|
224
|
+
const attribs = element.attribs;
|
|
225
|
+
for (const attr in attribs) {
|
|
226
|
+
if (matches.has(attribs[attr])) {
|
|
227
|
+
cheerio(element).removeAttr(attr);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const message = `Missing element with id="${id}"`;
|
|
232
|
+
if (fixErrors) {
|
|
233
|
+
fix();
|
|
234
|
+
console.warn(message);
|
|
235
|
+
} else {
|
|
236
|
+
throw new Error(message);
|
|
237
|
+
}
|
|
238
|
+
return false;
|
|
239
|
+
});
|
|
240
|
+
function hasChildItem(tree2, child, canThrow) {
|
|
241
|
+
const item = tree2.children.find((item2) => item2.index === child.index && item2.usedAsMask === child.usedAsMask);
|
|
242
|
+
if (item && canThrow) {
|
|
243
|
+
throw new Error("Recursion");
|
|
244
|
+
}
|
|
245
|
+
return !!item;
|
|
246
|
+
}
|
|
247
|
+
const tree = {
|
|
248
|
+
index: 1,
|
|
249
|
+
usedAsMask: false,
|
|
250
|
+
children: []
|
|
251
|
+
};
|
|
252
|
+
function parseTreeItem(tree2, usedItems, inMask) {
|
|
253
|
+
var _a, _b;
|
|
254
|
+
const element = elements.get(tree2.index);
|
|
255
|
+
if (tree2.usedAsMask || inMask) {
|
|
256
|
+
element._usedAsMask = true;
|
|
257
|
+
inMask = true;
|
|
258
|
+
} else {
|
|
259
|
+
element._usedAsPaint = true;
|
|
260
|
+
}
|
|
261
|
+
usedItems = usedItems.slice(0);
|
|
262
|
+
usedItems.push(element._index);
|
|
263
|
+
(_a = element._childElements) == null ? void 0 : _a.forEach((childIndex) => {
|
|
264
|
+
if (usedItems.indexOf(childIndex) !== -1) {
|
|
265
|
+
throw new Error("Recursion");
|
|
266
|
+
}
|
|
267
|
+
const childItem = {
|
|
268
|
+
index: childIndex,
|
|
269
|
+
usedAsMask: false,
|
|
270
|
+
children: [],
|
|
271
|
+
parent: tree2
|
|
272
|
+
};
|
|
273
|
+
tree2.children.push(childItem);
|
|
274
|
+
parseTreeItem(childItem, usedItems, inMask);
|
|
275
|
+
});
|
|
276
|
+
(_b = element._linksTo) == null ? void 0 : _b.forEach((link) => {
|
|
277
|
+
const linkIndex = ids[link.id];
|
|
278
|
+
const usedAsMask = link.usedAsMask;
|
|
279
|
+
const childItem = {
|
|
280
|
+
index: linkIndex,
|
|
281
|
+
usedAsMask,
|
|
282
|
+
children: [],
|
|
283
|
+
parent: tree2
|
|
284
|
+
};
|
|
285
|
+
if (hasChildItem(tree2, childItem, false)) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
tree2.children.push(childItem);
|
|
289
|
+
parseTreeItem(childItem, usedItems, inMask || usedAsMask);
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
parseTreeItem(tree, [0], false);
|
|
293
|
+
return {
|
|
294
|
+
elements,
|
|
295
|
+
ids,
|
|
296
|
+
links,
|
|
297
|
+
tree
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
export {
|
|
301
|
+
analyseSVGStructure
|
|
302
|
+
};
|
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.removeBadAttributes = void 0;
|
|
4
4
|
const attributes_1 = require("../data/attributes");
|
|
5
|
+
const tags_1 = require("../data/tags");
|
|
5
6
|
const parse_1 = require("../parse");
|
|
6
7
|
/**
|
|
7
8
|
* Remove useless attributes
|
|
8
9
|
*/
|
|
9
10
|
async function removeBadAttributes(svg) {
|
|
10
11
|
await (0, parse_1.parseSVG)(svg, (item) => {
|
|
12
|
+
const tagName = item.tagName;
|
|
11
13
|
const attribs = item.element.attribs;
|
|
12
14
|
const $element = item.$element;
|
|
13
15
|
// Common tags
|
|
@@ -20,6 +22,12 @@ async function removeBadAttributes(svg) {
|
|
|
20
22
|
$element.removeAttr(attr);
|
|
21
23
|
return;
|
|
22
24
|
}
|
|
25
|
+
// Attributes on <defs> aren't passed to child nodes, so remove everything)
|
|
26
|
+
if (tags_1.defsTag.has(tagName) &&
|
|
27
|
+
!attributes_1.tagSpecificPresentationalAttributes[tagName].has(attr)) {
|
|
28
|
+
$element.removeAttr(attr);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
23
31
|
// Check for namespace
|
|
24
32
|
const nsParts = attr.split(':');
|
|
25
33
|
if (nsParts.length > 1) {
|
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
import {
|
|
3
3
|
badAttributes,
|
|
4
4
|
badAttributePrefixes,
|
|
5
|
-
badSoftwareAttributes
|
|
5
|
+
badSoftwareAttributes,
|
|
6
|
+
tagSpecificPresentationalAttributes
|
|
6
7
|
} from "../data/attributes.mjs";
|
|
8
|
+
import { defsTag } from "../data/tags.mjs";
|
|
7
9
|
import { parseSVG } from "../parse.mjs";
|
|
8
10
|
async function removeBadAttributes(svg) {
|
|
9
11
|
await parseSVG(svg, (item) => {
|
|
12
|
+
const tagName = item.tagName;
|
|
10
13
|
const attribs = item.element.attribs;
|
|
11
14
|
const $element = item.$element;
|
|
12
15
|
Object.keys(attribs).forEach((attr) => {
|
|
@@ -14,6 +17,10 @@ async function removeBadAttributes(svg) {
|
|
|
14
17
|
$element.removeAttr(attr);
|
|
15
18
|
return;
|
|
16
19
|
}
|
|
20
|
+
if (defsTag.has(tagName) && !tagSpecificPresentationalAttributes[tagName].has(attr)) {
|
|
21
|
+
$element.removeAttr(attr);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
17
24
|
const nsParts = attr.split(":");
|
|
18
25
|
if (nsParts.length > 1) {
|
|
19
26
|
const namespace = nsParts.shift();
|
|
@@ -13,8 +13,6 @@ requiredParentTags.set(new Set(['feMerge']), tags_1.feMergeChildTags);
|
|
|
13
13
|
requiredParentTags.set(tags_1.feLightningTags, tags_1.feLightningChildTags);
|
|
14
14
|
// Filter tags must be children of <filter>
|
|
15
15
|
requiredParentTags.set(tags_1.filterTag, tags_1.filterChildTags);
|
|
16
|
-
// Tags that must be inside <defs>: gradients, <pattern>, <marker>
|
|
17
|
-
requiredParentTags.set(tags_1.defsTag, tags_1.tagsInsideDefs);
|
|
18
16
|
// <stop> must be inside gradient
|
|
19
17
|
requiredParentTags.set(tags_1.gradientTags, tags_1.gradientChildTags);
|
|
20
18
|
// <mpath> must be inside <animateMotion>
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
allValidTags,
|
|
5
5
|
animateMotionChildTags,
|
|
6
6
|
badTags,
|
|
7
|
-
defsTag,
|
|
8
7
|
feComponentTransferChildTag,
|
|
9
8
|
feLightningChildTags,
|
|
10
9
|
feLightningTags,
|
|
@@ -13,7 +12,6 @@ import {
|
|
|
13
12
|
filterTag,
|
|
14
13
|
gradientChildTags,
|
|
15
14
|
gradientTags,
|
|
16
|
-
tagsInsideDefs,
|
|
17
15
|
unsupportedTags
|
|
18
16
|
} from "../data/tags.mjs";
|
|
19
17
|
var requiredParentTags = new Map();
|
|
@@ -21,7 +19,6 @@ requiredParentTags.set(new Set(["feComponentTransfer"]), feComponentTransferChil
|
|
|
21
19
|
requiredParentTags.set(new Set(["feMerge"]), feMergeChildTags);
|
|
22
20
|
requiredParentTags.set(feLightningTags, feLightningChildTags);
|
|
23
21
|
requiredParentTags.set(filterTag, filterChildTags);
|
|
24
|
-
requiredParentTags.set(defsTag, tagsInsideDefs);
|
|
25
22
|
requiredParentTags.set(gradientTags, gradientChildTags);
|
|
26
23
|
requiredParentTags.set(new Set(["animateMotion"]), animateMotionChildTags);
|
|
27
24
|
async function checkBadTags(svg) {
|
|
@@ -77,7 +77,7 @@ async function cleanupSVGRoot(svg) {
|
|
|
77
77
|
$root.removeAttr(attr);
|
|
78
78
|
return;
|
|
79
79
|
}
|
|
80
|
-
console.
|
|
80
|
+
console.warn(`Removing unexpected attribute on SVG: ${attr}`);
|
|
81
81
|
$root.removeAttr(attr);
|
|
82
82
|
});
|
|
83
83
|
if (Object.keys(moveToChildren).length) {
|
|
@@ -93,7 +93,9 @@ async function cleanupSVGRoot(svg) {
|
|
|
93
93
|
return;
|
|
94
94
|
}
|
|
95
95
|
const tagName = child.tagName;
|
|
96
|
-
if (tagName === 'style' ||
|
|
96
|
+
if (tagName === 'style' ||
|
|
97
|
+
tags_1.reusableElementsWithPalette.has(tagName) ||
|
|
98
|
+
tags_1.maskTags.has(tagName)) {
|
|
97
99
|
// Do not wrap these elements
|
|
98
100
|
return;
|
|
99
101
|
}
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
tagSpecificNonPresentationalAttributes,
|
|
10
10
|
tagSpecificPresentationalAttributes
|
|
11
11
|
} from "../data/attributes.mjs";
|
|
12
|
-
import {
|
|
12
|
+
import { maskTags, reusableElementsWithPalette } from "../data/tags.mjs";
|
|
13
13
|
async function cleanupSVGRoot(svg) {
|
|
14
14
|
const cheerio = svg.$svg;
|
|
15
15
|
const $root = svg.$svg(":root");
|
|
@@ -60,7 +60,7 @@ async function cleanupSVGRoot(svg) {
|
|
|
60
60
|
$root.removeAttr(attr);
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
|
-
console.
|
|
63
|
+
console.warn(`Removing unexpected attribute on SVG: ${attr}`);
|
|
64
64
|
$root.removeAttr(attr);
|
|
65
65
|
});
|
|
66
66
|
if (Object.keys(moveToChildren).length) {
|
|
@@ -75,7 +75,7 @@ async function cleanupSVGRoot(svg) {
|
|
|
75
75
|
return;
|
|
76
76
|
}
|
|
77
77
|
const tagName2 = child.tagName;
|
|
78
|
-
if (tagName2 === "style" ||
|
|
78
|
+
if (tagName2 === "style" || reusableElementsWithPalette.has(tagName2) || maskTags.has(tagName2)) {
|
|
79
79
|
return;
|
|
80
80
|
}
|
|
81
81
|
$child.appendTo($wrapper);
|
|
@@ -221,7 +221,7 @@ exports.tagSpecificPresentationalAttributes = {
|
|
|
221
221
|
svg: new Set(['width', 'height', ...exports.presentationalAttributes]),
|
|
222
222
|
// Defnitions, containers and masks
|
|
223
223
|
clipPath: new Set([...exports.presentationalAttributes]),
|
|
224
|
-
defs: new Set([
|
|
224
|
+
defs: new Set([]),
|
|
225
225
|
g: new Set([...exports.presentationalAttributes]),
|
|
226
226
|
mask: new Set(['x', 'y', 'width', 'height', ...exports.presentationalAttributes]),
|
|
227
227
|
symbol: new Set(['x', 'y', 'width', 'height', ...exports.presentationalAttributes]),
|
|
@@ -156,7 +156,7 @@ var tagSpecificAnimatedAttributes = {
|
|
|
156
156
|
var tagSpecificPresentationalAttributes = {
|
|
157
157
|
svg: new Set(["width", "height", ...presentationalAttributes]),
|
|
158
158
|
clipPath: new Set([...presentationalAttributes]),
|
|
159
|
-
defs: new Set([
|
|
159
|
+
defs: new Set([]),
|
|
160
160
|
g: new Set([...presentationalAttributes]),
|
|
161
161
|
mask: new Set(["x", "y", "width", "height", ...presentationalAttributes]),
|
|
162
162
|
symbol: new Set(["x", "y", "width", "height", ...presentationalAttributes]),
|
package/lib/svg/data/tags.d.ts
CHANGED
|
@@ -29,9 +29,13 @@ export declare const styleTag: Set<string>;
|
|
|
29
29
|
*/
|
|
30
30
|
export declare const defsTag: Set<string>;
|
|
31
31
|
/**
|
|
32
|
-
* Masks: colors are ignored,
|
|
32
|
+
* Masks: colors are ignored, elements must have id
|
|
33
33
|
*/
|
|
34
|
-
export declare const
|
|
34
|
+
export declare const maskTags: Set<string>;
|
|
35
|
+
/**
|
|
36
|
+
* Symbol
|
|
37
|
+
*/
|
|
38
|
+
export declare const symbolTag: Set<string>;
|
|
35
39
|
/**
|
|
36
40
|
* SVG shapes
|
|
37
41
|
*/
|
|
@@ -45,7 +49,7 @@ export declare const useTag: Set<string>;
|
|
|
45
49
|
*/
|
|
46
50
|
export declare const groupTag: Set<string>;
|
|
47
51
|
/**
|
|
48
|
-
* Marker,
|
|
52
|
+
* Marker, should be inside <defs>
|
|
49
53
|
*/
|
|
50
54
|
export declare const markerTag: Set<string>;
|
|
51
55
|
/**
|
|
@@ -54,7 +58,7 @@ export declare const markerTag: Set<string>;
|
|
|
54
58
|
export declare const animateTags: Set<string>;
|
|
55
59
|
export declare const animateMotionChildTags: Set<string>;
|
|
56
60
|
/**
|
|
57
|
-
* Gradients,
|
|
61
|
+
* Gradients, should be inside <defs>
|
|
58
62
|
*/
|
|
59
63
|
export declare const gradientTags: Set<string>;
|
|
60
64
|
/**
|
|
@@ -62,7 +66,7 @@ export declare const gradientTags: Set<string>;
|
|
|
62
66
|
*/
|
|
63
67
|
export declare const gradientChildTags: Set<string>;
|
|
64
68
|
/**
|
|
65
|
-
* Pattern,
|
|
69
|
+
* Pattern, should be inside <defs>
|
|
66
70
|
*/
|
|
67
71
|
export declare const patternTag: Set<string>;
|
|
68
72
|
/**
|
|
@@ -76,9 +80,13 @@ export declare const feLightningChildTags: Set<string>;
|
|
|
76
80
|
export declare const feMergeChildTags: Set<string>;
|
|
77
81
|
/***** Combination of tags *****/
|
|
78
82
|
/**
|
|
79
|
-
*
|
|
83
|
+
* Reusable elements that use colors
|
|
84
|
+
*
|
|
85
|
+
* Most are used via color attributes like `fill`
|
|
86
|
+
* Some are used via custom attributes like `marker-start`
|
|
87
|
+
* Filter is used via `filter`
|
|
80
88
|
*/
|
|
81
|
-
export declare const
|
|
89
|
+
export declare const reusableElementsWithPalette: Set<string>;
|
|
82
90
|
/**
|
|
83
91
|
* All supported tags
|
|
84
92
|
*/
|
package/lib/svg/data/tags.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Icons cannot have anything that requires external resources, anything that renders inconsistently.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.allValidTags = exports.
|
|
7
|
+
exports.allValidTags = exports.reusableElementsWithPalette = exports.feMergeChildTags = exports.feLightningChildTags = exports.feComponentTransferChildTag = exports.filterChildTags = exports.feLightningTags = exports.filterTag = exports.patternTag = exports.gradientChildTags = exports.gradientTags = exports.animateMotionChildTags = exports.animateTags = exports.markerTag = exports.groupTag = exports.useTag = exports.shapeTags = exports.symbolTag = exports.maskTags = exports.defsTag = exports.styleTag = exports.unsupportedTags = exports.badTags = void 0;
|
|
8
8
|
/**
|
|
9
9
|
* Bad tags
|
|
10
10
|
*
|
|
@@ -57,9 +57,13 @@ exports.styleTag = new Set(['style']);
|
|
|
57
57
|
*/
|
|
58
58
|
exports.defsTag = new Set(['defs']);
|
|
59
59
|
/**
|
|
60
|
-
* Masks: colors are ignored,
|
|
60
|
+
* Masks: colors are ignored, elements must have id
|
|
61
61
|
*/
|
|
62
|
-
exports.
|
|
62
|
+
exports.maskTags = new Set(['clipPath', 'mask']);
|
|
63
|
+
/**
|
|
64
|
+
* Symbol
|
|
65
|
+
*/
|
|
66
|
+
exports.symbolTag = new Set(['symbol']);
|
|
63
67
|
/**
|
|
64
68
|
* SVG shapes
|
|
65
69
|
*/
|
|
@@ -81,7 +85,7 @@ exports.useTag = new Set(['use']);
|
|
|
81
85
|
*/
|
|
82
86
|
exports.groupTag = new Set(['g']);
|
|
83
87
|
/**
|
|
84
|
-
* Marker,
|
|
88
|
+
* Marker, should be inside <defs>
|
|
85
89
|
*/
|
|
86
90
|
exports.markerTag = new Set(['marker']);
|
|
87
91
|
/**
|
|
@@ -96,7 +100,7 @@ exports.animateTags = new Set([
|
|
|
96
100
|
]);
|
|
97
101
|
exports.animateMotionChildTags = new Set(['mpath']);
|
|
98
102
|
/**
|
|
99
|
-
* Gradients,
|
|
103
|
+
* Gradients, should be inside <defs>
|
|
100
104
|
*/
|
|
101
105
|
exports.gradientTags = new Set(['linearGradient', 'radialGradient']);
|
|
102
106
|
/**
|
|
@@ -104,7 +108,7 @@ exports.gradientTags = new Set(['linearGradient', 'radialGradient']);
|
|
|
104
108
|
*/
|
|
105
109
|
exports.gradientChildTags = new Set(['stop']);
|
|
106
110
|
/**
|
|
107
|
-
* Pattern,
|
|
111
|
+
* Pattern, should be inside <defs>
|
|
108
112
|
*/
|
|
109
113
|
exports.patternTag = new Set(['pattern']);
|
|
110
114
|
/**
|
|
@@ -146,12 +150,18 @@ exports.feLightningChildTags = new Set([
|
|
|
146
150
|
exports.feMergeChildTags = new Set(['feMergeNode']);
|
|
147
151
|
/***** Combination of tags *****/
|
|
148
152
|
/**
|
|
149
|
-
*
|
|
153
|
+
* Reusable elements that use colors
|
|
154
|
+
*
|
|
155
|
+
* Most are used via color attributes like `fill`
|
|
156
|
+
* Some are used via custom attributes like `marker-start`
|
|
157
|
+
* Filter is used via `filter`
|
|
150
158
|
*/
|
|
151
|
-
exports.
|
|
159
|
+
exports.reusableElementsWithPalette = new Set([
|
|
152
160
|
...exports.gradientTags,
|
|
153
161
|
...exports.patternTag,
|
|
154
162
|
...exports.markerTag,
|
|
163
|
+
...exports.symbolTag,
|
|
164
|
+
...exports.filterTag,
|
|
155
165
|
]);
|
|
156
166
|
/**
|
|
157
167
|
* All supported tags
|
|
@@ -159,7 +169,8 @@ exports.tagsInsideDefs = new Set([
|
|
|
159
169
|
exports.allValidTags = new Set([
|
|
160
170
|
...exports.styleTag,
|
|
161
171
|
...exports.defsTag,
|
|
162
|
-
...exports.
|
|
172
|
+
...exports.maskTags,
|
|
173
|
+
...exports.symbolTag,
|
|
163
174
|
...exports.shapeTags,
|
|
164
175
|
...exports.useTag,
|
|
165
176
|
...exports.groupTag,
|
package/lib/svg/data/tags.mjs
CHANGED
|
@@ -22,7 +22,8 @@ var badTags = new Set([
|
|
|
22
22
|
var unsupportedTags = new Set(["metadata", "desc", "title"]);
|
|
23
23
|
var styleTag = new Set(["style"]);
|
|
24
24
|
var defsTag = new Set(["defs"]);
|
|
25
|
-
var
|
|
25
|
+
var maskTags = new Set(["clipPath", "mask"]);
|
|
26
|
+
var symbolTag = new Set(["symbol"]);
|
|
26
27
|
var shapeTags = new Set([
|
|
27
28
|
"circle",
|
|
28
29
|
"ellipse",
|
|
@@ -80,15 +81,18 @@ var feLightningChildTags = new Set([
|
|
|
80
81
|
"feDistantLight"
|
|
81
82
|
]);
|
|
82
83
|
var feMergeChildTags = new Set(["feMergeNode"]);
|
|
83
|
-
var
|
|
84
|
+
var reusableElementsWithPalette = new Set([
|
|
84
85
|
...gradientTags,
|
|
85
86
|
...patternTag,
|
|
86
|
-
...markerTag
|
|
87
|
+
...markerTag,
|
|
88
|
+
...symbolTag,
|
|
89
|
+
...filterTag
|
|
87
90
|
]);
|
|
88
91
|
var allValidTags = new Set([
|
|
89
92
|
...styleTag,
|
|
90
93
|
...defsTag,
|
|
91
|
-
...
|
|
94
|
+
...maskTags,
|
|
95
|
+
...symbolTag,
|
|
92
96
|
...shapeTags,
|
|
93
97
|
...useTag,
|
|
94
98
|
...groupTag,
|
|
@@ -120,11 +124,12 @@ export {
|
|
|
120
124
|
gradientTags,
|
|
121
125
|
groupTag,
|
|
122
126
|
markerTag,
|
|
123
|
-
|
|
127
|
+
maskTags,
|
|
124
128
|
patternTag,
|
|
129
|
+
reusableElementsWithPalette,
|
|
125
130
|
shapeTags,
|
|
126
131
|
styleTag,
|
|
127
|
-
|
|
132
|
+
symbolTag,
|
|
128
133
|
unsupportedTags,
|
|
129
134
|
useTag
|
|
130
135
|
};
|