@iconify/tools 2.2.0 → 2.2.1
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.cjs +1 -0
- package/lib/colors/parse.mjs +1 -0
- package/lib/download/git/index.cjs +1 -0
- package/lib/download/git/index.mjs +1 -0
- package/lib/download/github/index.cjs +7 -1
- package/lib/download/github/index.mjs +7 -1
- package/lib/download/gitlab/index.cjs +7 -1
- package/lib/download/gitlab/index.mjs +7 -1
- package/lib/export/icon-package.cjs +1 -0
- package/lib/export/icon-package.mjs +1 -0
- package/lib/export/json-package.cjs +1 -0
- package/lib/export/json-package.mjs +1 -0
- package/lib/icon-set/index.cjs +90 -0
- package/lib/icon-set/index.mjs +90 -0
- package/lib/import/figma/index.cjs +5 -0
- package/lib/import/figma/index.mjs +5 -0
- package/lib/optimise/svgo.cjs +6 -1
- package/lib/optimise/svgo.mjs +6 -1
- package/lib/svg/cleanup/root-style.cjs +5 -1
- package/lib/svg/cleanup/root-style.mjs +5 -1
- package/lib/svg/cleanup/root-svg.cjs +6 -1
- package/lib/svg/cleanup/root-svg.mjs +6 -1
- package/lib/svg/cleanup/svgo-style.cjs +4 -1
- package/lib/svg/cleanup/svgo-style.mjs +4 -1
- package/lib/svg/data/attributes.cjs +17 -0
- package/lib/svg/data/attributes.mjs +17 -0
- package/lib/svg/data/tags.cjs +6 -0
- package/lib/svg/data/tags.mjs +6 -0
- package/lib/svg/index.cjs +20 -0
- package/lib/svg/index.mjs +20 -0
- package/package.json +12 -12
package/lib/colors/parse.cjs
CHANGED
package/lib/colors/parse.mjs
CHANGED
|
@@ -72,7 +72,13 @@ async function downloadGitHubRepo(options) {
|
|
|
72
72
|
const filename = rootDir + "/" + files[i];
|
|
73
73
|
const stat = await fs.promises.lstat(filename);
|
|
74
74
|
const isDir = stat.isDirectory();
|
|
75
|
-
if (
|
|
75
|
+
if (
|
|
76
|
+
// Remove symbolic links
|
|
77
|
+
stat.isSymbolicLink() || // Remove if directory matches hash to avoid errors extracting zip
|
|
78
|
+
isDir && filename.slice(0 - hashSearch.length) === hashSearch || // Remove if directory and cleanupOldDirectories is not disabled
|
|
79
|
+
isDir && options.cleanupOldDirectories !== false || // Remove if file and cleanupOldFiles is enabled
|
|
80
|
+
!isDir && options.cleanupOldFiles
|
|
81
|
+
) {
|
|
76
82
|
try {
|
|
77
83
|
await fs.promises.rm(filename, {
|
|
78
84
|
force: true,
|
|
@@ -70,7 +70,13 @@ async function downloadGitHubRepo(options) {
|
|
|
70
70
|
const filename = rootDir + "/" + files[i];
|
|
71
71
|
const stat = await promises.lstat(filename);
|
|
72
72
|
const isDir = stat.isDirectory();
|
|
73
|
-
if (
|
|
73
|
+
if (
|
|
74
|
+
// Remove symbolic links
|
|
75
|
+
stat.isSymbolicLink() || // Remove if directory matches hash to avoid errors extracting zip
|
|
76
|
+
isDir && filename.slice(0 - hashSearch.length) === hashSearch || // Remove if directory and cleanupOldDirectories is not disabled
|
|
77
|
+
isDir && options.cleanupOldDirectories !== false || // Remove if file and cleanupOldFiles is enabled
|
|
78
|
+
!isDir && options.cleanupOldFiles
|
|
79
|
+
) {
|
|
74
80
|
try {
|
|
75
81
|
await promises.rm(filename, {
|
|
76
82
|
force: true,
|
|
@@ -72,7 +72,13 @@ async function downloadGitLabRepo(options) {
|
|
|
72
72
|
const filename = rootDir + "/" + files[i];
|
|
73
73
|
const stat = await fs.promises.lstat(filename);
|
|
74
74
|
const isDir = stat.isDirectory();
|
|
75
|
-
if (
|
|
75
|
+
if (
|
|
76
|
+
// Remove symbolic links
|
|
77
|
+
stat.isSymbolicLink() || // Remove if directory matches hash to avoid errors extracting zip
|
|
78
|
+
isDir && filename.slice(0 - hashSearch.length) === hashSearch || // Remove if directory and cleanupOldDirectories is not disabled
|
|
79
|
+
isDir && options.cleanupOldDirectories !== false || // Remove if file and cleanupOldFiles is enabled
|
|
80
|
+
!isDir && options.cleanupOldFiles
|
|
81
|
+
) {
|
|
76
82
|
try {
|
|
77
83
|
await fs.promises.rm(filename, {
|
|
78
84
|
force: true,
|
|
@@ -70,7 +70,13 @@ async function downloadGitLabRepo(options) {
|
|
|
70
70
|
const filename = rootDir + "/" + files[i];
|
|
71
71
|
const stat = await promises.lstat(filename);
|
|
72
72
|
const isDir = stat.isDirectory();
|
|
73
|
-
if (
|
|
73
|
+
if (
|
|
74
|
+
// Remove symbolic links
|
|
75
|
+
stat.isSymbolicLink() || // Remove if directory matches hash to avoid errors extracting zip
|
|
76
|
+
isDir && filename.slice(0 - hashSearch.length) === hashSearch || // Remove if directory and cleanupOldDirectories is not disabled
|
|
77
|
+
isDir && options.cleanupOldDirectories !== false || // Remove if file and cleanupOldFiles is enabled
|
|
78
|
+
!isDir && options.cleanupOldFiles
|
|
79
|
+
) {
|
|
74
80
|
try {
|
|
75
81
|
await promises.rm(filename, {
|
|
76
82
|
force: true,
|
|
@@ -45,6 +45,7 @@ async function exportIconPackage(iconSet, options) {
|
|
|
45
45
|
...customPackageProps,
|
|
46
46
|
dependencies: dependencies || {
|
|
47
47
|
"@iconify/types": "*"
|
|
48
|
+
// '^' + (await getTypesVersion()),
|
|
48
49
|
}
|
|
49
50
|
};
|
|
50
51
|
await misc_writeJson.writeJSONFile(dir + "/package.json", packageJSON);
|
package/lib/icon-set/index.cjs
CHANGED
|
@@ -17,9 +17,15 @@ function sortThemeKeys(keys) {
|
|
|
17
17
|
);
|
|
18
18
|
}
|
|
19
19
|
class IconSet {
|
|
20
|
+
/**
|
|
21
|
+
* Load icon set
|
|
22
|
+
*/
|
|
20
23
|
constructor(data) {
|
|
21
24
|
this.load(data);
|
|
22
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Load icon set
|
|
28
|
+
*/
|
|
23
29
|
load(data) {
|
|
24
30
|
this.prefix = data.prefix;
|
|
25
31
|
const defaultProps = iconSet_props.filterProps(data, defaults.defaultIconDimensions, true);
|
|
@@ -129,15 +135,27 @@ class IconSet {
|
|
|
129
135
|
});
|
|
130
136
|
this.lastModified = data.lastModified || 0;
|
|
131
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Update last modification time
|
|
140
|
+
*/
|
|
132
141
|
updateLastModified(value) {
|
|
133
142
|
this.lastModified = value || Math.floor(Date.now() / 1e3);
|
|
134
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* List icons
|
|
146
|
+
*/
|
|
135
147
|
list(types = ["icon", "variation"]) {
|
|
136
148
|
return Object.keys(this.entries).filter((name) => {
|
|
137
149
|
const type = this.entries[name].type;
|
|
138
150
|
return types.indexOf(type) !== -1;
|
|
139
151
|
});
|
|
140
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* forEach function to loop through all entries.
|
|
155
|
+
* Supports asynchronous callbacks.
|
|
156
|
+
*
|
|
157
|
+
* Callback should return false to stop loop.
|
|
158
|
+
*/
|
|
141
159
|
async forEach(callback, types = ["icon", "variation", "alias"]) {
|
|
142
160
|
const names = this.list(types);
|
|
143
161
|
for (let i = 0; i < names.length; i++) {
|
|
@@ -154,6 +172,17 @@ class IconSet {
|
|
|
154
172
|
}
|
|
155
173
|
}
|
|
156
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* Get parent icons tree
|
|
177
|
+
*
|
|
178
|
+
* Returns parent icons list for each icon, null if failed to resolve.
|
|
179
|
+
* In parent icons list, first element is a direct parent, last is icon. Does not include item.
|
|
180
|
+
*
|
|
181
|
+
* Examples:
|
|
182
|
+
* 'alias3': ['alias2', 'alias1', 'icon']
|
|
183
|
+
* 'icon': []
|
|
184
|
+
* 'bad-icon': null
|
|
185
|
+
*/
|
|
157
186
|
getTree(names) {
|
|
158
187
|
const entries = this.entries;
|
|
159
188
|
const resolved = /* @__PURE__ */ Object.create(null);
|
|
@@ -200,6 +229,9 @@ class IconSet {
|
|
|
200
229
|
tree.forEach(parse);
|
|
201
230
|
return result && full ? { ...defaults.defaultIconProps, ...result } : result;
|
|
202
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* Generate HTML
|
|
234
|
+
*/
|
|
203
235
|
toString(name, customisations = {
|
|
204
236
|
width: "auto",
|
|
205
237
|
height: "auto"
|
|
@@ -214,10 +246,16 @@ class IconSet {
|
|
|
214
246
|
).join("");
|
|
215
247
|
return `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"${attributes}>${result.body}</svg>`;
|
|
216
248
|
}
|
|
249
|
+
/**
|
|
250
|
+
* Get SVG instance for icon
|
|
251
|
+
*/
|
|
217
252
|
toSVG(name) {
|
|
218
253
|
const html = this.toString(name);
|
|
219
254
|
return html ? new svg_index.SVG(html) : null;
|
|
220
255
|
}
|
|
256
|
+
/**
|
|
257
|
+
* Export icon set
|
|
258
|
+
*/
|
|
221
259
|
export(validate = true) {
|
|
222
260
|
const icons = /* @__PURE__ */ Object.create(null);
|
|
223
261
|
const aliases = /* @__PURE__ */ Object.create(null);
|
|
@@ -304,6 +342,9 @@ class IconSet {
|
|
|
304
342
|
minify.minifyIconSet(result);
|
|
305
343
|
return result;
|
|
306
344
|
}
|
|
345
|
+
/**
|
|
346
|
+
* Get characters map
|
|
347
|
+
*/
|
|
307
348
|
chars(names) {
|
|
308
349
|
const chars = /* @__PURE__ */ Object.create(null);
|
|
309
350
|
if (!names) {
|
|
@@ -318,6 +359,9 @@ class IconSet {
|
|
|
318
359
|
}
|
|
319
360
|
return chars;
|
|
320
361
|
}
|
|
362
|
+
/**
|
|
363
|
+
* Filter icons
|
|
364
|
+
*/
|
|
321
365
|
_filter(callback) {
|
|
322
366
|
const names = [];
|
|
323
367
|
for (const key in this.entries) {
|
|
@@ -341,6 +385,9 @@ class IconSet {
|
|
|
341
385
|
}
|
|
342
386
|
return names;
|
|
343
387
|
}
|
|
388
|
+
/**
|
|
389
|
+
* Count icons
|
|
390
|
+
*/
|
|
344
391
|
count() {
|
|
345
392
|
return this._filter((_key, item, icon) => {
|
|
346
393
|
if (item.type === "alias" || item.props.hidden || icon?.hidden) {
|
|
@@ -349,6 +396,9 @@ class IconSet {
|
|
|
349
396
|
return true;
|
|
350
397
|
}).length;
|
|
351
398
|
}
|
|
399
|
+
/**
|
|
400
|
+
* Find category by title
|
|
401
|
+
*/
|
|
352
402
|
findCategory(title, add) {
|
|
353
403
|
const categoryItem = Array.from(this.categories).find(
|
|
354
404
|
(item) => item.title === title
|
|
@@ -366,6 +416,11 @@ class IconSet {
|
|
|
366
416
|
}
|
|
367
417
|
return null;
|
|
368
418
|
}
|
|
419
|
+
/**
|
|
420
|
+
* Count icons in category, remove category if empty
|
|
421
|
+
*
|
|
422
|
+
* Hidden icons and aliases do not count
|
|
423
|
+
*/
|
|
369
424
|
listCategory(category) {
|
|
370
425
|
const categoryItem = typeof category === "string" ? this.findCategory(category, false) : category;
|
|
371
426
|
if (!categoryItem) {
|
|
@@ -385,9 +440,17 @@ class IconSet {
|
|
|
385
440
|
}
|
|
386
441
|
return icons;
|
|
387
442
|
}
|
|
443
|
+
/**
|
|
444
|
+
* Check if icon exists
|
|
445
|
+
*/
|
|
388
446
|
exists(name) {
|
|
389
447
|
return !!this.entries[name];
|
|
390
448
|
}
|
|
449
|
+
/**
|
|
450
|
+
* Remove icons. Returns number of removed icons
|
|
451
|
+
*
|
|
452
|
+
* If removeDependencies is a string, it represents new parent for all aliases of removed icon. New parent cannot be alias or variation.
|
|
453
|
+
*/
|
|
391
454
|
remove(name, removeDependencies = true) {
|
|
392
455
|
const entries = this.entries;
|
|
393
456
|
if (typeof removeDependencies === "string") {
|
|
@@ -430,6 +493,9 @@ class IconSet {
|
|
|
430
493
|
}
|
|
431
494
|
return count;
|
|
432
495
|
}
|
|
496
|
+
/**
|
|
497
|
+
* Remove icon
|
|
498
|
+
*/
|
|
433
499
|
rename(oldName, newName) {
|
|
434
500
|
const entries = this.entries;
|
|
435
501
|
if (entries[newName]) {
|
|
@@ -458,6 +524,9 @@ class IconSet {
|
|
|
458
524
|
this.updateLastModified();
|
|
459
525
|
return true;
|
|
460
526
|
}
|
|
527
|
+
/**
|
|
528
|
+
* Add/update item
|
|
529
|
+
*/
|
|
461
530
|
setItem(name, item) {
|
|
462
531
|
switch (item.type) {
|
|
463
532
|
case "alias":
|
|
@@ -471,6 +540,9 @@ class IconSet {
|
|
|
471
540
|
this.updateLastModified();
|
|
472
541
|
return true;
|
|
473
542
|
}
|
|
543
|
+
/**
|
|
544
|
+
* Add/update icon
|
|
545
|
+
*/
|
|
474
546
|
setIcon(name, icon) {
|
|
475
547
|
return this.setItem(name, {
|
|
476
548
|
type: "icon",
|
|
@@ -480,6 +552,9 @@ class IconSet {
|
|
|
480
552
|
categories: /* @__PURE__ */ new Set()
|
|
481
553
|
});
|
|
482
554
|
}
|
|
555
|
+
/**
|
|
556
|
+
* Add/update alias without props
|
|
557
|
+
*/
|
|
483
558
|
setAlias(name, parent) {
|
|
484
559
|
return this.setItem(name, {
|
|
485
560
|
type: "alias",
|
|
@@ -487,6 +562,9 @@ class IconSet {
|
|
|
487
562
|
chars: /* @__PURE__ */ new Set()
|
|
488
563
|
});
|
|
489
564
|
}
|
|
565
|
+
/**
|
|
566
|
+
* Add/update alias with props
|
|
567
|
+
*/
|
|
490
568
|
setVariation(name, parent, props) {
|
|
491
569
|
return this.setItem(name, {
|
|
492
570
|
type: "variation",
|
|
@@ -495,6 +573,9 @@ class IconSet {
|
|
|
495
573
|
chars: /* @__PURE__ */ new Set()
|
|
496
574
|
});
|
|
497
575
|
}
|
|
576
|
+
/**
|
|
577
|
+
* Icon from SVG. Updates old icon if it exists
|
|
578
|
+
*/
|
|
498
579
|
fromSVG(name, svg) {
|
|
499
580
|
const props = { ...svg.viewBox };
|
|
500
581
|
const body = svg.getBody();
|
|
@@ -516,6 +597,9 @@ class IconSet {
|
|
|
516
597
|
...props
|
|
517
598
|
});
|
|
518
599
|
}
|
|
600
|
+
/**
|
|
601
|
+
* Add or remove character for icon
|
|
602
|
+
*/
|
|
519
603
|
toggleCharacter(iconName, char, add) {
|
|
520
604
|
const item = this.entries[iconName];
|
|
521
605
|
if (!item) {
|
|
@@ -527,6 +611,9 @@ class IconSet {
|
|
|
527
611
|
}
|
|
528
612
|
return false;
|
|
529
613
|
}
|
|
614
|
+
/**
|
|
615
|
+
* Add or remove category for icon
|
|
616
|
+
*/
|
|
530
617
|
toggleCategory(iconName, category, add) {
|
|
531
618
|
const item = this.entries[iconName];
|
|
532
619
|
const categoryItem = this.findCategory(category, add);
|
|
@@ -543,6 +630,9 @@ class IconSet {
|
|
|
543
630
|
}
|
|
544
631
|
return false;
|
|
545
632
|
}
|
|
633
|
+
/**
|
|
634
|
+
* Find icons that belong to theme
|
|
635
|
+
*/
|
|
546
636
|
checkTheme(prefix) {
|
|
547
637
|
const themes = prefix ? this.prefixes : this.suffixes;
|
|
548
638
|
const keys = sortThemeKeys(Object.keys(themes));
|
package/lib/icon-set/index.mjs
CHANGED
|
@@ -15,9 +15,15 @@ function sortThemeKeys(keys) {
|
|
|
15
15
|
);
|
|
16
16
|
}
|
|
17
17
|
class IconSet {
|
|
18
|
+
/**
|
|
19
|
+
* Load icon set
|
|
20
|
+
*/
|
|
18
21
|
constructor(data) {
|
|
19
22
|
this.load(data);
|
|
20
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Load icon set
|
|
26
|
+
*/
|
|
21
27
|
load(data) {
|
|
22
28
|
this.prefix = data.prefix;
|
|
23
29
|
const defaultProps = filterProps(data, defaultIconDimensions, true);
|
|
@@ -127,15 +133,27 @@ class IconSet {
|
|
|
127
133
|
});
|
|
128
134
|
this.lastModified = data.lastModified || 0;
|
|
129
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Update last modification time
|
|
138
|
+
*/
|
|
130
139
|
updateLastModified(value) {
|
|
131
140
|
this.lastModified = value || Math.floor(Date.now() / 1e3);
|
|
132
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* List icons
|
|
144
|
+
*/
|
|
133
145
|
list(types = ["icon", "variation"]) {
|
|
134
146
|
return Object.keys(this.entries).filter((name) => {
|
|
135
147
|
const type = this.entries[name].type;
|
|
136
148
|
return types.indexOf(type) !== -1;
|
|
137
149
|
});
|
|
138
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* forEach function to loop through all entries.
|
|
153
|
+
* Supports asynchronous callbacks.
|
|
154
|
+
*
|
|
155
|
+
* Callback should return false to stop loop.
|
|
156
|
+
*/
|
|
139
157
|
async forEach(callback, types = ["icon", "variation", "alias"]) {
|
|
140
158
|
const names = this.list(types);
|
|
141
159
|
for (let i = 0; i < names.length; i++) {
|
|
@@ -152,6 +170,17 @@ class IconSet {
|
|
|
152
170
|
}
|
|
153
171
|
}
|
|
154
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* Get parent icons tree
|
|
175
|
+
*
|
|
176
|
+
* Returns parent icons list for each icon, null if failed to resolve.
|
|
177
|
+
* In parent icons list, first element is a direct parent, last is icon. Does not include item.
|
|
178
|
+
*
|
|
179
|
+
* Examples:
|
|
180
|
+
* 'alias3': ['alias2', 'alias1', 'icon']
|
|
181
|
+
* 'icon': []
|
|
182
|
+
* 'bad-icon': null
|
|
183
|
+
*/
|
|
155
184
|
getTree(names) {
|
|
156
185
|
const entries = this.entries;
|
|
157
186
|
const resolved = /* @__PURE__ */ Object.create(null);
|
|
@@ -198,6 +227,9 @@ class IconSet {
|
|
|
198
227
|
tree.forEach(parse);
|
|
199
228
|
return result && full ? { ...defaultIconProps, ...result } : result;
|
|
200
229
|
}
|
|
230
|
+
/**
|
|
231
|
+
* Generate HTML
|
|
232
|
+
*/
|
|
201
233
|
toString(name, customisations = {
|
|
202
234
|
width: "auto",
|
|
203
235
|
height: "auto"
|
|
@@ -212,10 +244,16 @@ class IconSet {
|
|
|
212
244
|
).join("");
|
|
213
245
|
return `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"${attributes}>${result.body}</svg>`;
|
|
214
246
|
}
|
|
247
|
+
/**
|
|
248
|
+
* Get SVG instance for icon
|
|
249
|
+
*/
|
|
215
250
|
toSVG(name) {
|
|
216
251
|
const html = this.toString(name);
|
|
217
252
|
return html ? new SVG(html) : null;
|
|
218
253
|
}
|
|
254
|
+
/**
|
|
255
|
+
* Export icon set
|
|
256
|
+
*/
|
|
219
257
|
export(validate = true) {
|
|
220
258
|
const icons = /* @__PURE__ */ Object.create(null);
|
|
221
259
|
const aliases = /* @__PURE__ */ Object.create(null);
|
|
@@ -302,6 +340,9 @@ class IconSet {
|
|
|
302
340
|
minifyIconSet(result);
|
|
303
341
|
return result;
|
|
304
342
|
}
|
|
343
|
+
/**
|
|
344
|
+
* Get characters map
|
|
345
|
+
*/
|
|
305
346
|
chars(names) {
|
|
306
347
|
const chars = /* @__PURE__ */ Object.create(null);
|
|
307
348
|
if (!names) {
|
|
@@ -316,6 +357,9 @@ class IconSet {
|
|
|
316
357
|
}
|
|
317
358
|
return chars;
|
|
318
359
|
}
|
|
360
|
+
/**
|
|
361
|
+
* Filter icons
|
|
362
|
+
*/
|
|
319
363
|
_filter(callback) {
|
|
320
364
|
const names = [];
|
|
321
365
|
for (const key in this.entries) {
|
|
@@ -339,6 +383,9 @@ class IconSet {
|
|
|
339
383
|
}
|
|
340
384
|
return names;
|
|
341
385
|
}
|
|
386
|
+
/**
|
|
387
|
+
* Count icons
|
|
388
|
+
*/
|
|
342
389
|
count() {
|
|
343
390
|
return this._filter((_key, item, icon) => {
|
|
344
391
|
if (item.type === "alias" || item.props.hidden || icon?.hidden) {
|
|
@@ -347,6 +394,9 @@ class IconSet {
|
|
|
347
394
|
return true;
|
|
348
395
|
}).length;
|
|
349
396
|
}
|
|
397
|
+
/**
|
|
398
|
+
* Find category by title
|
|
399
|
+
*/
|
|
350
400
|
findCategory(title, add) {
|
|
351
401
|
const categoryItem = Array.from(this.categories).find(
|
|
352
402
|
(item) => item.title === title
|
|
@@ -364,6 +414,11 @@ class IconSet {
|
|
|
364
414
|
}
|
|
365
415
|
return null;
|
|
366
416
|
}
|
|
417
|
+
/**
|
|
418
|
+
* Count icons in category, remove category if empty
|
|
419
|
+
*
|
|
420
|
+
* Hidden icons and aliases do not count
|
|
421
|
+
*/
|
|
367
422
|
listCategory(category) {
|
|
368
423
|
const categoryItem = typeof category === "string" ? this.findCategory(category, false) : category;
|
|
369
424
|
if (!categoryItem) {
|
|
@@ -383,9 +438,17 @@ class IconSet {
|
|
|
383
438
|
}
|
|
384
439
|
return icons;
|
|
385
440
|
}
|
|
441
|
+
/**
|
|
442
|
+
* Check if icon exists
|
|
443
|
+
*/
|
|
386
444
|
exists(name) {
|
|
387
445
|
return !!this.entries[name];
|
|
388
446
|
}
|
|
447
|
+
/**
|
|
448
|
+
* Remove icons. Returns number of removed icons
|
|
449
|
+
*
|
|
450
|
+
* If removeDependencies is a string, it represents new parent for all aliases of removed icon. New parent cannot be alias or variation.
|
|
451
|
+
*/
|
|
389
452
|
remove(name, removeDependencies = true) {
|
|
390
453
|
const entries = this.entries;
|
|
391
454
|
if (typeof removeDependencies === "string") {
|
|
@@ -428,6 +491,9 @@ class IconSet {
|
|
|
428
491
|
}
|
|
429
492
|
return count;
|
|
430
493
|
}
|
|
494
|
+
/**
|
|
495
|
+
* Remove icon
|
|
496
|
+
*/
|
|
431
497
|
rename(oldName, newName) {
|
|
432
498
|
const entries = this.entries;
|
|
433
499
|
if (entries[newName]) {
|
|
@@ -456,6 +522,9 @@ class IconSet {
|
|
|
456
522
|
this.updateLastModified();
|
|
457
523
|
return true;
|
|
458
524
|
}
|
|
525
|
+
/**
|
|
526
|
+
* Add/update item
|
|
527
|
+
*/
|
|
459
528
|
setItem(name, item) {
|
|
460
529
|
switch (item.type) {
|
|
461
530
|
case "alias":
|
|
@@ -469,6 +538,9 @@ class IconSet {
|
|
|
469
538
|
this.updateLastModified();
|
|
470
539
|
return true;
|
|
471
540
|
}
|
|
541
|
+
/**
|
|
542
|
+
* Add/update icon
|
|
543
|
+
*/
|
|
472
544
|
setIcon(name, icon) {
|
|
473
545
|
return this.setItem(name, {
|
|
474
546
|
type: "icon",
|
|
@@ -478,6 +550,9 @@ class IconSet {
|
|
|
478
550
|
categories: /* @__PURE__ */ new Set()
|
|
479
551
|
});
|
|
480
552
|
}
|
|
553
|
+
/**
|
|
554
|
+
* Add/update alias without props
|
|
555
|
+
*/
|
|
481
556
|
setAlias(name, parent) {
|
|
482
557
|
return this.setItem(name, {
|
|
483
558
|
type: "alias",
|
|
@@ -485,6 +560,9 @@ class IconSet {
|
|
|
485
560
|
chars: /* @__PURE__ */ new Set()
|
|
486
561
|
});
|
|
487
562
|
}
|
|
563
|
+
/**
|
|
564
|
+
* Add/update alias with props
|
|
565
|
+
*/
|
|
488
566
|
setVariation(name, parent, props) {
|
|
489
567
|
return this.setItem(name, {
|
|
490
568
|
type: "variation",
|
|
@@ -493,6 +571,9 @@ class IconSet {
|
|
|
493
571
|
chars: /* @__PURE__ */ new Set()
|
|
494
572
|
});
|
|
495
573
|
}
|
|
574
|
+
/**
|
|
575
|
+
* Icon from SVG. Updates old icon if it exists
|
|
576
|
+
*/
|
|
496
577
|
fromSVG(name, svg) {
|
|
497
578
|
const props = { ...svg.viewBox };
|
|
498
579
|
const body = svg.getBody();
|
|
@@ -514,6 +595,9 @@ class IconSet {
|
|
|
514
595
|
...props
|
|
515
596
|
});
|
|
516
597
|
}
|
|
598
|
+
/**
|
|
599
|
+
* Add or remove character for icon
|
|
600
|
+
*/
|
|
517
601
|
toggleCharacter(iconName, char, add) {
|
|
518
602
|
const item = this.entries[iconName];
|
|
519
603
|
if (!item) {
|
|
@@ -525,6 +609,9 @@ class IconSet {
|
|
|
525
609
|
}
|
|
526
610
|
return false;
|
|
527
611
|
}
|
|
612
|
+
/**
|
|
613
|
+
* Add or remove category for icon
|
|
614
|
+
*/
|
|
528
615
|
toggleCategory(iconName, category, add) {
|
|
529
616
|
const item = this.entries[iconName];
|
|
530
617
|
const categoryItem = this.findCategory(category, add);
|
|
@@ -541,6 +628,9 @@ class IconSet {
|
|
|
541
628
|
}
|
|
542
629
|
return false;
|
|
543
630
|
}
|
|
631
|
+
/**
|
|
632
|
+
* Find icons that belong to theme
|
|
633
|
+
*/
|
|
544
634
|
checkTheme(prefix) {
|
|
545
635
|
const themes = prefix ? this.prefixes : this.suffixes;
|
|
546
636
|
const keys = sortThemeKeys(Object.keys(themes));
|
|
@@ -42,10 +42,12 @@ require('../../misc/scan.cjs');
|
|
|
42
42
|
|
|
43
43
|
async function importFromFigma(options) {
|
|
44
44
|
const cacheOptions = options.cacheDir ? {
|
|
45
|
+
// 24 hours
|
|
45
46
|
ttl: options.cacheAPITTL || 60 * 60 * 24,
|
|
46
47
|
dir: options.cacheDir
|
|
47
48
|
} : void 0;
|
|
48
49
|
const cacheSVGOptions = options.cacheDir ? {
|
|
50
|
+
// 30 days
|
|
49
51
|
ttl: options.cacheSVGTTL || 60 * 60 * 24 * 30,
|
|
50
52
|
dir: options.cacheDir
|
|
51
53
|
} : void 0;
|
|
@@ -93,12 +95,15 @@ async function importFromFigma(options) {
|
|
|
93
95
|
}
|
|
94
96
|
}
|
|
95
97
|
const result = {
|
|
98
|
+
// Document
|
|
96
99
|
name: document.name,
|
|
97
100
|
version: document.version,
|
|
98
101
|
lastModified: document.lastModified,
|
|
102
|
+
// Counters
|
|
99
103
|
nodesCount: nodes.nodesCount,
|
|
100
104
|
generatedIconsCount: nodes.generatedIconsCount,
|
|
101
105
|
downloadedIconsCount: nodes.downloadedIconsCount,
|
|
106
|
+
// Icon set
|
|
102
107
|
iconSet,
|
|
103
108
|
missing
|
|
104
109
|
};
|
|
@@ -40,10 +40,12 @@ import '../../misc/scan.mjs';
|
|
|
40
40
|
|
|
41
41
|
async function importFromFigma(options) {
|
|
42
42
|
const cacheOptions = options.cacheDir ? {
|
|
43
|
+
// 24 hours
|
|
43
44
|
ttl: options.cacheAPITTL || 60 * 60 * 24,
|
|
44
45
|
dir: options.cacheDir
|
|
45
46
|
} : void 0;
|
|
46
47
|
const cacheSVGOptions = options.cacheDir ? {
|
|
48
|
+
// 30 days
|
|
47
49
|
ttl: options.cacheSVGTTL || 60 * 60 * 24 * 30,
|
|
48
50
|
dir: options.cacheDir
|
|
49
51
|
} : void 0;
|
|
@@ -91,12 +93,15 @@ async function importFromFigma(options) {
|
|
|
91
93
|
}
|
|
92
94
|
}
|
|
93
95
|
const result = {
|
|
96
|
+
// Document
|
|
94
97
|
name: document.name,
|
|
95
98
|
version: document.version,
|
|
96
99
|
lastModified: document.lastModified,
|
|
100
|
+
// Counters
|
|
97
101
|
nodesCount: nodes.nodesCount,
|
|
98
102
|
generatedIconsCount: nodes.generatedIconsCount,
|
|
99
103
|
downloadedIconsCount: nodes.downloadedIconsCount,
|
|
104
|
+
// Icon set
|
|
100
105
|
iconSet,
|
|
101
106
|
missing
|
|
102
107
|
};
|
package/lib/optimise/svgo.cjs
CHANGED
|
@@ -26,7 +26,9 @@ function getSVGOPlugins(options) {
|
|
|
26
26
|
"collapseGroups",
|
|
27
27
|
"sortDefsChildren",
|
|
28
28
|
"sortAttrs",
|
|
29
|
+
// Plugins that are bugged when using animations
|
|
29
30
|
...options.animated ? [] : ["removeUselessStrokeAndFill"],
|
|
31
|
+
// Plugins that modify shapes or are bugged when using animations
|
|
30
32
|
...options.animated || options.keepShapes ? [] : [
|
|
31
33
|
"removeHiddenElems",
|
|
32
34
|
"convertShapeToPath",
|
|
@@ -43,9 +45,12 @@ function getSVGOPlugins(options) {
|
|
|
43
45
|
noSpaceAfterFlags: true
|
|
44
46
|
}
|
|
45
47
|
},
|
|
48
|
+
// 'removeOffCanvasPaths', // bugged for some icons
|
|
46
49
|
"reusePaths"
|
|
47
50
|
],
|
|
48
|
-
|
|
51
|
+
// Clean up IDs, first run
|
|
52
|
+
// Sometimes bugs out on animated icons. Do not use with animations!
|
|
53
|
+
...!options.animated && options.cleanupIDs !== false ? ["cleanupIds"] : []
|
|
49
54
|
];
|
|
50
55
|
}
|
|
51
56
|
function runSVGO(svg, options = {}) {
|
package/lib/optimise/svgo.mjs
CHANGED
|
@@ -24,7 +24,9 @@ function getSVGOPlugins(options) {
|
|
|
24
24
|
"collapseGroups",
|
|
25
25
|
"sortDefsChildren",
|
|
26
26
|
"sortAttrs",
|
|
27
|
+
// Plugins that are bugged when using animations
|
|
27
28
|
...options.animated ? [] : ["removeUselessStrokeAndFill"],
|
|
29
|
+
// Plugins that modify shapes or are bugged when using animations
|
|
28
30
|
...options.animated || options.keepShapes ? [] : [
|
|
29
31
|
"removeHiddenElems",
|
|
30
32
|
"convertShapeToPath",
|
|
@@ -41,9 +43,12 @@ function getSVGOPlugins(options) {
|
|
|
41
43
|
noSpaceAfterFlags: true
|
|
42
44
|
}
|
|
43
45
|
},
|
|
46
|
+
// 'removeOffCanvasPaths', // bugged for some icons
|
|
44
47
|
"reusePaths"
|
|
45
48
|
],
|
|
46
|
-
|
|
49
|
+
// Clean up IDs, first run
|
|
50
|
+
// Sometimes bugs out on animated icons. Do not use with animations!
|
|
51
|
+
...!options.animated && options.cleanupIDs !== false ? ["cleanupIds"] : []
|
|
47
52
|
];
|
|
48
53
|
}
|
|
49
54
|
function runSVGO(svg, options = {}) {
|
|
@@ -12,7 +12,11 @@ require('../parse.cjs');
|
|
|
12
12
|
|
|
13
13
|
function cleanupRootStyle(svg) {
|
|
14
14
|
return svg_parseStyle.parseSVGStyle(svg, (item) => {
|
|
15
|
-
if (
|
|
15
|
+
if (
|
|
16
|
+
// If global style
|
|
17
|
+
item.type === "global" && // If selector tokens contain at-rule
|
|
18
|
+
item.selectorTokens.find((token) => token.type === "at-rule")
|
|
19
|
+
) {
|
|
16
20
|
return;
|
|
17
21
|
}
|
|
18
22
|
return item.value;
|
|
@@ -10,7 +10,11 @@ import '../parse.mjs';
|
|
|
10
10
|
|
|
11
11
|
function cleanupRootStyle(svg) {
|
|
12
12
|
return parseSVGStyle(svg, (item) => {
|
|
13
|
-
if (
|
|
13
|
+
if (
|
|
14
|
+
// If global style
|
|
15
|
+
item.type === "global" && // If selector tokens contain at-rule
|
|
16
|
+
item.selectorTokens.find((token) => token.type === "at-rule")
|
|
17
|
+
) {
|
|
14
18
|
return;
|
|
15
19
|
}
|
|
16
20
|
return item.value;
|
|
@@ -48,7 +48,12 @@ function cleanupSVGRoot(svg) {
|
|
|
48
48
|
}
|
|
49
49
|
throw new Error(`Unexpected attribute "${attr}" on <${tagName}>`);
|
|
50
50
|
}
|
|
51
|
-
if (
|
|
51
|
+
if (
|
|
52
|
+
// Events
|
|
53
|
+
attr.slice(0, 2) === "on" || // aria-stuff
|
|
54
|
+
attr.slice(0, 5) === "aria-" || // Junk
|
|
55
|
+
attr.slice(0, 6) === "xmlns:"
|
|
56
|
+
) {
|
|
52
57
|
$root.removeAttr(attr);
|
|
53
58
|
return;
|
|
54
59
|
}
|
|
@@ -46,7 +46,12 @@ function cleanupSVGRoot(svg) {
|
|
|
46
46
|
}
|
|
47
47
|
throw new Error(`Unexpected attribute "${attr}" on <${tagName}>`);
|
|
48
48
|
}
|
|
49
|
-
if (
|
|
49
|
+
if (
|
|
50
|
+
// Events
|
|
51
|
+
attr.slice(0, 2) === "on" || // aria-stuff
|
|
52
|
+
attr.slice(0, 5) === "aria-" || // Junk
|
|
53
|
+
attr.slice(0, 6) === "xmlns:"
|
|
54
|
+
) {
|
|
50
55
|
$root.removeAttr(attr);
|
|
51
56
|
return;
|
|
52
57
|
}
|
|
@@ -19,7 +19,10 @@ async function convertStyleToAttrs(svg) {
|
|
|
19
19
|
let hasStyle = false;
|
|
20
20
|
await svg_parseStyle.parseSVGStyle(svg, (item) => {
|
|
21
21
|
const prop = item.prop;
|
|
22
|
-
if (
|
|
22
|
+
if (
|
|
23
|
+
// Attributes / properties now allowed
|
|
24
|
+
svg_data_attributes.badAttributes.has(prop) || svg_data_attributes.badSoftwareAttributes.has(prop) || svg_data_attributes.badAttributePrefixes.has(prop.split("-").shift())
|
|
25
|
+
) {
|
|
23
26
|
return void 0;
|
|
24
27
|
}
|
|
25
28
|
hasStyle = true;
|
|
@@ -17,7 +17,10 @@ async function convertStyleToAttrs(svg) {
|
|
|
17
17
|
let hasStyle = false;
|
|
18
18
|
await parseSVGStyle(svg, (item) => {
|
|
19
19
|
const prop = item.prop;
|
|
20
|
-
if (
|
|
20
|
+
if (
|
|
21
|
+
// Attributes / properties now allowed
|
|
22
|
+
badAttributes.has(prop) || badSoftwareAttributes.has(prop) || badAttributePrefixes.has(prop.split("-").shift())
|
|
23
|
+
) {
|
|
21
24
|
return void 0;
|
|
22
25
|
}
|
|
23
26
|
hasStyle = true;
|
|
@@ -29,6 +29,7 @@ const badSoftwareAttributes = /* @__PURE__ */ new Set([
|
|
|
29
29
|
"overflow",
|
|
30
30
|
"marker",
|
|
31
31
|
"white-space",
|
|
32
|
+
// Font stuff
|
|
32
33
|
"direction"
|
|
33
34
|
]);
|
|
34
35
|
const badAttributePrefixes = /* @__PURE__ */ new Set([
|
|
@@ -37,6 +38,7 @@ const badAttributePrefixes = /* @__PURE__ */ new Set([
|
|
|
37
38
|
"block",
|
|
38
39
|
"data",
|
|
39
40
|
"aria",
|
|
41
|
+
// Font stuff
|
|
40
42
|
"text",
|
|
41
43
|
"font",
|
|
42
44
|
"letter",
|
|
@@ -44,6 +46,7 @@ const badAttributePrefixes = /* @__PURE__ */ new Set([
|
|
|
44
46
|
"word",
|
|
45
47
|
"line",
|
|
46
48
|
"writing",
|
|
49
|
+
// Prefix for browser specific stuff
|
|
47
50
|
""
|
|
48
51
|
]);
|
|
49
52
|
const commonAttributes = /* @__PURE__ */ new Set(["id"]);
|
|
@@ -155,12 +158,15 @@ const tagSpecificAnimatedAttributes = {
|
|
|
155
158
|
rect: /* @__PURE__ */ new Set(["x", "y", "width", "height", "rx", "ry"])
|
|
156
159
|
};
|
|
157
160
|
const tagSpecificPresentationalAttributes = {
|
|
161
|
+
// SVG
|
|
158
162
|
svg: /* @__PURE__ */ new Set(["width", "height", ...presentationalAttributes]),
|
|
163
|
+
// Defnitions, containers and masks
|
|
159
164
|
clipPath: /* @__PURE__ */ new Set([...presentationalAttributes]),
|
|
160
165
|
defs: /* @__PURE__ */ new Set([]),
|
|
161
166
|
g: /* @__PURE__ */ new Set([...presentationalAttributes]),
|
|
162
167
|
mask: /* @__PURE__ */ new Set(["x", "y", "width", "height", ...presentationalAttributes]),
|
|
163
168
|
symbol: /* @__PURE__ */ new Set(["x", "y", "width", "height", ...presentationalAttributes]),
|
|
169
|
+
// Use
|
|
164
170
|
use: /* @__PURE__ */ new Set([
|
|
165
171
|
"x",
|
|
166
172
|
"y",
|
|
@@ -170,7 +176,9 @@ const tagSpecificPresentationalAttributes = {
|
|
|
170
176
|
"refY",
|
|
171
177
|
...presentationalAttributes
|
|
172
178
|
]),
|
|
179
|
+
// Marker
|
|
173
180
|
marker: /* @__PURE__ */ new Set([...presentationalAttributes]),
|
|
181
|
+
// Gradients
|
|
174
182
|
linearGradient: /* @__PURE__ */ new Set([
|
|
175
183
|
"x1",
|
|
176
184
|
"x2",
|
|
@@ -188,6 +196,7 @@ const tagSpecificPresentationalAttributes = {
|
|
|
188
196
|
...presentationalAttributes
|
|
189
197
|
]),
|
|
190
198
|
stop: /* @__PURE__ */ new Set(["offset", "stop-color", "stop-opacity"]),
|
|
199
|
+
// Filters
|
|
191
200
|
feFlood: /* @__PURE__ */ new Set(["flood-color", "flood-opacity"]),
|
|
192
201
|
feDropShadow: /* @__PURE__ */ new Set(["flood-color", "flood-opacity"])
|
|
193
202
|
};
|
|
@@ -205,10 +214,13 @@ svg_data_tags.filterChildTags.forEach((tag) => {
|
|
|
205
214
|
]);
|
|
206
215
|
});
|
|
207
216
|
const tagSpecificNonPresentationalAttributes = {
|
|
217
|
+
// SVG
|
|
208
218
|
svg: /* @__PURE__ */ new Set(["xmlns", "viewBox", "preserveAspectRatio"]),
|
|
219
|
+
// Defnitions, containers and masks
|
|
209
220
|
clipPath: /* @__PURE__ */ new Set(["clipPathUnits"]),
|
|
210
221
|
mask: /* @__PURE__ */ new Set(["maskContentUnits", "maskUnits"]),
|
|
211
222
|
symbol: /* @__PURE__ */ new Set(["viewBox", "preserveAspectRatio"]),
|
|
223
|
+
// Shapes
|
|
212
224
|
circle: /* @__PURE__ */ new Set([...otherShapeAttributes]),
|
|
213
225
|
ellipse: /* @__PURE__ */ new Set([...otherShapeAttributes]),
|
|
214
226
|
line: /* @__PURE__ */ new Set([...otherShapeAttributes]),
|
|
@@ -216,7 +228,9 @@ const tagSpecificNonPresentationalAttributes = {
|
|
|
216
228
|
polygon: /* @__PURE__ */ new Set([...otherShapeAttributes]),
|
|
217
229
|
polyline: /* @__PURE__ */ new Set([...otherShapeAttributes]),
|
|
218
230
|
rect: /* @__PURE__ */ new Set([...otherShapeAttributes]),
|
|
231
|
+
// Use
|
|
219
232
|
use: /* @__PURE__ */ new Set(["href"]),
|
|
233
|
+
// Marker
|
|
220
234
|
marker: /* @__PURE__ */ new Set([
|
|
221
235
|
"markerHeight",
|
|
222
236
|
"markerUnits",
|
|
@@ -227,6 +241,7 @@ const tagSpecificNonPresentationalAttributes = {
|
|
|
227
241
|
"refY",
|
|
228
242
|
"viewBox"
|
|
229
243
|
]),
|
|
244
|
+
// Animations
|
|
230
245
|
animate: /* @__PURE__ */ new Set([
|
|
231
246
|
...animationTimingAttributes,
|
|
232
247
|
...animationValueAttributes,
|
|
@@ -256,8 +271,10 @@ const tagSpecificNonPresentationalAttributes = {
|
|
|
256
271
|
...otherAnimationAttributes
|
|
257
272
|
]),
|
|
258
273
|
mpath: /* @__PURE__ */ new Set(["href"]),
|
|
274
|
+
// Gradients
|
|
259
275
|
linearGradient: /* @__PURE__ */ new Set([...commonGradientAttributes]),
|
|
260
276
|
radialGradient: /* @__PURE__ */ new Set([...commonGradientAttributes]),
|
|
277
|
+
// Filters
|
|
261
278
|
feSpotLight: /* @__PURE__ */ new Set([
|
|
262
279
|
"x",
|
|
263
280
|
"y",
|
|
@@ -27,6 +27,7 @@ const badSoftwareAttributes = /* @__PURE__ */ new Set([
|
|
|
27
27
|
"overflow",
|
|
28
28
|
"marker",
|
|
29
29
|
"white-space",
|
|
30
|
+
// Font stuff
|
|
30
31
|
"direction"
|
|
31
32
|
]);
|
|
32
33
|
const badAttributePrefixes = /* @__PURE__ */ new Set([
|
|
@@ -35,6 +36,7 @@ const badAttributePrefixes = /* @__PURE__ */ new Set([
|
|
|
35
36
|
"block",
|
|
36
37
|
"data",
|
|
37
38
|
"aria",
|
|
39
|
+
// Font stuff
|
|
38
40
|
"text",
|
|
39
41
|
"font",
|
|
40
42
|
"letter",
|
|
@@ -42,6 +44,7 @@ const badAttributePrefixes = /* @__PURE__ */ new Set([
|
|
|
42
44
|
"word",
|
|
43
45
|
"line",
|
|
44
46
|
"writing",
|
|
47
|
+
// Prefix for browser specific stuff
|
|
45
48
|
""
|
|
46
49
|
]);
|
|
47
50
|
const commonAttributes = /* @__PURE__ */ new Set(["id"]);
|
|
@@ -153,12 +156,15 @@ const tagSpecificAnimatedAttributes = {
|
|
|
153
156
|
rect: /* @__PURE__ */ new Set(["x", "y", "width", "height", "rx", "ry"])
|
|
154
157
|
};
|
|
155
158
|
const tagSpecificPresentationalAttributes = {
|
|
159
|
+
// SVG
|
|
156
160
|
svg: /* @__PURE__ */ new Set(["width", "height", ...presentationalAttributes]),
|
|
161
|
+
// Defnitions, containers and masks
|
|
157
162
|
clipPath: /* @__PURE__ */ new Set([...presentationalAttributes]),
|
|
158
163
|
defs: /* @__PURE__ */ new Set([]),
|
|
159
164
|
g: /* @__PURE__ */ new Set([...presentationalAttributes]),
|
|
160
165
|
mask: /* @__PURE__ */ new Set(["x", "y", "width", "height", ...presentationalAttributes]),
|
|
161
166
|
symbol: /* @__PURE__ */ new Set(["x", "y", "width", "height", ...presentationalAttributes]),
|
|
167
|
+
// Use
|
|
162
168
|
use: /* @__PURE__ */ new Set([
|
|
163
169
|
"x",
|
|
164
170
|
"y",
|
|
@@ -168,7 +174,9 @@ const tagSpecificPresentationalAttributes = {
|
|
|
168
174
|
"refY",
|
|
169
175
|
...presentationalAttributes
|
|
170
176
|
]),
|
|
177
|
+
// Marker
|
|
171
178
|
marker: /* @__PURE__ */ new Set([...presentationalAttributes]),
|
|
179
|
+
// Gradients
|
|
172
180
|
linearGradient: /* @__PURE__ */ new Set([
|
|
173
181
|
"x1",
|
|
174
182
|
"x2",
|
|
@@ -186,6 +194,7 @@ const tagSpecificPresentationalAttributes = {
|
|
|
186
194
|
...presentationalAttributes
|
|
187
195
|
]),
|
|
188
196
|
stop: /* @__PURE__ */ new Set(["offset", "stop-color", "stop-opacity"]),
|
|
197
|
+
// Filters
|
|
189
198
|
feFlood: /* @__PURE__ */ new Set(["flood-color", "flood-opacity"]),
|
|
190
199
|
feDropShadow: /* @__PURE__ */ new Set(["flood-color", "flood-opacity"])
|
|
191
200
|
};
|
|
@@ -203,10 +212,13 @@ filterChildTags.forEach((tag) => {
|
|
|
203
212
|
]);
|
|
204
213
|
});
|
|
205
214
|
const tagSpecificNonPresentationalAttributes = {
|
|
215
|
+
// SVG
|
|
206
216
|
svg: /* @__PURE__ */ new Set(["xmlns", "viewBox", "preserveAspectRatio"]),
|
|
217
|
+
// Defnitions, containers and masks
|
|
207
218
|
clipPath: /* @__PURE__ */ new Set(["clipPathUnits"]),
|
|
208
219
|
mask: /* @__PURE__ */ new Set(["maskContentUnits", "maskUnits"]),
|
|
209
220
|
symbol: /* @__PURE__ */ new Set(["viewBox", "preserveAspectRatio"]),
|
|
221
|
+
// Shapes
|
|
210
222
|
circle: /* @__PURE__ */ new Set([...otherShapeAttributes]),
|
|
211
223
|
ellipse: /* @__PURE__ */ new Set([...otherShapeAttributes]),
|
|
212
224
|
line: /* @__PURE__ */ new Set([...otherShapeAttributes]),
|
|
@@ -214,7 +226,9 @@ const tagSpecificNonPresentationalAttributes = {
|
|
|
214
226
|
polygon: /* @__PURE__ */ new Set([...otherShapeAttributes]),
|
|
215
227
|
polyline: /* @__PURE__ */ new Set([...otherShapeAttributes]),
|
|
216
228
|
rect: /* @__PURE__ */ new Set([...otherShapeAttributes]),
|
|
229
|
+
// Use
|
|
217
230
|
use: /* @__PURE__ */ new Set(["href"]),
|
|
231
|
+
// Marker
|
|
218
232
|
marker: /* @__PURE__ */ new Set([
|
|
219
233
|
"markerHeight",
|
|
220
234
|
"markerUnits",
|
|
@@ -225,6 +239,7 @@ const tagSpecificNonPresentationalAttributes = {
|
|
|
225
239
|
"refY",
|
|
226
240
|
"viewBox"
|
|
227
241
|
]),
|
|
242
|
+
// Animations
|
|
228
243
|
animate: /* @__PURE__ */ new Set([
|
|
229
244
|
...animationTimingAttributes,
|
|
230
245
|
...animationValueAttributes,
|
|
@@ -254,8 +269,10 @@ const tagSpecificNonPresentationalAttributes = {
|
|
|
254
269
|
...otherAnimationAttributes
|
|
255
270
|
]),
|
|
256
271
|
mpath: /* @__PURE__ */ new Set(["href"]),
|
|
272
|
+
// Gradients
|
|
257
273
|
linearGradient: /* @__PURE__ */ new Set([...commonGradientAttributes]),
|
|
258
274
|
radialGradient: /* @__PURE__ */ new Set([...commonGradientAttributes]),
|
|
275
|
+
// Filters
|
|
259
276
|
feSpotLight: /* @__PURE__ */ new Set([
|
|
260
277
|
"x",
|
|
261
278
|
"y",
|
package/lib/svg/data/tags.cjs
CHANGED
|
@@ -1,23 +1,29 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const badTags = /* @__PURE__ */ new Set([
|
|
4
|
+
// Nasty stuff or external resource
|
|
4
5
|
"foreignObject",
|
|
5
6
|
"script",
|
|
6
7
|
"image",
|
|
7
8
|
"feImage",
|
|
9
|
+
// Deprecated
|
|
8
10
|
"animateColor",
|
|
9
11
|
"altGlyph",
|
|
12
|
+
// Text
|
|
10
13
|
"text",
|
|
11
14
|
"tspan",
|
|
12
15
|
"switch",
|
|
13
16
|
"textPath",
|
|
17
|
+
// Font
|
|
14
18
|
"font",
|
|
15
19
|
"font-face",
|
|
16
20
|
"glyph",
|
|
17
21
|
"missing-glyph",
|
|
18
22
|
"hkern",
|
|
19
23
|
"vhern",
|
|
24
|
+
// View
|
|
20
25
|
"view",
|
|
26
|
+
// Link
|
|
21
27
|
"a"
|
|
22
28
|
]);
|
|
23
29
|
const unsupportedTags = /* @__PURE__ */ new Set(["metadata", "desc", "title"]);
|
package/lib/svg/data/tags.mjs
CHANGED
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
const badTags = /* @__PURE__ */ new Set([
|
|
2
|
+
// Nasty stuff or external resource
|
|
2
3
|
"foreignObject",
|
|
3
4
|
"script",
|
|
4
5
|
"image",
|
|
5
6
|
"feImage",
|
|
7
|
+
// Deprecated
|
|
6
8
|
"animateColor",
|
|
7
9
|
"altGlyph",
|
|
10
|
+
// Text
|
|
8
11
|
"text",
|
|
9
12
|
"tspan",
|
|
10
13
|
"switch",
|
|
11
14
|
"textPath",
|
|
15
|
+
// Font
|
|
12
16
|
"font",
|
|
13
17
|
"font-face",
|
|
14
18
|
"glyph",
|
|
15
19
|
"missing-glyph",
|
|
16
20
|
"hkern",
|
|
17
21
|
"vhern",
|
|
22
|
+
// View
|
|
18
23
|
"view",
|
|
24
|
+
// Link
|
|
19
25
|
"a"
|
|
20
26
|
]);
|
|
21
27
|
const unsupportedTags = /* @__PURE__ */ new Set(["metadata", "desc", "title"]);
|
package/lib/svg/index.cjs
CHANGED
|
@@ -4,9 +4,15 @@ const cheerio = require('cheerio');
|
|
|
4
4
|
const utils = require('@iconify/utils');
|
|
5
5
|
|
|
6
6
|
class SVG {
|
|
7
|
+
/**
|
|
8
|
+
* Constructor
|
|
9
|
+
*/
|
|
7
10
|
constructor(content) {
|
|
8
11
|
this.load(content);
|
|
9
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Get SVG as string
|
|
15
|
+
*/
|
|
10
16
|
toString(customisations) {
|
|
11
17
|
if (customisations) {
|
|
12
18
|
const data = utils.iconToSVG(this.getIcon(), customisations);
|
|
@@ -36,9 +42,15 @@ class SVG {
|
|
|
36
42
|
}
|
|
37
43
|
return this.$svg.html();
|
|
38
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Get SVG as string without whitespaces
|
|
47
|
+
*/
|
|
39
48
|
toMinifiedString(customisations) {
|
|
40
49
|
return utils.trimSVG(this.toString(customisations));
|
|
41
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Get body
|
|
53
|
+
*/
|
|
42
54
|
getBody() {
|
|
43
55
|
const $root = this.$svg(":root");
|
|
44
56
|
const attribs = $root.get(0).attribs;
|
|
@@ -54,6 +66,9 @@ class SVG {
|
|
|
54
66
|
}
|
|
55
67
|
return utils.trimSVG(this.$svg("svg").html());
|
|
56
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Get icon as IconifyIcon
|
|
71
|
+
*/
|
|
57
72
|
getIcon() {
|
|
58
73
|
const props = this.viewBox;
|
|
59
74
|
const body = this.getBody();
|
|
@@ -62,6 +77,11 @@ class SVG {
|
|
|
62
77
|
body
|
|
63
78
|
};
|
|
64
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Load SVG
|
|
82
|
+
*
|
|
83
|
+
* @param {string} content
|
|
84
|
+
*/
|
|
65
85
|
load(content) {
|
|
66
86
|
function remove(str1, str2, append) {
|
|
67
87
|
let start = 0;
|
package/lib/svg/index.mjs
CHANGED
|
@@ -2,9 +2,15 @@ import cheerio from 'cheerio';
|
|
|
2
2
|
import { iconToSVG, trimSVG } from '@iconify/utils';
|
|
3
3
|
|
|
4
4
|
class SVG {
|
|
5
|
+
/**
|
|
6
|
+
* Constructor
|
|
7
|
+
*/
|
|
5
8
|
constructor(content) {
|
|
6
9
|
this.load(content);
|
|
7
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Get SVG as string
|
|
13
|
+
*/
|
|
8
14
|
toString(customisations) {
|
|
9
15
|
if (customisations) {
|
|
10
16
|
const data = iconToSVG(this.getIcon(), customisations);
|
|
@@ -34,9 +40,15 @@ class SVG {
|
|
|
34
40
|
}
|
|
35
41
|
return this.$svg.html();
|
|
36
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Get SVG as string without whitespaces
|
|
45
|
+
*/
|
|
37
46
|
toMinifiedString(customisations) {
|
|
38
47
|
return trimSVG(this.toString(customisations));
|
|
39
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Get body
|
|
51
|
+
*/
|
|
40
52
|
getBody() {
|
|
41
53
|
const $root = this.$svg(":root");
|
|
42
54
|
const attribs = $root.get(0).attribs;
|
|
@@ -52,6 +64,9 @@ class SVG {
|
|
|
52
64
|
}
|
|
53
65
|
return trimSVG(this.$svg("svg").html());
|
|
54
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Get icon as IconifyIcon
|
|
69
|
+
*/
|
|
55
70
|
getIcon() {
|
|
56
71
|
const props = this.viewBox;
|
|
57
72
|
const body = this.getBody();
|
|
@@ -60,6 +75,11 @@ class SVG {
|
|
|
60
75
|
body
|
|
61
76
|
};
|
|
62
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Load SVG
|
|
80
|
+
*
|
|
81
|
+
* @param {string} content
|
|
82
|
+
*/
|
|
63
83
|
load(content) {
|
|
64
84
|
function remove(str1, str2, append) {
|
|
65
85
|
let start = 0;
|
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": "2.2.
|
|
6
|
+
"version": "2.2.1",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"bugs": "https://github.com/iconify/tools/issues",
|
|
9
9
|
"homepage": "https://github.com/iconify/tools",
|
|
@@ -16,35 +16,35 @@
|
|
|
16
16
|
"types": "./lib/index.d.ts",
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@iconify/types": "^2.0.0",
|
|
19
|
-
"@iconify/utils": "^2.0.
|
|
19
|
+
"@iconify/utils": "^2.0.12",
|
|
20
20
|
"@types/cheerio": "^0.22.31",
|
|
21
21
|
"@types/node-fetch": "^2.6.2",
|
|
22
22
|
"@types/tar": "^6.1.3",
|
|
23
23
|
"cheerio": "^1.0.0-rc.12",
|
|
24
24
|
"extract-zip": "^2.0.1",
|
|
25
25
|
"local-pkg": "^0.4.2",
|
|
26
|
-
"node-fetch": "^2.6.
|
|
26
|
+
"node-fetch": "^2.6.8",
|
|
27
27
|
"pathe": "^1.0.0",
|
|
28
28
|
"svgo": "^3.0.2",
|
|
29
29
|
"tar": "^6.1.13"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@types/jest": "^29.2.
|
|
33
|
-
"@types/node": "^18.11.
|
|
34
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
35
|
-
"@typescript-eslint/parser": "^5.
|
|
32
|
+
"@types/jest": "^29.2.5",
|
|
33
|
+
"@types/node": "^18.11.18",
|
|
34
|
+
"@typescript-eslint/eslint-plugin": "^5.48.1",
|
|
35
|
+
"@typescript-eslint/parser": "^5.48.1",
|
|
36
36
|
"cross-env": "^7.0.3",
|
|
37
|
-
"eslint": "^8.
|
|
38
|
-
"eslint-config-prettier": "^8.
|
|
37
|
+
"eslint": "^8.32.0",
|
|
38
|
+
"eslint-config-prettier": "^8.6.0",
|
|
39
39
|
"eslint-plugin-jasmine": "^4.1.3",
|
|
40
40
|
"eslint-plugin-prettier": "^4.2.1",
|
|
41
41
|
"jasmine": "^4.5.0",
|
|
42
42
|
"jest": "^29.3.1",
|
|
43
|
-
"prettier": "^2.8.
|
|
43
|
+
"prettier": "^2.8.3",
|
|
44
44
|
"rimraf": "^3.0.2",
|
|
45
|
-
"ts-jest": "^29.0.
|
|
45
|
+
"ts-jest": "^29.0.5",
|
|
46
46
|
"typescript": "^4.9.4",
|
|
47
|
-
"unbuild": "^1.
|
|
47
|
+
"unbuild": "^1.1.1"
|
|
48
48
|
},
|
|
49
49
|
"exports": {
|
|
50
50
|
"./*": "./*",
|