@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
package/src/export/json.js
DELETED
|
@@ -1,329 +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 fs = require('fs');
|
|
13
|
-
const path = require('path');
|
|
14
|
-
const helpers = require('../helpers');
|
|
15
|
-
const optimize = require('@iconify/json-tools').Collection.optimize;
|
|
16
|
-
|
|
17
|
-
const defaults = {
|
|
18
|
-
// True if characters table added by importing fonts should be included in JSON output
|
|
19
|
-
includeChars: true,
|
|
20
|
-
|
|
21
|
-
// True if aliases should be included in JSON output
|
|
22
|
-
includeAliases: true,
|
|
23
|
-
|
|
24
|
-
// True if categories should be included in JSON output
|
|
25
|
-
includeCategories: false,
|
|
26
|
-
|
|
27
|
-
// True if inlineHeight, inlineTop and verticalAlign attributes should be included in output
|
|
28
|
-
includeInline: true,
|
|
29
|
-
|
|
30
|
-
// True if prefix should be included separately
|
|
31
|
-
// If enabled and collection has no prefix, exporter will try to detect common prefix (result is saved in collection)
|
|
32
|
-
separatePrefix: true,
|
|
33
|
-
|
|
34
|
-
// If true, common values would be moved to root scope to make JSON file smaller
|
|
35
|
-
optimize: false,
|
|
36
|
-
|
|
37
|
-
// If true all white space is removed, making file smaller, but harder to read
|
|
38
|
-
minify: false,
|
|
39
|
-
|
|
40
|
-
// Information block, overrides collection's block
|
|
41
|
-
info: null,
|
|
42
|
-
|
|
43
|
-
// Themes block (legacy), overrides collection's block
|
|
44
|
-
themes: null,
|
|
45
|
-
|
|
46
|
-
// Prefixes and suffixes, replacement for themes block for new format
|
|
47
|
-
themePrefixes: null,
|
|
48
|
-
themeSuffixes: null,
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const transformKeys = ['rotate', 'vFlip', 'hFlip'];
|
|
52
|
-
|
|
53
|
-
const positionAttributes = ['left', 'top'];
|
|
54
|
-
|
|
55
|
-
const inlineAttributes = ['inlineHeight', 'inlineTop', 'verticalAlign'];
|
|
56
|
-
|
|
57
|
-
const extraAttributes = ['deprecated', 'hidden', 'renamed'];
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Export collection to json file
|
|
61
|
-
*
|
|
62
|
-
* @param {Collection} collection Collection to export
|
|
63
|
-
* @param {string} [target] Target filename
|
|
64
|
-
* @param {object} [options] Options
|
|
65
|
-
* @returns {Promise}
|
|
66
|
-
*/
|
|
67
|
-
module.exports = (collection, target, options) => {
|
|
68
|
-
options = options === void 0 ? Object.create(null) : options;
|
|
69
|
-
Object.keys(defaults).forEach((key) => {
|
|
70
|
-
if (options[key] === void 0) {
|
|
71
|
-
options[key] = defaults[key];
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
// Function to add prefix to name if needed
|
|
76
|
-
let prefix = (key) =>
|
|
77
|
-
options.separatePrefix
|
|
78
|
-
? key
|
|
79
|
-
: (collection.prefix === '' ? '' : collection.prefix + ':') + key;
|
|
80
|
-
|
|
81
|
-
// Return promise
|
|
82
|
-
return new Promise((fulfill, reject) => {
|
|
83
|
-
let json = Object.create(null),
|
|
84
|
-
categories = Object.create(null);
|
|
85
|
-
|
|
86
|
-
if (options.separatePrefix) {
|
|
87
|
-
if (
|
|
88
|
-
collection.prefix === '' &&
|
|
89
|
-
collection.findCommonPrefix(true) === ''
|
|
90
|
-
) {
|
|
91
|
-
options.separatePrefix = false;
|
|
92
|
-
} else {
|
|
93
|
-
json.prefix = collection.prefix;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Add info block
|
|
98
|
-
if (
|
|
99
|
-
collection.info &&
|
|
100
|
-
collection.info.name &&
|
|
101
|
-
typeof collection.info.author === 'object'
|
|
102
|
-
) {
|
|
103
|
-
json.info = JSON.parse(JSON.stringify(collection.info));
|
|
104
|
-
json.info.total = collection.length(true, true);
|
|
105
|
-
}
|
|
106
|
-
if (
|
|
107
|
-
options.info &&
|
|
108
|
-
options.info.name &&
|
|
109
|
-
typeof options.info.author === 'object'
|
|
110
|
-
) {
|
|
111
|
-
json.info = JSON.parse(JSON.stringify(options.info));
|
|
112
|
-
json.info.total = collection.length(true, true);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Create icons block
|
|
116
|
-
json.icons = Object.create(null);
|
|
117
|
-
|
|
118
|
-
// Export all files
|
|
119
|
-
let keys = collection.keys();
|
|
120
|
-
keys.sort((a, b) => a.localeCompare(b));
|
|
121
|
-
keys.forEach((key) => {
|
|
122
|
-
let svg = collection.items[key],
|
|
123
|
-
iconKey = prefix(key);
|
|
124
|
-
|
|
125
|
-
json.icons[iconKey] = {
|
|
126
|
-
body: svg.getBody().replace(/\s*\n\s*/g, ''),
|
|
127
|
-
width: svg.width,
|
|
128
|
-
height: svg.height,
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
// Add left/top
|
|
132
|
-
positionAttributes.forEach((attr) => {
|
|
133
|
-
if (svg[attr] !== 0) {
|
|
134
|
-
json.icons[iconKey][attr] = svg[attr];
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
// Add transformations
|
|
139
|
-
transformKeys.forEach((attr) => {
|
|
140
|
-
if (svg[attr] !== void 0) {
|
|
141
|
-
json.icons[iconKey][attr] = svg[attr];
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
// Include inline attributes
|
|
146
|
-
if (options.includeInline) {
|
|
147
|
-
inlineAttributes.forEach((attr) => {
|
|
148
|
-
if (svg[attr] !== void 0) {
|
|
149
|
-
json.icons[iconKey][attr] = svg[attr];
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// Extra attributes
|
|
155
|
-
extraAttributes.forEach((attr) => {
|
|
156
|
-
if (svg[attr] !== void 0) {
|
|
157
|
-
json.icons[iconKey][attr] = svg[attr];
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
// Category
|
|
162
|
-
if (options.includeCategories && svg.category !== void 0) {
|
|
163
|
-
let list =
|
|
164
|
-
typeof svg.category === 'string' ? [svg.category] : svg.category;
|
|
165
|
-
list.forEach((cat) => {
|
|
166
|
-
if (categories[cat] === void 0) {
|
|
167
|
-
categories[cat] = [];
|
|
168
|
-
}
|
|
169
|
-
categories[cat].push(iconKey);
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
// Add aliases
|
|
175
|
-
if (options.includeAliases) {
|
|
176
|
-
let aliases = Object.create(null);
|
|
177
|
-
|
|
178
|
-
collection.forEach((svg, key) => {
|
|
179
|
-
if (svg.aliases) {
|
|
180
|
-
let parentKey = prefix(key);
|
|
181
|
-
|
|
182
|
-
svg.aliases.forEach((alias) => {
|
|
183
|
-
// Check alias format
|
|
184
|
-
let item = {
|
|
185
|
-
parent: parentKey,
|
|
186
|
-
},
|
|
187
|
-
name;
|
|
188
|
-
|
|
189
|
-
switch (typeof alias) {
|
|
190
|
-
case 'string':
|
|
191
|
-
name = alias;
|
|
192
|
-
break;
|
|
193
|
-
|
|
194
|
-
case 'object':
|
|
195
|
-
if (alias.name === void 0) {
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
name = alias.name;
|
|
199
|
-
|
|
200
|
-
transformKeys.forEach((key) => {
|
|
201
|
-
if (alias[key] !== void 0) {
|
|
202
|
-
item[key] = alias[key];
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
extraAttributes.forEach((key) => {
|
|
207
|
-
if (alias[key] !== void 0) {
|
|
208
|
-
item[key] = alias[key];
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
break;
|
|
213
|
-
|
|
214
|
-
default:
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// Add prefix
|
|
219
|
-
name = prefix(name);
|
|
220
|
-
|
|
221
|
-
// Check for duplicate
|
|
222
|
-
if (json.icons[name] !== void 0) {
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
// Add alias
|
|
227
|
-
aliases[name] = item;
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
// Sort keys
|
|
233
|
-
let keys = Object.keys(aliases);
|
|
234
|
-
if (keys.length) {
|
|
235
|
-
keys.sort((a, b) => a.localeCompare(b));
|
|
236
|
-
json.aliases = Object.create(null);
|
|
237
|
-
keys.forEach((key) => {
|
|
238
|
-
json.aliases[key] = aliases[key];
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// Add characters
|
|
244
|
-
if (options.includeChars) {
|
|
245
|
-
let chars = Object.create(null);
|
|
246
|
-
collection.forEach((svg, key) => {
|
|
247
|
-
if (svg.char === void 0) {
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
if (options.includeAliases && svg.aliases) {
|
|
251
|
-
svg.aliases.forEach((alias) => {
|
|
252
|
-
if (
|
|
253
|
-
typeof alias === 'object' &&
|
|
254
|
-
alias.char !== void 0 &&
|
|
255
|
-
alias.name !== void 0
|
|
256
|
-
) {
|
|
257
|
-
chars[alias.char] = prefix(alias.name);
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
chars[svg.char] = prefix(key);
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
// Sort keys
|
|
265
|
-
let keys = Object.keys(chars);
|
|
266
|
-
if (keys.length) {
|
|
267
|
-
keys.sort((a, b) => a.localeCompare(b));
|
|
268
|
-
json.chars = Object.create(null);
|
|
269
|
-
keys.forEach((key) => {
|
|
270
|
-
json.chars[key] = chars[key];
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// Add categories
|
|
276
|
-
if (options.includeCategories) {
|
|
277
|
-
let categoryKeys = Object.keys(categories);
|
|
278
|
-
|
|
279
|
-
if (categoryKeys.length) {
|
|
280
|
-
categoryKeys.sort((a, b) => a.localeCompare(b));
|
|
281
|
-
json.categories = Object.create(null);
|
|
282
|
-
categoryKeys.forEach((key) => {
|
|
283
|
-
categories[key].sort((a, b) => a.localeCompare(b));
|
|
284
|
-
json.categories[key] = categories[key];
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
// Add themes
|
|
290
|
-
if (collection.themes) {
|
|
291
|
-
json.themes = JSON.parse(JSON.stringify(collection.themes));
|
|
292
|
-
} else if (options.themes) {
|
|
293
|
-
json.themes = JSON.parse(JSON.stringify(options.themes));
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
['prefixes', 'suffixes'].forEach((attr) => {
|
|
297
|
-
if (collection[attr]) {
|
|
298
|
-
json[attr] = Object.assign({}, collection[attr]);
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
const optionsKey =
|
|
303
|
-
'theme' + attr.slice(0, 1).toUpperCase() + attr.slice(1);
|
|
304
|
-
if (options[optionsKey]) {
|
|
305
|
-
json[attr] = Object.assign({}, options[optionsKey]);
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
// Optimize common attributes by moving duplicate items to root
|
|
310
|
-
if (options.optimize) {
|
|
311
|
-
optimize(json);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
// Export
|
|
315
|
-
let content = options.minify
|
|
316
|
-
? JSON.stringify(json)
|
|
317
|
-
: JSON.stringify(json, null, '\t');
|
|
318
|
-
if (typeof target === 'string') {
|
|
319
|
-
try {
|
|
320
|
-
helpers.mkdir(path.dirname(target));
|
|
321
|
-
fs.writeFileSync(target, content, 'utf8');
|
|
322
|
-
} catch (err) {
|
|
323
|
-
reject(err);
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
fulfill(json);
|
|
328
|
-
});
|
|
329
|
-
};
|
package/src/export/phantomjs.js
DELETED
|
@@ -1,76 +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 fs = require('fs');
|
|
13
|
-
const path = require('path');
|
|
14
|
-
const child_process = require('child_process');
|
|
15
|
-
const crypto = require('crypto');
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Generate image from data
|
|
19
|
-
*
|
|
20
|
-
* @param {object} data
|
|
21
|
-
* @return {Promise<any>}
|
|
22
|
-
*/
|
|
23
|
-
module.exports = data =>
|
|
24
|
-
new Promise((fulfill, reject) => {
|
|
25
|
-
let rootDir = path.dirname(path.dirname(path.dirname(__filename))),
|
|
26
|
-
tempDir = rootDir + '/temp',
|
|
27
|
-
cmd = path.dirname(__filename) + '/phantomjs_script.js';
|
|
28
|
-
|
|
29
|
-
// Convert data to array
|
|
30
|
-
if (!(data instanceof Array)) {
|
|
31
|
-
data = [data];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Generate temporary file
|
|
35
|
-
data = JSON.stringify(data, null, 4);
|
|
36
|
-
|
|
37
|
-
let tempFile =
|
|
38
|
-
crypto
|
|
39
|
-
.createHash('md5')
|
|
40
|
-
.update(data)
|
|
41
|
-
.digest('hex') +
|
|
42
|
-
'-' +
|
|
43
|
-
Date.now() +
|
|
44
|
-
'.json',
|
|
45
|
-
tempFilename = tempDir + '/' + tempFile;
|
|
46
|
-
|
|
47
|
-
try {
|
|
48
|
-
fs.mkdirSync(tempDir);
|
|
49
|
-
} catch (err) {}
|
|
50
|
-
|
|
51
|
-
fs.writeFile(tempFilename, data, 'utf8', err => {
|
|
52
|
-
if (err) {
|
|
53
|
-
reject(err);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Execute
|
|
58
|
-
child_process.execFile(
|
|
59
|
-
'phantomjs',
|
|
60
|
-
[cmd, tempFilename],
|
|
61
|
-
{
|
|
62
|
-
env: process.env,
|
|
63
|
-
uid: process.getuid(),
|
|
64
|
-
},
|
|
65
|
-
(error, stdout, stderr) => {
|
|
66
|
-
fs.unlinkSync(tempFilename);
|
|
67
|
-
// console.log(stdout);
|
|
68
|
-
if (error) {
|
|
69
|
-
reject('Error executing: ' + cmd + ': ' + error);
|
|
70
|
-
} else {
|
|
71
|
-
fulfill();
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
);
|
|
75
|
-
});
|
|
76
|
-
});
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var system = require('system'),
|
|
4
|
-
fs = require('fs'),
|
|
5
|
-
webpage = require('webpage'),
|
|
6
|
-
dataList,
|
|
7
|
-
done,
|
|
8
|
-
data,
|
|
9
|
-
next;
|
|
10
|
-
|
|
11
|
-
if (system.args.length < 2) {
|
|
12
|
-
console.log('Invalid arguments');
|
|
13
|
-
phantom.exit();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
dataList = JSON.parse(fs.read(system.args[1]));
|
|
17
|
-
if (typeof dataList !== 'object' || !(dataList instanceof Array)) {
|
|
18
|
-
console.log('Invalid arguments');
|
|
19
|
-
phantom.exit();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Run next task
|
|
24
|
-
*/
|
|
25
|
-
next = function() {
|
|
26
|
-
var canvas = document.createElement('canvas'),
|
|
27
|
-
ctx,
|
|
28
|
-
pending,
|
|
29
|
-
images,
|
|
30
|
-
canComplete;
|
|
31
|
-
|
|
32
|
-
data = dataList.shift();
|
|
33
|
-
if (data === void 0) {
|
|
34
|
-
phantom.exit();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function loaded(index) {
|
|
38
|
-
var item;
|
|
39
|
-
|
|
40
|
-
if (index === true) {
|
|
41
|
-
// failed image
|
|
42
|
-
pending--;
|
|
43
|
-
} else if (index !== false) {
|
|
44
|
-
// loaded image
|
|
45
|
-
pending--;
|
|
46
|
-
item = data.images[index];
|
|
47
|
-
ctx.drawImage(
|
|
48
|
-
images[index],
|
|
49
|
-
item.left,
|
|
50
|
-
item.top,
|
|
51
|
-
item.width,
|
|
52
|
-
item.height
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (!canComplete || pending > 0) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
canComplete = false;
|
|
61
|
-
done(canvas.toDataURL('image/png', 1));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
canvas.setAttribute('width', data.width);
|
|
65
|
-
canvas.setAttribute('height', data.height);
|
|
66
|
-
ctx = canvas.getContext('2d');
|
|
67
|
-
ctx.clearRect(0, 0, data.width, data.height);
|
|
68
|
-
|
|
69
|
-
if (data.background !== 'transparent') {
|
|
70
|
-
ctx.fillStyle = data.background;
|
|
71
|
-
ctx.fillRect(0, 0, data.width, data.height);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
images = [];
|
|
75
|
-
pending = 0;
|
|
76
|
-
canComplete = false;
|
|
77
|
-
|
|
78
|
-
data.images.forEach(function(item, index) {
|
|
79
|
-
var image = new Image();
|
|
80
|
-
image.onload = function() {
|
|
81
|
-
loaded(index);
|
|
82
|
-
};
|
|
83
|
-
image.onerror = function() {
|
|
84
|
-
loaded(true);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
pending++;
|
|
88
|
-
images.push(image);
|
|
89
|
-
image.setAttribute('src', item.url);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
canComplete = true;
|
|
93
|
-
loaded(false);
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Completed task
|
|
98
|
-
*
|
|
99
|
-
* @param png
|
|
100
|
-
*/
|
|
101
|
-
done = function(png) {
|
|
102
|
-
var page;
|
|
103
|
-
|
|
104
|
-
// Create page
|
|
105
|
-
page = webpage.create();
|
|
106
|
-
page.viewportSize = {
|
|
107
|
-
width: data.width,
|
|
108
|
-
height: data.height,
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
page.open(png, function() {
|
|
112
|
-
page.render(data.output);
|
|
113
|
-
console.log(
|
|
114
|
-
JSON.stringify({
|
|
115
|
-
output: data.output,
|
|
116
|
-
width: data.width,
|
|
117
|
-
height: data.height,
|
|
118
|
-
})
|
|
119
|
-
);
|
|
120
|
-
setTimeout(next, 0);
|
|
121
|
-
});
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
// Run next task
|
|
125
|
-
next();
|
package/src/export/png.js
DELETED
|
@@ -1,193 +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 fs = require('fs');
|
|
13
|
-
const path = require('path');
|
|
14
|
-
const helpers = require('../helpers');
|
|
15
|
-
const phantom = require('./phantomjs');
|
|
16
|
-
const SVG = require('../svg');
|
|
17
|
-
const Collection = require('../collection');
|
|
18
|
-
|
|
19
|
-
const defaults = {
|
|
20
|
-
color: '#000',
|
|
21
|
-
background: 'transparent',
|
|
22
|
-
|
|
23
|
-
// Icon dimensions. null = not set, which will set to same as SVG
|
|
24
|
-
width: null,
|
|
25
|
-
height: null,
|
|
26
|
-
|
|
27
|
-
// False if errors should be ignored
|
|
28
|
-
reject: true,
|
|
29
|
-
|
|
30
|
-
// False if instead of converting icons function should return data for phantom() call
|
|
31
|
-
parse: true,
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Export to .png file
|
|
36
|
-
*
|
|
37
|
-
* @param {SVG|Collection|string} item
|
|
38
|
-
* @param target
|
|
39
|
-
* @param options
|
|
40
|
-
* @return {Promise<any>}
|
|
41
|
-
*/
|
|
42
|
-
module.exports = (item, target, options) => {
|
|
43
|
-
options = options === void 0 ? Object.create(null) : options;
|
|
44
|
-
Object.keys(defaults).forEach(key => {
|
|
45
|
-
if (options[key] === void 0) {
|
|
46
|
-
options[key] = defaults[key];
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
const scaleSVG = (svg, target) => {
|
|
51
|
-
let width = svg.width,
|
|
52
|
-
height = svg.height;
|
|
53
|
-
|
|
54
|
-
if (typeof options.height === 'number' && options.height !== height) {
|
|
55
|
-
// Scale
|
|
56
|
-
width = (width * options.height) / height;
|
|
57
|
-
height = options.height;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Get raw SVG
|
|
61
|
-
let content = svg.toString();
|
|
62
|
-
content = content.replace(/currentColor/g, options.color);
|
|
63
|
-
|
|
64
|
-
// Generate data
|
|
65
|
-
return {
|
|
66
|
-
output: target,
|
|
67
|
-
width: width,
|
|
68
|
-
height: height,
|
|
69
|
-
background: options.background,
|
|
70
|
-
images: [
|
|
71
|
-
{
|
|
72
|
-
url:
|
|
73
|
-
'data:image/svg+xml;base64,' +
|
|
74
|
-
Buffer.from(content, 'utf8').toString('base64'),
|
|
75
|
-
left: 0,
|
|
76
|
-
top: 0,
|
|
77
|
-
width: width,
|
|
78
|
-
height: height,
|
|
79
|
-
},
|
|
80
|
-
],
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
return new Promise((fulfill, reject) => {
|
|
85
|
-
// Parse icon
|
|
86
|
-
if (typeof item === 'string') {
|
|
87
|
-
item = new SVG(item);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (item instanceof SVG) {
|
|
91
|
-
let data = scaleSVG(item, target);
|
|
92
|
-
if (!options.parse) {
|
|
93
|
-
// Return raw data for running multiple PhantomJS calls at the same time to speed up building many icons
|
|
94
|
-
fulfill(data);
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
phantom(data)
|
|
99
|
-
.then(res => {
|
|
100
|
-
fulfill(item);
|
|
101
|
-
})
|
|
102
|
-
.catch(err => {
|
|
103
|
-
if (options.reject) {
|
|
104
|
-
reject(err);
|
|
105
|
-
} else {
|
|
106
|
-
fulfill(item);
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Parse collection
|
|
113
|
-
if (!(item instanceof Collection)) {
|
|
114
|
-
reject('Invalid arguments.');
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
let data = [],
|
|
119
|
-
results = options.parse ? {} : data,
|
|
120
|
-
collection = item;
|
|
121
|
-
|
|
122
|
-
collection.forEach((svg, key) => {
|
|
123
|
-
// Get filename
|
|
124
|
-
let filename = target;
|
|
125
|
-
if (typeof filename === 'function') {
|
|
126
|
-
// Callback
|
|
127
|
-
filename = filename(key, svg, collection, options);
|
|
128
|
-
if (filename === null) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
} else {
|
|
132
|
-
// Replace keywords with icon data
|
|
133
|
-
if (filename.indexOf('{icon}') === -1) {
|
|
134
|
-
// No {icon} found - treat target as directory name. Append icon name without prefix
|
|
135
|
-
filename +=
|
|
136
|
-
(filename.length && filename.slice(-1) !== '/' ? '/' : '') +
|
|
137
|
-
key +
|
|
138
|
-
'.png';
|
|
139
|
-
} else {
|
|
140
|
-
filename = filename
|
|
141
|
-
.replace('{icon}', key)
|
|
142
|
-
.replace('{prefix}', collection.prefix)
|
|
143
|
-
.replace('{color}', options.color)
|
|
144
|
-
.replace('{width}', options.width)
|
|
145
|
-
.replace('{height}', options.height);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Create target directory
|
|
150
|
-
helpers.mkdir(path.dirname(filename));
|
|
151
|
-
|
|
152
|
-
// Get data
|
|
153
|
-
data.push(scaleSVG(svg, filename));
|
|
154
|
-
|
|
155
|
-
// Set result
|
|
156
|
-
if (options.parse) {
|
|
157
|
-
results[key] = filename;
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
// Return data
|
|
162
|
-
if (!options.parse) {
|
|
163
|
-
fulfill(data);
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// Parse icons in bulk, 16 icons at a time
|
|
168
|
-
const next = () => {
|
|
169
|
-
let items = data.slice(0, 16);
|
|
170
|
-
|
|
171
|
-
if (!items.length) {
|
|
172
|
-
// Done
|
|
173
|
-
fulfill(results);
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
data = data.slice(16);
|
|
178
|
-
phantom(items)
|
|
179
|
-
.then(res => {
|
|
180
|
-
next();
|
|
181
|
-
})
|
|
182
|
-
.catch(err => {
|
|
183
|
-
if (options.reject) {
|
|
184
|
-
reject(err);
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
next();
|
|
188
|
-
});
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
next();
|
|
192
|
-
});
|
|
193
|
-
};
|