@iconify/tools 5.0.2 → 5.0.3
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.js +15 -15
- package/lib/css/parser/tree.js +2 -2
- package/lib/download/gitlab/hash.js +1 -1
- package/lib/download/helpers/unzip.js +5 -5
- package/lib/export/icon-package.js +4 -4
- package/lib/icon-set/index.js +15 -15
- package/lib/import/directory.js +4 -4
- package/lib/import/figma/query.js +8 -8
- package/lib/misc/compare-dirs.js +3 -3
- package/lib/optimise/figma.js +12 -12
- package/lib/optimise/global-style.js +2 -2
- package/lib/svg/analyse.js +20 -20
- package/lib/svg/cleanup/inline-style.js +1 -1
- package/lib/svg/cleanup/root-svg.js +2 -2
- package/lib/svg/parse-style.js +7 -7
- package/package.json +9 -9
package/lib/colors/parse.js
CHANGED
|
@@ -56,21 +56,21 @@ function parseColors(svg, options = {}) {
|
|
|
56
56
|
/**
|
|
57
57
|
* Get element color
|
|
58
58
|
*/
|
|
59
|
-
function getElementColor(prop, item, elements
|
|
60
|
-
function find(prop
|
|
59
|
+
function getElementColor(prop, item, elements) {
|
|
60
|
+
function find(prop) {
|
|
61
61
|
let currentItem = item;
|
|
62
|
-
const allowDefaultColor = allowDefaultColorValue[prop
|
|
62
|
+
const allowDefaultColor = allowDefaultColorValue[prop];
|
|
63
63
|
while (currentItem) {
|
|
64
|
-
const element = elements
|
|
65
|
-
const color = element._colors?.[prop
|
|
64
|
+
const element = elements.get(currentItem.index);
|
|
65
|
+
const color = element._colors?.[prop];
|
|
66
66
|
if (color !== void 0) return color;
|
|
67
67
|
if (allowDefaultColor) {
|
|
68
68
|
if (allowDefaultColor === true || element.attribs[allowDefaultColor]) return null;
|
|
69
69
|
}
|
|
70
70
|
currentItem = currentItem.parent;
|
|
71
|
-
if (currentItem?.usedAsMask) return defaultColorValues[prop
|
|
71
|
+
if (currentItem?.usedAsMask) return defaultColorValues[prop];
|
|
72
72
|
}
|
|
73
|
-
return defaultColorValues[prop
|
|
73
|
+
return defaultColorValues[prop];
|
|
74
74
|
}
|
|
75
75
|
let propColor = find(prop);
|
|
76
76
|
if (propColor !== null && typeof propColor === "object" && propColor.type === "current" && prop !== "color") propColor = find("color");
|
|
@@ -126,15 +126,15 @@ function parseColors(svg, options = {}) {
|
|
|
126
126
|
const removedElements = /* @__PURE__ */ new Set();
|
|
127
127
|
const parsedElements = /* @__PURE__ */ new Set();
|
|
128
128
|
function removeElement(index, element) {
|
|
129
|
-
function removeChildren(element
|
|
130
|
-
element
|
|
129
|
+
function removeChildren(element) {
|
|
130
|
+
element.children.forEach((item) => {
|
|
131
131
|
if (item.type !== "tag") return;
|
|
132
|
-
const element
|
|
133
|
-
const index
|
|
134
|
-
if (index
|
|
135
|
-
element
|
|
136
|
-
removedElements.add(index
|
|
137
|
-
removeChildren(element
|
|
132
|
+
const element = item;
|
|
133
|
+
const index = element._index;
|
|
134
|
+
if (index && !removedElements.has(index)) {
|
|
135
|
+
element._removed = true;
|
|
136
|
+
removedElements.add(index);
|
|
137
|
+
removeChildren(element);
|
|
138
138
|
}
|
|
139
139
|
});
|
|
140
140
|
}
|
package/lib/css/parser/tree.js
CHANGED
|
@@ -19,8 +19,8 @@ function tokensTree(tokens) {
|
|
|
19
19
|
target.push(newItem);
|
|
20
20
|
parse(newItem.children);
|
|
21
21
|
if (!newItem.children.length) {
|
|
22
|
-
const index
|
|
23
|
-
if (index
|
|
22
|
+
const index = target.indexOf(newItem);
|
|
23
|
+
if (index !== -1) target.splice(index, 1);
|
|
24
24
|
}
|
|
25
25
|
break;
|
|
26
26
|
}
|
|
@@ -11,7 +11,7 @@ async function getGitLabRepoHash(options) {
|
|
|
11
11
|
});
|
|
12
12
|
if (!response.success) throw new Error(`Error downloading data from GitLab API: ${response.error}`);
|
|
13
13
|
const content = JSON.parse(response.content);
|
|
14
|
-
const item = (content instanceof Array ? content : [content]).find((item
|
|
14
|
+
const item = (content instanceof Array ? content : [content]).find((item) => item.name === options.branch && typeof item.commit.id === "string");
|
|
15
15
|
if (!item) throw new Error("Error parsing GitLab API response");
|
|
16
16
|
return item.commit.id;
|
|
17
17
|
}
|
|
@@ -8,9 +8,9 @@ import { unzip as unzip$1 } from "fflate";
|
|
|
8
8
|
async function unzip(source, path, filter) {
|
|
9
9
|
const dir = normalize(path);
|
|
10
10
|
const data = await readFile(source);
|
|
11
|
-
async function writeFiles(data
|
|
11
|
+
async function writeFiles(data) {
|
|
12
12
|
const createdDirs = /* @__PURE__ */ new Set();
|
|
13
|
-
for (const name in data
|
|
13
|
+
for (const name in data) {
|
|
14
14
|
const filePath = normalize(join(dir, name));
|
|
15
15
|
if (filter && !filter(filePath)) continue;
|
|
16
16
|
if (filePath.startsWith("/") || filePath.includes("../") || filePath.includes(":")) throw new Error("Invalid file path in zip: " + filePath);
|
|
@@ -23,16 +23,16 @@ async function unzip(source, path, filter) {
|
|
|
23
23
|
await mkdir(fileDir, { recursive: true });
|
|
24
24
|
} catch {}
|
|
25
25
|
}
|
|
26
|
-
if (!isDir) await writeFile(filePath, data
|
|
26
|
+
if (!isDir) await writeFile(filePath, data[name]);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
return new Promise((resolve
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
30
|
unzip$1(data, (err, unzipped) => {
|
|
31
31
|
if (err) {
|
|
32
32
|
reject(err);
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
35
|
-
writeFiles(unzipped).then(() => resolve
|
|
35
|
+
writeFiles(unzipped).then(() => resolve()).catch((err) => reject(err));
|
|
36
36
|
});
|
|
37
37
|
});
|
|
38
38
|
}
|
|
@@ -21,16 +21,16 @@ async function exportIconPackage(iconSet, options) {
|
|
|
21
21
|
const esm = options.module !== false;
|
|
22
22
|
const dir = await prepareDirectoryForExport(options);
|
|
23
23
|
const typesContent = options.typesContent || defaultTypesContent;
|
|
24
|
-
await iconSet.forEach(async (name
|
|
25
|
-
const data = iconSet.resolve(name
|
|
24
|
+
await iconSet.forEach(async (name) => {
|
|
25
|
+
const data = iconSet.resolve(name, false);
|
|
26
26
|
if (!data) return;
|
|
27
|
-
const typesFilename = name
|
|
27
|
+
const typesFilename = name + ".d.ts";
|
|
28
28
|
await promises.writeFile(`${dir}/${typesFilename}`, typesContent, "utf8");
|
|
29
29
|
files.add(typesFilename);
|
|
30
30
|
let content = `const data = ` + JSON.stringify(data, null, " ") + ";\n";
|
|
31
31
|
if (!esm) content += "exports.__esModule = true;\nexports.default = data;\n";
|
|
32
32
|
else content += "export default data;\n";
|
|
33
|
-
const contentFilename = name
|
|
33
|
+
const contentFilename = name + ".js";
|
|
34
34
|
await promises.writeFile(`${dir}/${contentFilename}`, content, "utf8");
|
|
35
35
|
files.add(contentFilename);
|
|
36
36
|
});
|
package/lib/icon-set/index.js
CHANGED
|
@@ -206,11 +206,11 @@ var IconSet = class {
|
|
|
206
206
|
const tree = item && (item.type === "icon" ? [] : this.getTree([name])[name]);
|
|
207
207
|
if (!tree) return null;
|
|
208
208
|
let result = {};
|
|
209
|
-
function parse(name
|
|
210
|
-
const item
|
|
211
|
-
if (item
|
|
212
|
-
result = mergeIconData(item
|
|
213
|
-
if (item
|
|
209
|
+
function parse(name) {
|
|
210
|
+
const item = entries[name];
|
|
211
|
+
if (item.type === "alias") return;
|
|
212
|
+
result = mergeIconData(item.props, result);
|
|
213
|
+
if (item.type === "icon") result.body = item.body;
|
|
214
214
|
}
|
|
215
215
|
parse(name);
|
|
216
216
|
tree.forEach(parse);
|
|
@@ -283,10 +283,10 @@ var IconSet = class {
|
|
|
283
283
|
if (Object.keys(chars).length) result.chars = chars;
|
|
284
284
|
const categories = Object.create(null);
|
|
285
285
|
Array.from(this.categories).sort((a, b) => a.title.localeCompare(b.title)).forEach((item) => {
|
|
286
|
-
const names
|
|
287
|
-
if (names
|
|
288
|
-
names
|
|
289
|
-
categories[item.title] = names
|
|
286
|
+
const names = this.listCategory(item);
|
|
287
|
+
if (names) {
|
|
288
|
+
names.sort((a, b) => a.localeCompare(b));
|
|
289
|
+
categories[item.title] = names;
|
|
290
290
|
}
|
|
291
291
|
});
|
|
292
292
|
if (Object.keys(categories).length) result.categories = categories;
|
|
@@ -414,14 +414,14 @@ var IconSet = class {
|
|
|
414
414
|
delete entries[name];
|
|
415
415
|
let count = 1;
|
|
416
416
|
function remove(parent) {
|
|
417
|
-
Object.keys(entries).filter((name
|
|
418
|
-
const item = entries[name
|
|
417
|
+
Object.keys(entries).filter((name) => {
|
|
418
|
+
const item = entries[name];
|
|
419
419
|
return item.type !== "icon" && item.parent === parent;
|
|
420
|
-
}).forEach((name
|
|
421
|
-
if (entries[name
|
|
422
|
-
delete entries[name
|
|
420
|
+
}).forEach((name) => {
|
|
421
|
+
if (entries[name]) {
|
|
422
|
+
delete entries[name];
|
|
423
423
|
count++;
|
|
424
|
-
remove(name
|
|
424
|
+
remove(name);
|
|
425
425
|
}
|
|
426
426
|
});
|
|
427
427
|
}
|
package/lib/import/directory.js
CHANGED
|
@@ -45,12 +45,12 @@ function isValidFile(item) {
|
|
|
45
45
|
*/
|
|
46
46
|
function importDirectory(path, options = {}) {
|
|
47
47
|
return new Promise((fulfill, reject) => {
|
|
48
|
-
scanDirectory(path, (ext, file, subdir, path
|
|
48
|
+
scanDirectory(path, (ext, file, subdir, path) => {
|
|
49
49
|
const result = {
|
|
50
50
|
file,
|
|
51
51
|
ext,
|
|
52
52
|
subdir,
|
|
53
|
-
path
|
|
53
|
+
path
|
|
54
54
|
};
|
|
55
55
|
return isValidFile(result) ? result : false;
|
|
56
56
|
}, options.includeSubDirs !== false).then((files) => {
|
|
@@ -75,12 +75,12 @@ function importDirectory(path, options = {}) {
|
|
|
75
75
|
* Import all icons from directory synchronously
|
|
76
76
|
*/
|
|
77
77
|
function importDirectorySync(path, options = {}) {
|
|
78
|
-
const files = scanDirectorySync(path, (ext, file, subdir, path
|
|
78
|
+
const files = scanDirectorySync(path, (ext, file, subdir, path) => {
|
|
79
79
|
const result = {
|
|
80
80
|
file,
|
|
81
81
|
ext,
|
|
82
82
|
subdir,
|
|
83
|
-
path
|
|
83
|
+
path
|
|
84
84
|
};
|
|
85
85
|
return isValidFile(result) ? result : false;
|
|
86
86
|
}, options.includeSubDirs !== false);
|
|
@@ -29,12 +29,12 @@ async function figmaFilesQuery(options, cache) {
|
|
|
29
29
|
if (!cachedData) return true;
|
|
30
30
|
let ifModifiedSince;
|
|
31
31
|
if (options.ifModifiedSince === true) try {
|
|
32
|
-
const parsedData
|
|
33
|
-
if (typeof parsedData
|
|
32
|
+
const parsedData = JSON.parse(cachedData);
|
|
33
|
+
if (typeof parsedData.lastModified !== "string") {
|
|
34
34
|
await clearAPICache(cache.dir);
|
|
35
35
|
return true;
|
|
36
36
|
}
|
|
37
|
-
ifModifiedSince = parsedData
|
|
37
|
+
ifModifiedSince = parsedData.lastModified;
|
|
38
38
|
} catch {
|
|
39
39
|
await clearAPICache(cache.dir);
|
|
40
40
|
return true;
|
|
@@ -45,10 +45,10 @@ async function figmaFilesQuery(options, cache) {
|
|
|
45
45
|
params: new URLSearchParams(params)
|
|
46
46
|
};
|
|
47
47
|
versionCheckParams.params.set("depth", "1");
|
|
48
|
-
const response
|
|
48
|
+
const response = await sendAPIQuery(versionCheckParams);
|
|
49
49
|
try {
|
|
50
|
-
if (response
|
|
51
|
-
if (identicalDates(JSON.parse(response
|
|
50
|
+
if (response.success) {
|
|
51
|
+
if (identicalDates(JSON.parse(response.content).lastModified, ifModifiedSince)) return false;
|
|
52
52
|
}
|
|
53
53
|
} catch {}
|
|
54
54
|
await clearAPICache(cache.dir);
|
|
@@ -79,10 +79,10 @@ async function figmaImagesQuery(options, nodes, cache) {
|
|
|
79
79
|
const uri = "https://api.figma.com/v1/images/" + options.file;
|
|
80
80
|
const maxLength = 2048 - uri.length;
|
|
81
81
|
const svgOptions = options.svgOptions || {};
|
|
82
|
-
const query = (ids
|
|
82
|
+
const query = (ids) => {
|
|
83
83
|
return new Promise((resolve, reject) => {
|
|
84
84
|
const params = new URLSearchParams({
|
|
85
|
-
ids: ids
|
|
85
|
+
ids: ids.join(","),
|
|
86
86
|
format: "svg"
|
|
87
87
|
});
|
|
88
88
|
if (options.version) params.set("version", options.version);
|
package/lib/misc/compare-dirs.js
CHANGED
|
@@ -37,9 +37,9 @@ async function compareDirectories(dir1, dir2, options) {
|
|
|
37
37
|
if (!files2.includes(file)) return false;
|
|
38
38
|
const ext = file.split(".").pop().toLowerCase();
|
|
39
39
|
if (!textExtensions.has(ext)) {
|
|
40
|
-
const content1
|
|
41
|
-
const content2
|
|
42
|
-
if (Buffer.compare(content1
|
|
40
|
+
const content1 = await promises.readFile(dir1 + "/" + file);
|
|
41
|
+
const content2 = await promises.readFile(dir2 + "/" + file);
|
|
42
|
+
if (Buffer.compare(content1, content2) !== 0) return false;
|
|
43
43
|
continue;
|
|
44
44
|
}
|
|
45
45
|
let content1 = await promises.readFile(dir1 + "/" + file, "utf8");
|
package/lib/optimise/figma.js
CHANGED
|
@@ -79,39 +79,39 @@ function remove(svg) {
|
|
|
79
79
|
parseSVG(svg, (item) => {
|
|
80
80
|
const node = item.node;
|
|
81
81
|
const tagName = node.tag;
|
|
82
|
-
const attribs
|
|
83
|
-
Object.keys(attribs
|
|
84
|
-
const value = attribs
|
|
82
|
+
const attribs = node.attribs;
|
|
83
|
+
Object.keys(attribs).forEach((attr) => {
|
|
84
|
+
const value = attribs[attr];
|
|
85
85
|
if (typeof value !== "string") return;
|
|
86
86
|
switch (attr) {
|
|
87
87
|
case "id":
|
|
88
|
-
if (!maskTags.has(tagName) && !symbolTag.has(tagName)) delete attribs
|
|
88
|
+
if (!maskTags.has(tagName) && !symbolTag.has(tagName)) delete attribs[attr];
|
|
89
89
|
break;
|
|
90
90
|
case "class":
|
|
91
91
|
case "xmlns:xlink":
|
|
92
92
|
case "version":
|
|
93
|
-
delete attribs
|
|
93
|
+
delete attribs[attr];
|
|
94
94
|
break;
|
|
95
95
|
case "transform": {
|
|
96
96
|
const trimmed = value.replace(/\s+/g, "").replace(/\.0+/g, "");
|
|
97
|
-
if (!trimmed || trimmed === "matrix(1,0,0,1,0,0)") delete attribs
|
|
97
|
+
if (!trimmed || trimmed === "matrix(1,0,0,1,0,0)") delete attribs[attr];
|
|
98
98
|
break;
|
|
99
99
|
}
|
|
100
100
|
case "rx":
|
|
101
101
|
case "ry":
|
|
102
102
|
case "x":
|
|
103
103
|
case "y":
|
|
104
|
-
if (value === "0") delete attribs
|
|
104
|
+
if (value === "0") delete attribs[attr];
|
|
105
105
|
break;
|
|
106
106
|
case "fill-opacity":
|
|
107
107
|
case "stroke-opacity":
|
|
108
108
|
case "opacity":
|
|
109
|
-
if (value === "1") delete attribs
|
|
109
|
+
if (value === "1") delete attribs[attr];
|
|
110
110
|
break;
|
|
111
111
|
case "fill":
|
|
112
112
|
case "stroke": {
|
|
113
113
|
const colorValue = stringToColor(value);
|
|
114
|
-
if (colorValue?.type === "rgb") attribs
|
|
114
|
+
if (colorValue?.type === "rgb") attribs[attr] = colorToString(colorValue);
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
});
|
|
@@ -135,9 +135,9 @@ function remove(svg) {
|
|
|
135
135
|
if (node.type === "tag") {
|
|
136
136
|
const tagName = node.tag;
|
|
137
137
|
if (!defsTag.has(tagName) && !maskTags.has(tagName) && !symbolTag.has(tagName)) {
|
|
138
|
-
const clipPath
|
|
139
|
-
if (typeof clipPath
|
|
140
|
-
const id = clipPath
|
|
138
|
+
const clipPath = node.attribs["clip-path"];
|
|
139
|
+
if (typeof clipPath !== "string" || !clipPath.startsWith(urlStart) || !clipPath.endsWith(urlEnd)) return false;
|
|
140
|
+
const id = clipPath.slice(5, -1);
|
|
141
141
|
if (typeof clipID === "string" && clipID !== id) return false;
|
|
142
142
|
clipID = id;
|
|
143
143
|
shapesToClip.push(node);
|
|
@@ -24,8 +24,8 @@ function cleanupGlobalStyle(svg) {
|
|
|
24
24
|
].forEach((attr) => {
|
|
25
25
|
const value = attribs[attr];
|
|
26
26
|
if (typeof value !== "string") return;
|
|
27
|
-
value.split(";").forEach((item
|
|
28
|
-
splitClassName(item
|
|
27
|
+
value.split(";").forEach((item) => {
|
|
28
|
+
splitClassName(item).forEach((className) => {
|
|
29
29
|
animatedClasses.add(className);
|
|
30
30
|
});
|
|
31
31
|
});
|
package/lib/svg/analyse.js
CHANGED
|
@@ -46,7 +46,7 @@ function analyseSVGStructure(svg, options = {}) {
|
|
|
46
46
|
function gotReusableElement(item, isMask) {
|
|
47
47
|
const element = item.node;
|
|
48
48
|
const attribs = element.attribs;
|
|
49
|
-
const index
|
|
49
|
+
const index = element._index;
|
|
50
50
|
const id = attribs["id"];
|
|
51
51
|
if (typeof id !== "string") {
|
|
52
52
|
const message = `Definition element ${analyseTagError(element)} does not have id`;
|
|
@@ -67,7 +67,7 @@ function analyseSVGStructure(svg, options = {}) {
|
|
|
67
67
|
element._reusableElement = {
|
|
68
68
|
id,
|
|
69
69
|
isMask,
|
|
70
|
-
index
|
|
70
|
+
index
|
|
71
71
|
};
|
|
72
72
|
gotElementWithID(element, id, isMask);
|
|
73
73
|
return true;
|
|
@@ -128,9 +128,9 @@ function analyseSVGStructure(svg, options = {}) {
|
|
|
128
128
|
const parentBelongsTo = parentElement._belongsTo;
|
|
129
129
|
if (parentBelongsTo) {
|
|
130
130
|
const list = element._belongsTo || (element._belongsTo = []);
|
|
131
|
-
parentBelongsTo.forEach((item
|
|
132
|
-
item
|
|
133
|
-
list.push(item
|
|
131
|
+
parentBelongsTo.forEach((item) => {
|
|
132
|
+
item.indexes.add(index);
|
|
133
|
+
list.push(item);
|
|
134
134
|
});
|
|
135
135
|
}
|
|
136
136
|
if (element._id === void 0) {
|
|
@@ -169,21 +169,21 @@ function analyseSVGStructure(svg, options = {}) {
|
|
|
169
169
|
const id = item.id;
|
|
170
170
|
if (ids[id]) return true;
|
|
171
171
|
function fix() {
|
|
172
|
-
const index
|
|
173
|
-
const element = elements.get(index
|
|
172
|
+
const index = item.usedByIndex;
|
|
173
|
+
const element = elements.get(index);
|
|
174
174
|
const tagName = element.tag;
|
|
175
175
|
function remove() {
|
|
176
176
|
const parentIndex = element._parentElement;
|
|
177
177
|
const parent = typeof parentIndex === "number" ? elements.get(parentIndex) : null;
|
|
178
178
|
if (parent) {
|
|
179
|
-
if (parent._childElements) parent._childElements = parent._childElements.filter((num) => num !== index
|
|
179
|
+
if (parent._childElements) parent._childElements = parent._childElements.filter((num) => num !== index);
|
|
180
180
|
parent._belongsTo?.forEach((list) => {
|
|
181
|
-
list.indexes.delete(index
|
|
181
|
+
list.indexes.delete(index);
|
|
182
182
|
});
|
|
183
183
|
parent.children = parent.children.filter((node) => node !== element);
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
|
-
if (element._linksTo) element._linksTo = element._linksTo.filter((item
|
|
186
|
+
if (element._linksTo) element._linksTo = element._linksTo.filter((item) => item.id !== id);
|
|
187
187
|
if (!element.children.length) {
|
|
188
188
|
if (useTag.has(tagName)) {
|
|
189
189
|
remove();
|
|
@@ -201,8 +201,8 @@ function analyseSVGStructure(svg, options = {}) {
|
|
|
201
201
|
} else throw new Error(message);
|
|
202
202
|
return false;
|
|
203
203
|
});
|
|
204
|
-
function hasChildItem(tree
|
|
205
|
-
const item = tree
|
|
204
|
+
function hasChildItem(tree, child, canThrow) {
|
|
205
|
+
const item = tree.children.find((item) => item.index === child.index && item.usedAsMask === child.usedAsMask);
|
|
206
206
|
if (item && canThrow) throw new Error("Recursion");
|
|
207
207
|
return !!item;
|
|
208
208
|
}
|
|
@@ -211,9 +211,9 @@ function analyseSVGStructure(svg, options = {}) {
|
|
|
211
211
|
usedAsMask: false,
|
|
212
212
|
children: []
|
|
213
213
|
};
|
|
214
|
-
function parseTreeItem(tree
|
|
215
|
-
const element = elements.get(tree
|
|
216
|
-
if (tree
|
|
214
|
+
function parseTreeItem(tree, usedItems, inMask) {
|
|
215
|
+
const element = elements.get(tree.index);
|
|
216
|
+
if (tree.usedAsMask || inMask) {
|
|
217
217
|
element._usedAsMask = true;
|
|
218
218
|
inMask = true;
|
|
219
219
|
} else element._usedAsPaint = true;
|
|
@@ -225,9 +225,9 @@ function analyseSVGStructure(svg, options = {}) {
|
|
|
225
225
|
index: childIndex,
|
|
226
226
|
usedAsMask: false,
|
|
227
227
|
children: [],
|
|
228
|
-
parent: tree
|
|
228
|
+
parent: tree
|
|
229
229
|
};
|
|
230
|
-
tree
|
|
230
|
+
tree.children.push(childItem);
|
|
231
231
|
parseTreeItem(childItem, usedItems, inMask);
|
|
232
232
|
});
|
|
233
233
|
element._linksTo?.forEach((link) => {
|
|
@@ -237,10 +237,10 @@ function analyseSVGStructure(svg, options = {}) {
|
|
|
237
237
|
index: linkIndex,
|
|
238
238
|
usedAsMask,
|
|
239
239
|
children: [],
|
|
240
|
-
parent: tree
|
|
240
|
+
parent: tree
|
|
241
241
|
};
|
|
242
|
-
if (hasChildItem(tree
|
|
243
|
-
tree
|
|
242
|
+
if (hasChildItem(tree, childItem, false)) return;
|
|
243
|
+
tree.children.push(childItem);
|
|
244
244
|
parseTreeItem(childItem, usedItems, inMask || usedAsMask);
|
|
245
245
|
});
|
|
246
246
|
}
|
|
@@ -61,7 +61,7 @@ function cleanupInlineStyle(svg) {
|
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
63
|
if (insideClipPathAttributes.has(prop)) {
|
|
64
|
-
if (item.parents.find((item
|
|
64
|
+
if (item.parents.find((item) => item.node.tag === "clipPath")) attribs[prop] = value;
|
|
65
65
|
return;
|
|
66
66
|
}
|
|
67
67
|
if (badSoftwareAttributes.has(prop) || badAttributePrefixes.has(prop.split("-").shift()) || knownIgnoredRules.has(prop) || knownIgnoredRules.has(partial)) return;
|
|
@@ -62,8 +62,8 @@ function cleanupSVGRoot(svg) {
|
|
|
62
62
|
wrapper.children.push(child);
|
|
63
63
|
continue;
|
|
64
64
|
}
|
|
65
|
-
const tagName
|
|
66
|
-
if (tagName
|
|
65
|
+
const tagName = child.tag;
|
|
66
|
+
if (tagName === "style" || tagName === "title" || reusableElementsWithPalette.has(tagName) || maskTags.has(tagName)) root.children.push(child);
|
|
67
67
|
else wrapper.children.push(child);
|
|
68
68
|
}
|
|
69
69
|
root.children.push(wrapper);
|
package/lib/svg/parse-style.js
CHANGED
|
@@ -30,7 +30,7 @@ function parseSVGStyle(svg, callback) {
|
|
|
30
30
|
}
|
|
31
31
|
const tokens = getTokens(content);
|
|
32
32
|
if (!(tokens instanceof Array)) throw new Error("Error parsing style. This parser can handle only basic CSS");
|
|
33
|
-
let changed
|
|
33
|
+
let changed = false;
|
|
34
34
|
const selectorStart = [];
|
|
35
35
|
let newTokens = [];
|
|
36
36
|
while (tokens.length) {
|
|
@@ -105,7 +105,7 @@ function parseSVGStyle(svg, callback) {
|
|
|
105
105
|
assertNotOldCode(result);
|
|
106
106
|
if (isAnimation) {
|
|
107
107
|
if (result !== value) {
|
|
108
|
-
changed
|
|
108
|
+
changed = true;
|
|
109
109
|
token.value = result;
|
|
110
110
|
}
|
|
111
111
|
newTokens.push(token);
|
|
@@ -116,14 +116,14 @@ function parseSVGStyle(svg, callback) {
|
|
|
116
116
|
newTokens.push(token);
|
|
117
117
|
}
|
|
118
118
|
} else {
|
|
119
|
-
changed
|
|
119
|
+
changed = true;
|
|
120
120
|
for (let i = 0; i < skipCount; i++) tokens.shift();
|
|
121
121
|
}
|
|
122
122
|
break;
|
|
123
123
|
}
|
|
124
124
|
case "rule": {
|
|
125
125
|
const value = token.value;
|
|
126
|
-
const selectorTokens = selectorStart.map((index) => newTokens[index]).filter((item
|
|
126
|
+
const selectorTokens = selectorStart.map((index) => newTokens[index]).filter((item) => item !== null);
|
|
127
127
|
const result = callback({
|
|
128
128
|
type: "global",
|
|
129
129
|
prop: token.prop,
|
|
@@ -142,17 +142,17 @@ function parseSVGStyle(svg, callback) {
|
|
|
142
142
|
if (result !== void 0) {
|
|
143
143
|
assertNotOldCode(result);
|
|
144
144
|
if (result !== value) {
|
|
145
|
-
changed
|
|
145
|
+
changed = true;
|
|
146
146
|
token.value = result;
|
|
147
147
|
}
|
|
148
148
|
newTokens.push(token);
|
|
149
|
-
} else changed
|
|
149
|
+
} else changed = true;
|
|
150
150
|
break;
|
|
151
151
|
}
|
|
152
152
|
default: assertNever(token);
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
|
-
if (changed
|
|
155
|
+
if (changed) {
|
|
156
156
|
const tree = tokensTree(newTokens.filter((token) => token !== null));
|
|
157
157
|
if (!tree.length) item.removeNode = true;
|
|
158
158
|
else node.children = [{
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "Collection of functions for cleaning up and parsing SVG for Iconify project",
|
|
5
5
|
"author": "Vjacheslav Trushkin",
|
|
6
|
-
"version": "5.0.
|
|
6
|
+
"version": "5.0.3",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"bugs": "https://github.com/iconify/tools/issues",
|
|
9
9
|
"homepage": "https://github.com/iconify/tools",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"module": "./lib/index.js",
|
|
15
15
|
"types": "./lib/index.d.ts",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@cyberalien/svg-utils": "^1.
|
|
17
|
+
"@cyberalien/svg-utils": "^1.1.1",
|
|
18
18
|
"@iconify/types": "^2.0.0",
|
|
19
19
|
"@iconify/utils": "^3.1.0",
|
|
20
20
|
"fflate": "^0.8.2",
|
|
@@ -26,19 +26,19 @@
|
|
|
26
26
|
"@eslint/eslintrc": "^3.3.3",
|
|
27
27
|
"@eslint/js": "^9.39.2",
|
|
28
28
|
"@types/jest": "^30.0.0",
|
|
29
|
-
"@types/node": "^24.10.
|
|
30
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
31
|
-
"@typescript-eslint/parser": "^8.
|
|
29
|
+
"@types/node": "^24.10.9",
|
|
30
|
+
"@typescript-eslint/eslint-plugin": "^8.54.0",
|
|
31
|
+
"@typescript-eslint/parser": "^8.54.0",
|
|
32
32
|
"cross-env": "^10.1.0",
|
|
33
33
|
"eslint": "^9.39.2",
|
|
34
34
|
"eslint-config-prettier": "^10.1.8",
|
|
35
|
-
"eslint-plugin-prettier": "^5.5.
|
|
35
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
36
36
|
"globals": "^16.5.0",
|
|
37
|
-
"prettier": "^3.
|
|
37
|
+
"prettier": "^3.8.1",
|
|
38
38
|
"rimraf": "^6.1.2",
|
|
39
|
-
"tsdown": "^0.
|
|
39
|
+
"tsdown": "^0.20.1",
|
|
40
40
|
"typescript": "^5.9.3",
|
|
41
|
-
"vitest": "^4.0.
|
|
41
|
+
"vitest": "^4.0.18"
|
|
42
42
|
},
|
|
43
43
|
"exports": {
|
|
44
44
|
"./*": "./*",
|