@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
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<svg width="128px" height="128px" viewBox="0 0 128 128" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
3
|
-
<!-- Generator: Sketch 43.1 (39012) - http://www.bohemiancoding.com/sketch -->
|
|
4
|
-
<title>icon-search</title>
|
|
5
|
-
<desc>Created with Sketch.</desc>
|
|
6
|
-
<defs></defs>
|
|
7
|
-
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
|
8
|
-
<g id="16x16-(144)-fill" transform="translate(-8.000000, -8.000000)">
|
|
9
|
-
<g id="_slices" transform="translate(8.000000, 8.000000)"></g>
|
|
10
|
-
<g id="search" transform="translate(8.000000, 8.000000)" fill-rule="nonzero" fill="#000000">
|
|
11
|
-
<path d="M46.3431458,70.3431458 L2.34314575,114.343146 C-0.781048584,117.46734 -0.781048584,122.53266 2.34314575,125.656854 C5.46734008,128.781049 10.5326599,128.781049 13.6568542,125.656854 L57.6568542,81.6568542 C60.7810486,78.5326599 60.7810486,73.4673401 57.6568542,70.3431458 C54.5326599,67.2189514 49.4673401,67.2189514 46.3431458,70.3431458 Z" id="Line"></path>
|
|
12
|
-
<path d="M80,80 C97.7029463,80 112,65.6911262 112,48 C112,30.3075053 97.7052107,16 80,16 C62.2947893,16 48,30.3075053 48,48 C48,56.5320158 51.4831767,64.661849 57.5546468,70.6847074 C63.6033879,76.6850187 71.370606,80 80,80 Z M32,48 C32,21.4741325 53.455047,-9.41469125e-14 80,-2.27373675e-13 C106.544953,-3.60600438e-13 128,21.4741325 128,48 C128,74.5247236 106.542464,96 80,96 C67.0741988,96 55.281859,90.9671317 46.2865035,82.0437983 C37.2267639,73.0565963 32,60.857181 32,48 Z" id="Oval-2"></path>
|
|
13
|
-
</g>
|
|
14
|
-
</g>
|
|
15
|
-
</g>
|
|
16
|
-
</svg>
|
package/src/collection.js
DELETED
|
@@ -1,641 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the @iconify/tools package.
|
|
3
|
-
*
|
|
4
|
-
* (c) Vjacheslav Trushkin <cyberalien@gmail.com>
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
'use strict';
|
|
11
|
-
|
|
12
|
-
const crypto = require('crypto');
|
|
13
|
-
const SVG = require('./svg');
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Default values for merge() options
|
|
17
|
-
*
|
|
18
|
-
* @type {object}
|
|
19
|
-
*/
|
|
20
|
-
const defaultMergeOptions = {
|
|
21
|
-
// True if icons that exist in older collection, but missing in new collection should be marked as hidden
|
|
22
|
-
markAsHidden: true,
|
|
23
|
-
|
|
24
|
-
// True if missing icons should be copied. If false, missing icons will be added as aliases instead.
|
|
25
|
-
copyMissingIcons: false,
|
|
26
|
-
|
|
27
|
-
// True if aliases should be checked
|
|
28
|
-
checkAliases: true,
|
|
29
|
-
|
|
30
|
-
// True if characters should be checked
|
|
31
|
-
checkChars: true,
|
|
32
|
-
|
|
33
|
-
// True if categories should be checked
|
|
34
|
-
checkCategories: true,
|
|
35
|
-
|
|
36
|
-
// Function to hash SVG content to compare different icons
|
|
37
|
-
// viewBox and body are merged because order of attributes in toString() might be different for identical icons
|
|
38
|
-
hashCallback: (key, svg) =>
|
|
39
|
-
crypto
|
|
40
|
-
.createHash('md5')
|
|
41
|
-
.update(
|
|
42
|
-
'<viewBox="' +
|
|
43
|
-
svg.left +
|
|
44
|
-
' ' +
|
|
45
|
-
svg.top +
|
|
46
|
-
' ' +
|
|
47
|
-
svg.width +
|
|
48
|
-
' ' +
|
|
49
|
-
svg.height +
|
|
50
|
-
'"/>' +
|
|
51
|
-
svg.getBody()
|
|
52
|
-
)
|
|
53
|
-
.digest('hex'),
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Class for storing collection of SVG objects
|
|
58
|
-
*/
|
|
59
|
-
class Collection {
|
|
60
|
-
/**
|
|
61
|
-
* Constructor
|
|
62
|
-
*
|
|
63
|
-
* @param {string|Collection} [param] Items prefix or collection to clone
|
|
64
|
-
*/
|
|
65
|
-
constructor(param) {
|
|
66
|
-
this.items = Object.create(null);
|
|
67
|
-
this.prefix = typeof param === 'string' ? param : '';
|
|
68
|
-
|
|
69
|
-
if (param instanceof Collection) {
|
|
70
|
-
// Clone collection
|
|
71
|
-
param.forEach((item, key) => {
|
|
72
|
-
this.items[key] = item;
|
|
73
|
-
});
|
|
74
|
-
this.prefix = param.prefix;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Add item to collection
|
|
80
|
-
*
|
|
81
|
-
* @param {string} key Item name.
|
|
82
|
-
* If collection has prefix set, item name should not have prefix.
|
|
83
|
-
* @param {SVG} item
|
|
84
|
-
*/
|
|
85
|
-
add(key, item) {
|
|
86
|
-
if (item instanceof SVG) {
|
|
87
|
-
this.items[key] = item;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Remove item from collection
|
|
93
|
-
*
|
|
94
|
-
* @param {string} key Item name.
|
|
95
|
-
* If collection has prefix set, item name should not have prefix.
|
|
96
|
-
*/
|
|
97
|
-
remove(key) {
|
|
98
|
-
delete this.items[key];
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Change key
|
|
103
|
-
*
|
|
104
|
-
* @param {string} oldKey Old key.
|
|
105
|
-
* @param {string} newKey New key.
|
|
106
|
-
* @return {boolean}
|
|
107
|
-
*/
|
|
108
|
-
rename(oldKey, newKey) {
|
|
109
|
-
if (this.items[newKey] !== void 0 || this.items[oldKey] === void 0) {
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
this.items[newKey] = this.items[oldKey];
|
|
113
|
-
delete this.items[oldKey];
|
|
114
|
-
return true;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Find common prefix in icon names.
|
|
119
|
-
* This function works only if all icons use "-" as prefix.
|
|
120
|
-
* Important: this function ignores icon aliases and other custom properties.
|
|
121
|
-
*
|
|
122
|
-
* @param {boolean} [updateIcons] True if function should update prefix in collection. Default = true
|
|
123
|
-
* @return {string}
|
|
124
|
-
*/
|
|
125
|
-
findCommonPrefix(updateIcons) {
|
|
126
|
-
if (this.prefix !== '') {
|
|
127
|
-
// Prefix is already set
|
|
128
|
-
return this.prefix;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Find all possible prefixes
|
|
132
|
-
let commonPrefix = Object.create(null),
|
|
133
|
-
complexPrefix = '';
|
|
134
|
-
|
|
135
|
-
let keys = this.keys(false, true);
|
|
136
|
-
for (let i = 0; i < keys.length; i++) {
|
|
137
|
-
let parts = keys[i].split(':');
|
|
138
|
-
if (parts.length > 1) {
|
|
139
|
-
if (complexPrefix === '' || parts[0] === complexPrefix) {
|
|
140
|
-
complexPrefix = parts[0];
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
// Cannot combine items with complex prefixes
|
|
144
|
-
return '';
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
parts = keys[i].split('-');
|
|
148
|
-
let key = parts.shift(),
|
|
149
|
-
count = 1;
|
|
150
|
-
while (parts.length) {
|
|
151
|
-
if (commonPrefix[count] === void 0) {
|
|
152
|
-
commonPrefix[count] = key;
|
|
153
|
-
} else if (commonPrefix[count] !== key) {
|
|
154
|
-
break;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
key = key + '-' + parts.shift();
|
|
158
|
-
count++;
|
|
159
|
-
}
|
|
160
|
-
commonPrefix[count] = false;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// Find smallest counter with only 1 item
|
|
164
|
-
let count = 1;
|
|
165
|
-
while (typeof commonPrefix[count] === 'string') {
|
|
166
|
-
count++;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
let newPrefix;
|
|
170
|
-
|
|
171
|
-
// Still 1? Nothing to do
|
|
172
|
-
if (count === 1) {
|
|
173
|
-
if (commonPrefix[1] !== void 0) {
|
|
174
|
-
// No items with simple prefixes
|
|
175
|
-
return '';
|
|
176
|
-
}
|
|
177
|
-
// All items had complex prefixes?
|
|
178
|
-
newPrefix = complexPrefix;
|
|
179
|
-
} else {
|
|
180
|
-
// More than 1? Found some common parts
|
|
181
|
-
newPrefix = commonPrefix[count - 1];
|
|
182
|
-
if (complexPrefix !== '') {
|
|
183
|
-
// Both complex and simple prefixes are found, check if they match
|
|
184
|
-
if (
|
|
185
|
-
newPrefix !== complexPrefix &&
|
|
186
|
-
newPrefix.slice(0, complexPrefix.length + 1) !== complexPrefix + '-'
|
|
187
|
-
) {
|
|
188
|
-
// Prefixes don't match
|
|
189
|
-
return '';
|
|
190
|
-
}
|
|
191
|
-
newPrefix = complexPrefix;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if (!updateIcons) {
|
|
196
|
-
return newPrefix;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// Update all items
|
|
200
|
-
this.prefix = newPrefix;
|
|
201
|
-
|
|
202
|
-
let items = Object.create(null);
|
|
203
|
-
let start = newPrefix.length + 1;
|
|
204
|
-
Object.keys(this.items).forEach(key => {
|
|
205
|
-
items[key.slice(start)] = this.items[key];
|
|
206
|
-
});
|
|
207
|
-
this.items = items;
|
|
208
|
-
|
|
209
|
-
return this.prefix;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Get number of items
|
|
214
|
-
*
|
|
215
|
-
* @param {boolean} [filterHidden] True if hidden icons should not be included. default = false
|
|
216
|
-
* @param {boolean} [includeAliases] True if count should include aliases (counts only aliases with transformations). default = false
|
|
217
|
-
* @return {Number}
|
|
218
|
-
*/
|
|
219
|
-
length(filterHidden, includeAliases) {
|
|
220
|
-
let keys = Object.keys(this.items);
|
|
221
|
-
|
|
222
|
-
if (filterHidden) {
|
|
223
|
-
keys = keys.filter(name => this.items[name].hidden !== true);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
let result = keys.length;
|
|
227
|
-
|
|
228
|
-
if (includeAliases) {
|
|
229
|
-
Object.keys(this.items).forEach(key => {
|
|
230
|
-
if (filterHidden && this.items[key].hidden) {
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
if (this.items[key].aliases instanceof Array) {
|
|
234
|
-
this.items[key].aliases.forEach(alias => {
|
|
235
|
-
if (filterHidden) {
|
|
236
|
-
// Check if icon is hidden
|
|
237
|
-
if (typeof alias === 'string' || alias.hidden) {
|
|
238
|
-
// String or hidden
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
if (!alias.rotate && !alias.hFlip && !alias.vFlip) {
|
|
242
|
-
// No transformations
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
result++;
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
return result;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Get item keys
|
|
258
|
-
*
|
|
259
|
-
* @param {boolean} [prefixed] True if results must include prefix (default: false)
|
|
260
|
-
* @param {boolean} [withAliases] True if results must include aliases (default: false)
|
|
261
|
-
* @return {Array}
|
|
262
|
-
*/
|
|
263
|
-
keys(prefixed, withAliases) {
|
|
264
|
-
let results = Object.keys(this.items);
|
|
265
|
-
|
|
266
|
-
if (withAliases) {
|
|
267
|
-
Object.keys(this.items).forEach(key => {
|
|
268
|
-
if (this.items[key].aliases instanceof Array) {
|
|
269
|
-
this.items[key].aliases.forEach(alias => {
|
|
270
|
-
if (typeof alias === 'string') {
|
|
271
|
-
results.push(alias);
|
|
272
|
-
} else if (alias && typeof alias.name === 'string') {
|
|
273
|
-
results.push(alias.name);
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
if (prefixed && this.prefix !== '') {
|
|
281
|
-
results = results.map(item => this.prefix + ':' + item);
|
|
282
|
-
}
|
|
283
|
-
return results;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Run callback on all items
|
|
288
|
-
*
|
|
289
|
-
* @param callback
|
|
290
|
-
*/
|
|
291
|
-
forEach(callback) {
|
|
292
|
-
Object.keys(this.items).forEach(key => {
|
|
293
|
-
callback(this.items[key], key, this.prefix);
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* Run custom promise on all items
|
|
299
|
-
*
|
|
300
|
-
* Example:
|
|
301
|
-
* collection.promiseAll(svg => somePromise(svg)).then(
|
|
302
|
-
* results => {
|
|
303
|
-
* Object.keys(results).forEach(key => {
|
|
304
|
-
* ... // key = collection key, results[key] = xml
|
|
305
|
-
* });
|
|
306
|
-
* }
|
|
307
|
-
* );
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
* @param {function} promise Callback to return Promise for item: callback(svg, key, prefix)
|
|
311
|
-
* @return {Promise}
|
|
312
|
-
*/
|
|
313
|
-
promiseAll(promise) {
|
|
314
|
-
return this._runPromises(key => promise(this.items[key], key, this.prefix));
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* Run custom promise on all items.
|
|
319
|
-
* Same as promiseAll(), but executes each promise separately and result is different.
|
|
320
|
-
*
|
|
321
|
-
* Result is an object: {
|
|
322
|
-
* success: list of successful promises,
|
|
323
|
-
* error: list of failed promises
|
|
324
|
-
* }
|
|
325
|
-
*
|
|
326
|
-
* Each list in result is object where key is icon key, value is result or error.
|
|
327
|
-
*
|
|
328
|
-
* Rejected object only contains "error" part of result.
|
|
329
|
-
*
|
|
330
|
-
* @param {function} promise Callback to return Promise for item: callback(svg, key, prefix)
|
|
331
|
-
* @param {boolean} [stopOnError] True if execution should halt upon finding error. Default = false
|
|
332
|
-
* If false, promise will be fulfilled unless all promises fail
|
|
333
|
-
* @returns {Promise}
|
|
334
|
-
*/
|
|
335
|
-
promiseEach(promise, stopOnError) {
|
|
336
|
-
let items = this.items,
|
|
337
|
-
prefix = this.prefix;
|
|
338
|
-
|
|
339
|
-
stopOnError = stopOnError === true;
|
|
340
|
-
|
|
341
|
-
return new Promise((fulfill, reject) => {
|
|
342
|
-
// Convert to arrays
|
|
343
|
-
let keys = Object.keys(items),
|
|
344
|
-
failed = 0,
|
|
345
|
-
success = 0,
|
|
346
|
-
results = {
|
|
347
|
-
success: Object.create(null),
|
|
348
|
-
error: Object.create(null),
|
|
349
|
-
skipped: Object.create(null),
|
|
350
|
-
};
|
|
351
|
-
|
|
352
|
-
function next() {
|
|
353
|
-
let key = keys.shift();
|
|
354
|
-
if (key === void 0) {
|
|
355
|
-
return done();
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
// Get promise
|
|
359
|
-
let func = promise(items[key], key, prefix);
|
|
360
|
-
if (func === null) {
|
|
361
|
-
results.skipped[key] = true;
|
|
362
|
-
process.nextTick(next);
|
|
363
|
-
return;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
// Run promise
|
|
367
|
-
func
|
|
368
|
-
.then(result => {
|
|
369
|
-
results.success[key] = result;
|
|
370
|
-
success++;
|
|
371
|
-
|
|
372
|
-
process.nextTick(next);
|
|
373
|
-
})
|
|
374
|
-
.catch(err => {
|
|
375
|
-
results.error[key] = err;
|
|
376
|
-
failed++;
|
|
377
|
-
|
|
378
|
-
if (stopOnError) {
|
|
379
|
-
reject(results.error);
|
|
380
|
-
} else {
|
|
381
|
-
process.nextTick(next);
|
|
382
|
-
}
|
|
383
|
-
});
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
function done() {
|
|
387
|
-
if (!success && failed) {
|
|
388
|
-
reject(results.error);
|
|
389
|
-
} else {
|
|
390
|
-
fulfill(results);
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
next();
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* Run promise on all items
|
|
400
|
-
*
|
|
401
|
-
* @param {function} callback Function that returns Promise for one item (key, prefix)
|
|
402
|
-
* @return {Promise}
|
|
403
|
-
* @private
|
|
404
|
-
*/
|
|
405
|
-
_runPromises(callback) {
|
|
406
|
-
let prefix = this.prefix;
|
|
407
|
-
|
|
408
|
-
return new Promise((fulfill, reject) => {
|
|
409
|
-
// Convert to arrays
|
|
410
|
-
let keys = Object.keys(this.items),
|
|
411
|
-
promises = [],
|
|
412
|
-
resultKeys = [];
|
|
413
|
-
|
|
414
|
-
keys.forEach((key, index) => {
|
|
415
|
-
let result = callback(key, prefix);
|
|
416
|
-
if (result !== null) {
|
|
417
|
-
promises.push(result);
|
|
418
|
-
resultKeys.push(key);
|
|
419
|
-
}
|
|
420
|
-
});
|
|
421
|
-
|
|
422
|
-
// Run all promises
|
|
423
|
-
Promise.all(promises)
|
|
424
|
-
.then(results => {
|
|
425
|
-
let filtered = Object.create(null);
|
|
426
|
-
resultKeys.forEach((key, index) => {
|
|
427
|
-
filtered[key] = results[index];
|
|
428
|
-
});
|
|
429
|
-
fulfill(filtered);
|
|
430
|
-
})
|
|
431
|
-
.catch(err => {
|
|
432
|
-
reject(err);
|
|
433
|
-
});
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
/**
|
|
438
|
-
* Merge collection with older version of same collection
|
|
439
|
-
*
|
|
440
|
-
* @param {Collection} oldCollection Collection to merge with
|
|
441
|
-
* @param {object} [options]
|
|
442
|
-
* @returns {object|string} String on error, object with statistics on success
|
|
443
|
-
*/
|
|
444
|
-
merge(oldCollection, options) {
|
|
445
|
-
if (this.prefix !== oldCollection.prefix) {
|
|
446
|
-
return 'Cannot merge collections with different prefixes.';
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
let results = {
|
|
450
|
-
identical: 0, // number of icons that are identical
|
|
451
|
-
updated: 0, // number of icons that are different
|
|
452
|
-
removed: 0, // number of icons that were missing in this collection
|
|
453
|
-
renamed: 0, // number of icons that were renamed
|
|
454
|
-
};
|
|
455
|
-
|
|
456
|
-
// Check options
|
|
457
|
-
options = options ? options : Object.create(null);
|
|
458
|
-
Object.keys(defaultMergeOptions).forEach(key => {
|
|
459
|
-
if (options[key] === void 0) {
|
|
460
|
-
options[key] = defaultMergeOptions[key];
|
|
461
|
-
}
|
|
462
|
-
});
|
|
463
|
-
|
|
464
|
-
let oldKeys = oldCollection.keys(),
|
|
465
|
-
newKeys = this.keys();
|
|
466
|
-
|
|
467
|
-
// Find all aliases and hash all icons
|
|
468
|
-
let newAliases = Object.create(null),
|
|
469
|
-
newHashes = Object.create(null),
|
|
470
|
-
oldHashes = Object.create(null),
|
|
471
|
-
newChars = Object.create(null);
|
|
472
|
-
|
|
473
|
-
newKeys.forEach(key => {
|
|
474
|
-
let svg = this.items[key];
|
|
475
|
-
newHashes[key] = options.hashCallback(key, svg, this);
|
|
476
|
-
if (options.checkAliases && svg.aliases !== void 0) {
|
|
477
|
-
svg.aliases.forEach(alias => {
|
|
478
|
-
if (typeof alias === 'string') {
|
|
479
|
-
newAliases[alias] = key;
|
|
480
|
-
} else {
|
|
481
|
-
newAliases[alias.name] = key;
|
|
482
|
-
}
|
|
483
|
-
});
|
|
484
|
-
}
|
|
485
|
-
if (options.checkChars && svg.char !== void 0) {
|
|
486
|
-
newChars[svg.char] = key;
|
|
487
|
-
}
|
|
488
|
-
});
|
|
489
|
-
oldKeys.forEach(key => {
|
|
490
|
-
let svg = oldCollection.items[key];
|
|
491
|
-
oldHashes[key] = options.hashCallback(key, svg, oldCollection);
|
|
492
|
-
});
|
|
493
|
-
|
|
494
|
-
// Check each old file
|
|
495
|
-
oldKeys.forEach(oldKey => {
|
|
496
|
-
let oldSVG = oldCollection.items[oldKey];
|
|
497
|
-
|
|
498
|
-
if (newHashes[oldKey] !== void 0) {
|
|
499
|
-
// Item exists. Check aliases
|
|
500
|
-
if (newHashes[oldKey] !== oldHashes[oldKey]) {
|
|
501
|
-
results.updated++;
|
|
502
|
-
} else {
|
|
503
|
-
results.identical++;
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
let newSVG = this.items[oldKey];
|
|
507
|
-
|
|
508
|
-
// Check all aliases
|
|
509
|
-
if (options.checkAliases && oldSVG.aliases) {
|
|
510
|
-
oldSVG.aliases.forEach(alias => {
|
|
511
|
-
let name = typeof alias === 'string' ? alias : alias.name;
|
|
512
|
-
if (newAliases[name] === void 0 && newHashes[name] === void 0) {
|
|
513
|
-
// Missing alias
|
|
514
|
-
if (this.items[oldKey].aliases === void 0) {
|
|
515
|
-
this.items[oldKey].aliases = [];
|
|
516
|
-
}
|
|
517
|
-
this.items[oldKey].aliases.push(alias);
|
|
518
|
-
newAliases[name] = oldKey;
|
|
519
|
-
}
|
|
520
|
-
});
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
// Add character if its missing
|
|
524
|
-
if (options.checkChars && oldSVG.char !== void 0) {
|
|
525
|
-
let char = oldSVG.char;
|
|
526
|
-
if (newChars[char] === void 0 && newSVG.char === void 0) {
|
|
527
|
-
newSVG.char = oldSVG.char;
|
|
528
|
-
newChars[char] = oldKey;
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
// Add category if its missing
|
|
533
|
-
if (
|
|
534
|
-
options.checkCategories &&
|
|
535
|
-
oldSVG.category !== void 0 &&
|
|
536
|
-
newSVG.category === void 0
|
|
537
|
-
) {
|
|
538
|
-
newSVG.category =
|
|
539
|
-
typeof oldSVG.category === 'string'
|
|
540
|
-
? [oldSVG.category]
|
|
541
|
-
: oldSVG.category.slice(0);
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
return;
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
if (newAliases[oldKey] !== void 0) {
|
|
548
|
-
// Item exists as other icon's alias
|
|
549
|
-
return;
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
// Item is missing. Check for matching item
|
|
553
|
-
let newKey = null,
|
|
554
|
-
oldHash = oldHashes[oldKey];
|
|
555
|
-
Object.keys(newHashes).forEach(key => {
|
|
556
|
-
if (newKey === null && newHashes[key] === oldHash) {
|
|
557
|
-
newKey = key;
|
|
558
|
-
}
|
|
559
|
-
});
|
|
560
|
-
|
|
561
|
-
if (newKey !== null) {
|
|
562
|
-
// Item was renamed
|
|
563
|
-
results.renamed++;
|
|
564
|
-
if (this.items[newKey].aliases === void 0) {
|
|
565
|
-
this.items[newKey].aliases = [];
|
|
566
|
-
}
|
|
567
|
-
this.items[newKey].aliases.push(oldKey);
|
|
568
|
-
newAliases[oldKey] = newKey;
|
|
569
|
-
|
|
570
|
-
if (options.checkAliases && oldSVG.aliases) {
|
|
571
|
-
oldSVG.aliases.forEach(alias => {
|
|
572
|
-
let name = typeof alias === 'string' ? alias : alias.name;
|
|
573
|
-
if (newAliases[name] === void 0 && newHashes[name] === void 0) {
|
|
574
|
-
// Missing alias
|
|
575
|
-
this.items[newKey].aliases.push(alias);
|
|
576
|
-
newAliases[name] = newKey;
|
|
577
|
-
}
|
|
578
|
-
});
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
if (options.checkChars && oldSVG.char !== void 0) {
|
|
582
|
-
let char = oldSVG.char;
|
|
583
|
-
if (newChars[char] === void 0 && this.items[newKey].char === void 0) {
|
|
584
|
-
this.items[newKey].char = oldSVG.char;
|
|
585
|
-
newChars[char] = newKey;
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
return;
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
// Item was deleted
|
|
592
|
-
if (!oldSVG.hidden) {
|
|
593
|
-
results.removed++;
|
|
594
|
-
}
|
|
595
|
-
this.add(oldKey, new SVG(oldSVG.toString()));
|
|
596
|
-
|
|
597
|
-
let newSVG = this.items[oldKey];
|
|
598
|
-
if (options.markAsHidden) {
|
|
599
|
-
newSVG.hidden = true;
|
|
600
|
-
}
|
|
601
|
-
newHashes[oldKey] = oldHashes[oldKey];
|
|
602
|
-
|
|
603
|
-
if (oldSVG.aliases) {
|
|
604
|
-
newSVG.aliases = [];
|
|
605
|
-
oldSVG.aliases.forEach(alias => {
|
|
606
|
-
let name = typeof alias === 'string' ? alias : alias.name;
|
|
607
|
-
if (newAliases[name] === void 0 && newHashes[name] === void 0) {
|
|
608
|
-
// Missing alias
|
|
609
|
-
newSVG.aliases.push(
|
|
610
|
-
typeof alias === 'string'
|
|
611
|
-
? alias
|
|
612
|
-
: Object.assign(Object.create(null), alias)
|
|
613
|
-
);
|
|
614
|
-
newAliases[name] = oldKey;
|
|
615
|
-
}
|
|
616
|
-
});
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
// Add character if its missing
|
|
620
|
-
if (options.checkChars && oldSVG.char !== void 0) {
|
|
621
|
-
let char = oldSVG.char;
|
|
622
|
-
if (newChars[char] === void 0) {
|
|
623
|
-
this.items[oldKey].char = oldSVG.char;
|
|
624
|
-
newChars[char] = oldKey;
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
// Add category if its missing
|
|
629
|
-
if (options.checkCategories && oldSVG.category !== void 0) {
|
|
630
|
-
this.items[oldKey].category =
|
|
631
|
-
typeof oldSVG.category === 'string'
|
|
632
|
-
? [oldSVG.category]
|
|
633
|
-
: oldSVG.category.slice(0);
|
|
634
|
-
}
|
|
635
|
-
});
|
|
636
|
-
|
|
637
|
-
return results;
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
module.exports = Collection;
|