@iconify/tools 1.3.17 → 2.0.0-dev.2
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/.editorconfig +13 -0
- package/.eslintignore +2 -0
- package/lib/colors/attribs.d.ts +16 -0
- package/lib/colors/attribs.js +26 -0
- package/lib/colors/attribs.mjs +28 -0
- package/lib/colors/parse.d.ts +37 -0
- package/lib/colors/parse.js +261 -0
- package/lib/colors/parse.mjs +212 -0
- package/lib/css/parse.d.ts +4 -0
- package/lib/css/parse.js +23 -0
- package/lib/css/parse.mjs +20 -0
- package/lib/css/parser/error.d.ts +11 -0
- package/lib/css/parser/error.js +27 -0
- package/lib/css/parser/error.mjs +23 -0
- package/lib/css/parser/export.d.ts +5 -0
- package/lib/css/parser/export.js +69 -0
- package/lib/css/parser/export.mjs +46 -0
- package/lib/css/parser/strings.d.ts +13 -0
- package/lib/css/parser/strings.js +93 -0
- package/lib/css/parser/strings.mjs +74 -0
- package/lib/css/parser/text.d.ts +17 -0
- package/lib/css/parser/text.js +174 -0
- package/lib/css/parser/text.mjs +133 -0
- package/lib/css/parser/tokens.d.ts +6 -0
- package/lib/css/parser/tokens.js +200 -0
- package/lib/css/parser/tokens.mjs +186 -0
- package/lib/css/parser/tree.d.ts +5 -0
- package/lib/css/parser/tree.js +44 -0
- package/lib/css/parser/tree.mjs +40 -0
- package/lib/css/parser/types.d.ts +51 -0
- package/lib/css/parser/types.js +2 -0
- package/lib/css/parser/types.mjs +0 -0
- package/lib/icon-set/index.d.ts +134 -0
- package/lib/icon-set/index.js +776 -0
- package/lib/icon-set/index.mjs +617 -0
- package/lib/icon-set/match.d.ts +6 -0
- package/lib/icon-set/match.js +66 -0
- package/lib/icon-set/match.mjs +55 -0
- package/lib/icon-set/merge.d.ts +5 -0
- package/lib/icon-set/merge.js +91 -0
- package/lib/icon-set/merge.mjs +75 -0
- package/lib/icon-set/props.d.ts +10 -0
- package/lib/icon-set/props.js +33 -0
- package/lib/icon-set/props.mjs +25 -0
- package/lib/icon-set/types.d.ts +68 -0
- package/lib/icon-set/types.js +2 -0
- package/lib/icon-set/types.mjs +0 -0
- package/lib/import/directory.d.ts +35 -0
- package/lib/import/directory.js +59 -0
- package/lib/import/directory.mjs +47 -0
- package/lib/misc/keyword.d.ts +4 -0
- package/lib/misc/keyword.js +31 -0
- package/lib/misc/keyword.mjs +17 -0
- package/lib/misc/scan.d.ts +24 -0
- package/lib/misc/scan.js +48 -0
- package/lib/misc/scan.mjs +43 -0
- package/lib/optimise/flags.d.ts +5 -0
- package/lib/optimise/flags.js +303 -0
- package/lib/optimise/flags.mjs +241 -0
- package/lib/optimise/scale.d.ts +5 -0
- package/lib/optimise/scale.js +42 -0
- package/lib/optimise/scale.mjs +22 -0
- package/lib/optimise/svgo.d.ts +27 -0
- package/lib/optimise/svgo.js +88 -0
- package/lib/optimise/svgo.mjs +75 -0
- package/lib/svg/cleanup/attribs.d.ts +5 -0
- package/lib/svg/cleanup/attribs.js +43 -0
- package/lib/svg/cleanup/attribs.mjs +36 -0
- package/lib/svg/cleanup/bad-tags.d.ts +5 -0
- package/lib/svg/cleanup/bad-tags.js +69 -0
- package/lib/svg/cleanup/bad-tags.mjs +68 -0
- package/lib/svg/cleanup/inline-style.d.ts +5 -0
- package/lib/svg/cleanup/inline-style.js +77 -0
- package/lib/svg/cleanup/inline-style.mjs +65 -0
- package/lib/svg/cleanup/root-svg.d.ts +5 -0
- package/lib/svg/cleanup/root-svg.js +106 -0
- package/lib/svg/cleanup/root-svg.mjs +88 -0
- package/lib/svg/cleanup/svgo-style.d.ts +5 -0
- package/lib/svg/cleanup/svgo-style.js +35 -0
- package/lib/svg/cleanup/svgo-style.mjs +29 -0
- package/lib/svg/cleanup.d.ts +5 -0
- package/lib/svg/cleanup.js +24 -0
- package/lib/svg/cleanup.mjs +16 -0
- package/lib/svg/data/attributes.d.ts +71 -0
- package/lib/svg/data/attributes.js +403 -0
- package/lib/svg/data/attributes.mjs +352 -0
- package/lib/svg/data/tags.d.ts +89 -0
- package/lib/svg/data/tags.js +185 -0
- package/lib/svg/data/tags.mjs +136 -0
- package/lib/svg/index.d.ts +33 -0
- package/lib/svg/index.js +122 -0
- package/lib/svg/index.mjs +85 -0
- package/lib/svg/parse-style.d.ts +40 -0
- package/lib/svg/parse-style.js +131 -0
- package/lib/svg/parse-style.mjs +109 -0
- package/lib/svg/parse.d.ts +30 -0
- package/lib/svg/parse.js +49 -0
- package/lib/svg/parse.mjs +40 -0
- package/package.json +167 -13
- package/README.md +0 -576
- package/license.txt +0 -21
- package/sample/parse.js +0 -74
- package/sample/source/icon-close.svg +0 -15
- package/sample/source/icon-confirm.svg +0 -14
- package/sample/source/icon-search.svg +0 -16
- package/src/collection.js +0 -641
- package/src/colors/change_palette.js +0 -227
- package/src/colors/get_palette.js +0 -143
- package/src/colors/opacify.js +0 -195
- package/src/export/component.js +0 -482
- package/src/export/dir.js +0 -109
- package/src/export/json.js +0 -329
- package/src/export/phantomjs.js +0 -76
- package/src/export/phantomjs_script.js +0 -125
- package/src/export/png.js +0 -193
- package/src/export/svg.js +0 -55
- package/src/export/templates/component.md +0 -79
- package/src/export/templates/info.md +0 -3
- package/src/export/templates/sample-react-1.md +0 -21
- package/src/export/templates/sample-react-2.md +0 -15
- package/src/export/templates/sample-react.md +0 -11
- package/src/export/templates/sample-svelte.md +0 -11
- package/src/export/templates/sample-svelte1.md +0 -22
- package/src/export/templates/sample-svelte2.md +0 -13
- package/src/export/templates/sample-vue-0.md +0 -30
- package/src/export/templates/sample-vue-1.md +0 -25
- package/src/export/templates/sample-vue-2.md +0 -27
- package/src/export/templates/sample-vue.md +0 -28
- package/src/helpers.js +0 -43
- package/src/import/dir.js +0 -234
- package/src/import/font.js +0 -402
- package/src/import/json.js +0 -200
- package/src/import/svg.js +0 -60
- package/src/import/web_icons.js +0 -248
- package/src/modules.js +0 -50
- package/src/optimize/crop.js +0 -554
- package/src/optimize/crop_script.js +0 -525
- package/src/optimize/flags.js +0 -430
- package/src/optimize/scale.js +0 -72
- package/src/optimize/svgo.js +0 -161
- package/src/optimize/tags.js +0 -522
- package/src/shapes/convert.js +0 -264
- package/src/shapes/index.js +0 -135
- package/src/shapes/length.js +0 -707
- package/src/shapes/length_script.js +0 -105
- package/src/shapes/options.js +0 -60
- package/src/svg.js +0 -162
|
@@ -0,0 +1,617 @@
|
|
|
1
|
+
// src/icon-set/index.ts
|
|
2
|
+
import { fullIcon } from "@iconify/utils/lib/icon";
|
|
3
|
+
import { iconToSVG } from "@iconify/utils/lib/svg/build";
|
|
4
|
+
import {
|
|
5
|
+
defaults
|
|
6
|
+
} from "@iconify/utils/lib/customisations";
|
|
7
|
+
import { minifyIconSet } from "@iconify/utils/lib/icon-set/minify";
|
|
8
|
+
import { convertIconSetInfo } from "@iconify/utils/lib/icon-set/convert-info";
|
|
9
|
+
import { extraDefaultProps, filterProps } from "./props.mjs";
|
|
10
|
+
import { SVG } from "../svg/index.mjs";
|
|
11
|
+
function assertNever(v) {
|
|
12
|
+
}
|
|
13
|
+
var maxIteration = 6;
|
|
14
|
+
var themeKeys = ["prefixes", "suffixes"];
|
|
15
|
+
function sortThemeKeys(keys) {
|
|
16
|
+
return keys.sort((a, b) => a.length === b.length ? a.localeCompare(b) : b.length - a.length);
|
|
17
|
+
}
|
|
18
|
+
var IconSet = class {
|
|
19
|
+
constructor(data) {
|
|
20
|
+
this.load(data);
|
|
21
|
+
}
|
|
22
|
+
load(data) {
|
|
23
|
+
this.prefix = data.prefix;
|
|
24
|
+
const defaultProps = filterProps(data);
|
|
25
|
+
this.entries = Object.create(null);
|
|
26
|
+
const entries = this.entries;
|
|
27
|
+
for (const name in data.icons) {
|
|
28
|
+
const item = data.icons[name];
|
|
29
|
+
const entry = {
|
|
30
|
+
type: "icon",
|
|
31
|
+
body: item.body,
|
|
32
|
+
props: { ...defaultProps, ...filterProps(item) },
|
|
33
|
+
chars: new Set(),
|
|
34
|
+
categories: new Set()
|
|
35
|
+
};
|
|
36
|
+
entries[name] = entry;
|
|
37
|
+
}
|
|
38
|
+
if (data.aliases) {
|
|
39
|
+
for (const name in data.aliases) {
|
|
40
|
+
const item = data.aliases[name];
|
|
41
|
+
const parent = item.parent;
|
|
42
|
+
const props = filterProps(item);
|
|
43
|
+
if (Object.keys(props).length) {
|
|
44
|
+
const entry = {
|
|
45
|
+
type: "variation",
|
|
46
|
+
parent,
|
|
47
|
+
props,
|
|
48
|
+
chars: new Set(),
|
|
49
|
+
categories: new Set()
|
|
50
|
+
};
|
|
51
|
+
entries[name] = entry;
|
|
52
|
+
} else {
|
|
53
|
+
const entry = {
|
|
54
|
+
type: "alias",
|
|
55
|
+
parent
|
|
56
|
+
};
|
|
57
|
+
entries[name] = entry;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const info = data.info && convertIconSetInfo(data.info);
|
|
62
|
+
this.info = info || void 0;
|
|
63
|
+
if (data.chars) {
|
|
64
|
+
for (const char in data.chars) {
|
|
65
|
+
const name = data.chars[char];
|
|
66
|
+
const icon = entries[name];
|
|
67
|
+
if (icon) {
|
|
68
|
+
switch (icon.type) {
|
|
69
|
+
case "icon":
|
|
70
|
+
case "variation":
|
|
71
|
+
icon.chars.add(char);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
this.categories = new Set();
|
|
77
|
+
if (data.categories) {
|
|
78
|
+
for (const category in data.categories) {
|
|
79
|
+
const item = {
|
|
80
|
+
title: category,
|
|
81
|
+
count: 0
|
|
82
|
+
};
|
|
83
|
+
data.categories[category].forEach((iconName) => {
|
|
84
|
+
const icon = entries[iconName];
|
|
85
|
+
switch (icon == null ? void 0 : icon.type) {
|
|
86
|
+
case "icon":
|
|
87
|
+
case "variation":
|
|
88
|
+
icon.categories.add(item);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
this.categories.add(item);
|
|
92
|
+
this.listCategory(item);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const prefixes = this.prefixes = Object.create(null);
|
|
96
|
+
const suffixes = this.suffixes = Object.create(null);
|
|
97
|
+
if (data.themes) {
|
|
98
|
+
for (const key in data.themes) {
|
|
99
|
+
const item = data.themes[key];
|
|
100
|
+
if (typeof item.prefix === "string") {
|
|
101
|
+
const prefix = item.prefix;
|
|
102
|
+
if (prefix.slice(-1) === "-") {
|
|
103
|
+
prefixes[prefix.slice(0, prefix.length - 1)] = item.title;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (typeof item.suffix === "string") {
|
|
107
|
+
const suffix = item.suffix;
|
|
108
|
+
if (suffix.slice(0, 1) === "-") {
|
|
109
|
+
suffixes[suffix.slice(1)] = item.title;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
themeKeys.forEach((prop) => {
|
|
115
|
+
const items = data[prop];
|
|
116
|
+
if (items) {
|
|
117
|
+
this[prop] = Object.create(null);
|
|
118
|
+
for (const key in items) {
|
|
119
|
+
this[prop][key] = items[key];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
list(types = ["icon", "variation"]) {
|
|
125
|
+
return Object.keys(this.entries).filter((name) => {
|
|
126
|
+
const type = this.entries[name].type;
|
|
127
|
+
return types.indexOf(type) !== -1;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
async forEach(callback, types = ["icon", "variation", "alias"]) {
|
|
131
|
+
const names = this.list(types);
|
|
132
|
+
for (let i = 0; i < names.length; i++) {
|
|
133
|
+
const name = names[i];
|
|
134
|
+
const item = this.entries[name];
|
|
135
|
+
if (item) {
|
|
136
|
+
let result = callback(name, item.type);
|
|
137
|
+
if (result instanceof Promise) {
|
|
138
|
+
result = await result;
|
|
139
|
+
}
|
|
140
|
+
if (result === false) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
resolve(name, full = false) {
|
|
147
|
+
const entries = this.entries;
|
|
148
|
+
function getIcon(name2, iteration) {
|
|
149
|
+
if (entries[name2] === void 0 || iteration > maxIteration) {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
const item = entries[name2];
|
|
153
|
+
switch (item.type) {
|
|
154
|
+
case "icon": {
|
|
155
|
+
const result2 = {
|
|
156
|
+
body: item.body,
|
|
157
|
+
...item.props
|
|
158
|
+
};
|
|
159
|
+
return result2;
|
|
160
|
+
}
|
|
161
|
+
case "alias":
|
|
162
|
+
return getIcon(item.parent, iteration + 1);
|
|
163
|
+
case "variation": {
|
|
164
|
+
const parent = getIcon(item.parent, iteration + 1);
|
|
165
|
+
if (!parent) {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
for (const key in item.props) {
|
|
169
|
+
const attr = key;
|
|
170
|
+
const value = item.props[attr];
|
|
171
|
+
if (value) {
|
|
172
|
+
if (parent[attr] === void 0) {
|
|
173
|
+
parent[attr] = value;
|
|
174
|
+
} else {
|
|
175
|
+
switch (attr) {
|
|
176
|
+
case "rotate":
|
|
177
|
+
parent[attr] = (parent[attr] + value) % 4;
|
|
178
|
+
break;
|
|
179
|
+
case "hFlip":
|
|
180
|
+
case "vFlip":
|
|
181
|
+
parent[attr] = !parent[attr];
|
|
182
|
+
break;
|
|
183
|
+
default:
|
|
184
|
+
parent[attr] = value;
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return parent;
|
|
191
|
+
}
|
|
192
|
+
default:
|
|
193
|
+
assertNever(item);
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const result = getIcon(name, 0);
|
|
198
|
+
return result && full ? fullIcon(result) : result;
|
|
199
|
+
}
|
|
200
|
+
toString(name, custommisations = {
|
|
201
|
+
width: "auto",
|
|
202
|
+
height: "auto"
|
|
203
|
+
}) {
|
|
204
|
+
const item = this.resolve(name, true);
|
|
205
|
+
if (!item) {
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
const result = iconToSVG(item, {
|
|
209
|
+
...defaults,
|
|
210
|
+
...custommisations
|
|
211
|
+
});
|
|
212
|
+
const attributes = Object.keys(result.attributes).map((key) => ` ${key}="${result.attributes[key]}"`).join("");
|
|
213
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"${attributes}>${result.body}</svg>`;
|
|
214
|
+
}
|
|
215
|
+
toSVG(name) {
|
|
216
|
+
const html = this.toString(name);
|
|
217
|
+
return html ? new SVG(html) : null;
|
|
218
|
+
}
|
|
219
|
+
export(validate = true) {
|
|
220
|
+
const icons = Object.create(null);
|
|
221
|
+
const aliases = Object.create(null);
|
|
222
|
+
const names = Object.keys(this.entries);
|
|
223
|
+
names.sort((a, b) => a.localeCompare(b));
|
|
224
|
+
names.forEach((name) => {
|
|
225
|
+
const item = this.entries[name];
|
|
226
|
+
switch (item.type) {
|
|
227
|
+
case "icon": {
|
|
228
|
+
const icon = {
|
|
229
|
+
body: item.body,
|
|
230
|
+
...item.props
|
|
231
|
+
};
|
|
232
|
+
icons[name] = icon;
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
case "alias":
|
|
236
|
+
case "variation": {
|
|
237
|
+
if (validate && !this.resolve(name)) {
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
const props = item.type === "variation" ? item.props : {};
|
|
241
|
+
const alias = {
|
|
242
|
+
parent: item.parent,
|
|
243
|
+
...props
|
|
244
|
+
};
|
|
245
|
+
aliases[name] = alias;
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
default: {
|
|
249
|
+
assertNever(item);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
let info;
|
|
254
|
+
if (this.info) {
|
|
255
|
+
this.info.total = this.count();
|
|
256
|
+
info = JSON.parse(JSON.stringify(this.info));
|
|
257
|
+
}
|
|
258
|
+
const result = {
|
|
259
|
+
prefix: this.prefix
|
|
260
|
+
};
|
|
261
|
+
if (info) {
|
|
262
|
+
result.info = info;
|
|
263
|
+
}
|
|
264
|
+
result.icons = icons;
|
|
265
|
+
if (Object.keys(aliases).length) {
|
|
266
|
+
result.aliases = aliases;
|
|
267
|
+
}
|
|
268
|
+
const chars = this.chars(Object.keys(icons).concat(Object.keys(aliases)));
|
|
269
|
+
if (Object.keys(chars).length) {
|
|
270
|
+
result.chars = chars;
|
|
271
|
+
}
|
|
272
|
+
const categories = Object.create(null);
|
|
273
|
+
Array.from(this.categories).sort((a, b) => a.title.localeCompare(b.title)).forEach((item) => {
|
|
274
|
+
const names2 = this.listCategory(item);
|
|
275
|
+
if (names2) {
|
|
276
|
+
categories[item.title] = names2;
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
if (Object.keys(categories).length) {
|
|
280
|
+
result.categories = categories;
|
|
281
|
+
}
|
|
282
|
+
themeKeys.forEach((prop) => {
|
|
283
|
+
const items = this[prop];
|
|
284
|
+
const keys = Object.keys(items);
|
|
285
|
+
if (keys.length) {
|
|
286
|
+
sortThemeKeys(keys);
|
|
287
|
+
const sortedTheme = Object.create(null);
|
|
288
|
+
const tested = this.checkTheme(prop === "prefixes");
|
|
289
|
+
keys.forEach((key) => {
|
|
290
|
+
if (tested.valid[key].length) {
|
|
291
|
+
sortedTheme[key] = items[key];
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
if (Object.keys(sortedTheme).length) {
|
|
295
|
+
result[prop] = sortedTheme;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
minifyIconSet(result);
|
|
300
|
+
return result;
|
|
301
|
+
}
|
|
302
|
+
chars(names) {
|
|
303
|
+
const chars = Object.create(null);
|
|
304
|
+
if (!names) {
|
|
305
|
+
names = Object.keys(this.entries);
|
|
306
|
+
}
|
|
307
|
+
for (let i = 0; i < names.length; i++) {
|
|
308
|
+
const name = names[i];
|
|
309
|
+
const item = this.entries[name];
|
|
310
|
+
switch (item.type) {
|
|
311
|
+
case "icon":
|
|
312
|
+
case "variation":
|
|
313
|
+
item.chars.forEach((char) => {
|
|
314
|
+
chars[char] = name;
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return chars;
|
|
319
|
+
}
|
|
320
|
+
_filter(callback) {
|
|
321
|
+
const names = [];
|
|
322
|
+
for (const key in this.entries) {
|
|
323
|
+
const item = this.entries[key];
|
|
324
|
+
switch (item.type) {
|
|
325
|
+
case "icon": {
|
|
326
|
+
if (callback(key, item)) {
|
|
327
|
+
names.push(key);
|
|
328
|
+
}
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
case "variation":
|
|
332
|
+
case "alias": {
|
|
333
|
+
const icon = this.resolve(key);
|
|
334
|
+
if (icon && callback(key, item, icon)) {
|
|
335
|
+
names.push(key);
|
|
336
|
+
}
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return names;
|
|
342
|
+
}
|
|
343
|
+
count() {
|
|
344
|
+
return this._filter((key, item, icon) => {
|
|
345
|
+
if (item.type === "alias" || item.props.hidden || (icon == null ? void 0 : icon.hidden)) {
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
return true;
|
|
349
|
+
}).length;
|
|
350
|
+
}
|
|
351
|
+
_findCategory(title, add) {
|
|
352
|
+
const categoryItem = Array.from(this.categories).find((item) => item.title === title);
|
|
353
|
+
if (categoryItem) {
|
|
354
|
+
return categoryItem;
|
|
355
|
+
}
|
|
356
|
+
if (add) {
|
|
357
|
+
const newItem = {
|
|
358
|
+
title,
|
|
359
|
+
count: 0
|
|
360
|
+
};
|
|
361
|
+
this.categories.add(newItem);
|
|
362
|
+
return newItem;
|
|
363
|
+
}
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
listCategory(category) {
|
|
367
|
+
const categoryItem = typeof category === "string" ? this._findCategory(category, false) : category;
|
|
368
|
+
if (!categoryItem) {
|
|
369
|
+
return null;
|
|
370
|
+
}
|
|
371
|
+
const icons = this._filter((key, item, icon) => {
|
|
372
|
+
if (item.type === "alias" || item.props.hidden || (icon == null ? void 0 : icon.hidden)) {
|
|
373
|
+
return false;
|
|
374
|
+
}
|
|
375
|
+
return item.categories.has(categoryItem);
|
|
376
|
+
});
|
|
377
|
+
const count = icons.length;
|
|
378
|
+
categoryItem.count = count;
|
|
379
|
+
if (!count) {
|
|
380
|
+
this.categories.delete(categoryItem);
|
|
381
|
+
return null;
|
|
382
|
+
}
|
|
383
|
+
return icons;
|
|
384
|
+
}
|
|
385
|
+
exists(name) {
|
|
386
|
+
return !!this.entries[name];
|
|
387
|
+
}
|
|
388
|
+
remove(name, removeDependencies = true) {
|
|
389
|
+
const entries = this.entries;
|
|
390
|
+
const names = new Set();
|
|
391
|
+
if (typeof removeDependencies === "string") {
|
|
392
|
+
if (name === removeDependencies || !entries[removeDependencies]) {
|
|
393
|
+
return 0;
|
|
394
|
+
}
|
|
395
|
+
names.add(removeDependencies);
|
|
396
|
+
}
|
|
397
|
+
function del(name2, iteration) {
|
|
398
|
+
if (entries[name2] === void 0 || iteration > maxIteration || names.has(name2)) {
|
|
399
|
+
return false;
|
|
400
|
+
}
|
|
401
|
+
names.add(name2);
|
|
402
|
+
if (removeDependencies === true || !iteration && typeof removeDependencies === "string") {
|
|
403
|
+
for (const key in entries) {
|
|
404
|
+
const item = entries[key];
|
|
405
|
+
switch (item.type) {
|
|
406
|
+
case "icon":
|
|
407
|
+
break;
|
|
408
|
+
case "alias":
|
|
409
|
+
case "variation":
|
|
410
|
+
if (item.parent === name2) {
|
|
411
|
+
if (removeDependencies === true) {
|
|
412
|
+
if (!del(key, iteration + 1)) {
|
|
413
|
+
return false;
|
|
414
|
+
}
|
|
415
|
+
break;
|
|
416
|
+
}
|
|
417
|
+
item.parent = removeDependencies;
|
|
418
|
+
}
|
|
419
|
+
break;
|
|
420
|
+
default:
|
|
421
|
+
assertNever(item);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return true;
|
|
426
|
+
}
|
|
427
|
+
if (del(name, 0)) {
|
|
428
|
+
if (typeof removeDependencies === "string") {
|
|
429
|
+
names.delete(removeDependencies);
|
|
430
|
+
}
|
|
431
|
+
names.forEach((name2) => {
|
|
432
|
+
delete entries[name2];
|
|
433
|
+
});
|
|
434
|
+
return names.size;
|
|
435
|
+
}
|
|
436
|
+
return 0;
|
|
437
|
+
}
|
|
438
|
+
rename(oldName, newName) {
|
|
439
|
+
const entries = this.entries;
|
|
440
|
+
if (entries[newName]) {
|
|
441
|
+
if (!this.remove(newName)) {
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
if (!entries[oldName]) {
|
|
446
|
+
return false;
|
|
447
|
+
}
|
|
448
|
+
entries[newName] = entries[oldName];
|
|
449
|
+
delete entries[oldName];
|
|
450
|
+
for (const key in entries) {
|
|
451
|
+
const item = entries[key];
|
|
452
|
+
switch (item.type) {
|
|
453
|
+
case "icon":
|
|
454
|
+
break;
|
|
455
|
+
case "alias":
|
|
456
|
+
case "variation":
|
|
457
|
+
if (item.parent === oldName) {
|
|
458
|
+
item.parent = newName;
|
|
459
|
+
}
|
|
460
|
+
break;
|
|
461
|
+
default:
|
|
462
|
+
assertNever(item);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
return true;
|
|
466
|
+
}
|
|
467
|
+
setItem(name, item) {
|
|
468
|
+
switch (item.type) {
|
|
469
|
+
case "alias":
|
|
470
|
+
case "variation": {
|
|
471
|
+
if (!this.entries[item.parent]) {
|
|
472
|
+
return false;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
this.entries[name] = item;
|
|
477
|
+
return true;
|
|
478
|
+
}
|
|
479
|
+
setIcon(name, icon) {
|
|
480
|
+
return this.setItem(name, {
|
|
481
|
+
type: "icon",
|
|
482
|
+
body: icon.body,
|
|
483
|
+
props: filterProps(icon),
|
|
484
|
+
chars: new Set(),
|
|
485
|
+
categories: new Set()
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
setAlias(name, parent) {
|
|
489
|
+
return this.setItem(name, {
|
|
490
|
+
type: "alias",
|
|
491
|
+
parent
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
setVariation(name, parent, props) {
|
|
495
|
+
let categories;
|
|
496
|
+
while (!categories) {
|
|
497
|
+
const parentItem = this.entries[parent];
|
|
498
|
+
if (!parentItem) {
|
|
499
|
+
return false;
|
|
500
|
+
}
|
|
501
|
+
if (parentItem.type === "alias") {
|
|
502
|
+
parent = parentItem.parent;
|
|
503
|
+
} else {
|
|
504
|
+
categories = new Set(parentItem.categories);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
return this.setItem(name, {
|
|
508
|
+
type: "variation",
|
|
509
|
+
parent,
|
|
510
|
+
props,
|
|
511
|
+
chars: new Set(),
|
|
512
|
+
categories
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
fromSVG(name, svg) {
|
|
516
|
+
const props = svg.viewBox;
|
|
517
|
+
const body = svg.getBody();
|
|
518
|
+
const item = this.entries[name];
|
|
519
|
+
switch (item == null ? void 0 : item.type) {
|
|
520
|
+
case "icon":
|
|
521
|
+
case "variation": {
|
|
522
|
+
for (const key in extraDefaultProps) {
|
|
523
|
+
const prop = key;
|
|
524
|
+
if (item.props[prop]) {
|
|
525
|
+
props[prop] = item.props[prop];
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
return this.setItem(name, {
|
|
529
|
+
type: "icon",
|
|
530
|
+
body,
|
|
531
|
+
props,
|
|
532
|
+
chars: item.chars,
|
|
533
|
+
categories: item.categories
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
return this.setIcon(name, {
|
|
538
|
+
body,
|
|
539
|
+
...props
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
toggleCharacter(iconName, char, add) {
|
|
543
|
+
const item = this.entries[iconName];
|
|
544
|
+
if (!item) {
|
|
545
|
+
return false;
|
|
546
|
+
}
|
|
547
|
+
switch (item.type) {
|
|
548
|
+
case "icon":
|
|
549
|
+
case "variation":
|
|
550
|
+
if (item.chars.has(char) !== add) {
|
|
551
|
+
item.chars[add ? "add" : "delete"](char);
|
|
552
|
+
return true;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
return false;
|
|
556
|
+
}
|
|
557
|
+
toggleCategory(iconName, category, add) {
|
|
558
|
+
const item = this.entries[iconName];
|
|
559
|
+
const categoryItem = this._findCategory(category, add);
|
|
560
|
+
if (!item || !categoryItem) {
|
|
561
|
+
return false;
|
|
562
|
+
}
|
|
563
|
+
switch (item.type) {
|
|
564
|
+
case "icon":
|
|
565
|
+
case "variation":
|
|
566
|
+
if (item.categories.has(categoryItem) !== add) {
|
|
567
|
+
categoryItem.count += add ? 1 : -1;
|
|
568
|
+
item.categories[add ? "add" : "delete"](categoryItem);
|
|
569
|
+
return true;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
return false;
|
|
573
|
+
}
|
|
574
|
+
checkTheme(prefix) {
|
|
575
|
+
const themes = prefix ? this.prefixes : this.suffixes;
|
|
576
|
+
const keys = sortThemeKeys(Object.keys(themes));
|
|
577
|
+
const results = {
|
|
578
|
+
valid: Object.create(null),
|
|
579
|
+
invalid: []
|
|
580
|
+
};
|
|
581
|
+
keys.forEach((key) => {
|
|
582
|
+
results.valid[key] = [];
|
|
583
|
+
});
|
|
584
|
+
results.invalid = this._filter((name, item, icon) => {
|
|
585
|
+
if (item.type === "alias" || item.props.hidden || (icon == null ? void 0 : icon.hidden)) {
|
|
586
|
+
return false;
|
|
587
|
+
}
|
|
588
|
+
for (let i = 0; i < keys.length; i++) {
|
|
589
|
+
const search = keys[i];
|
|
590
|
+
if (search === "") {
|
|
591
|
+
results.valid[search].push(name);
|
|
592
|
+
return false;
|
|
593
|
+
}
|
|
594
|
+
const match = prefix ? search + "-" : "-" + search;
|
|
595
|
+
const length = match.length;
|
|
596
|
+
const test = prefix ? name.slice(0, length) : name.slice(0 - length);
|
|
597
|
+
if (test === match) {
|
|
598
|
+
results.valid[search].push(name);
|
|
599
|
+
return false;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
return true;
|
|
603
|
+
});
|
|
604
|
+
return results;
|
|
605
|
+
}
|
|
606
|
+
};
|
|
607
|
+
function blankIconSet(prefix) {
|
|
608
|
+
return new IconSet({
|
|
609
|
+
prefix,
|
|
610
|
+
icons: {}
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
export {
|
|
614
|
+
IconSet,
|
|
615
|
+
blankIconSet,
|
|
616
|
+
sortThemeKeys
|
|
617
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findMatchingIcon = void 0;
|
|
4
|
+
const icon_1 = require("@iconify/utils/lib/icon");
|
|
5
|
+
// Maximum depth for looking for parent icons
|
|
6
|
+
const maxIteration = 5;
|
|
7
|
+
/**
|
|
8
|
+
* Find matching icon in icon set
|
|
9
|
+
*/
|
|
10
|
+
function findMatchingIcon(iconSet, icon) {
|
|
11
|
+
const body = icon.body;
|
|
12
|
+
let hiddenMatch = null;
|
|
13
|
+
function isMatching(data) {
|
|
14
|
+
for (const key in icon_1.iconDefaults) {
|
|
15
|
+
const attr = key;
|
|
16
|
+
if (data[attr] !== icon[attr]) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Check if icon matches
|
|
24
|
+
*/
|
|
25
|
+
function test(name, iteration) {
|
|
26
|
+
const data = iconSet.resolve(name, true);
|
|
27
|
+
if (!data) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
if (isMatching(data)) {
|
|
31
|
+
if (data.hidden) {
|
|
32
|
+
hiddenMatch = name;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return name;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (iteration > maxIteration) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
// Check aliases
|
|
42
|
+
for (const key in iconSet.entries) {
|
|
43
|
+
const item = iconSet.entries[key];
|
|
44
|
+
if (item.type === 'variation' && item.parent === name) {
|
|
45
|
+
const result = test(key, iteration + 1);
|
|
46
|
+
if (typeof result === 'string') {
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
// Find icons that match
|
|
54
|
+
for (const key in iconSet.entries) {
|
|
55
|
+
const item = iconSet.entries[key];
|
|
56
|
+
if (item.type === 'icon' && item.body === body) {
|
|
57
|
+
// Possible match
|
|
58
|
+
const result = test(key, 0);
|
|
59
|
+
if (typeof result === 'string') {
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return hiddenMatch;
|
|
65
|
+
}
|
|
66
|
+
exports.findMatchingIcon = findMatchingIcon;
|