@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/component.js
DELETED
|
@@ -1,482 +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 helpers = require('../helpers');
|
|
14
|
-
|
|
15
|
-
const iconType = `interface IconifyIcon {
|
|
16
|
-
body: string;
|
|
17
|
-
left?: number;
|
|
18
|
-
top?: number;
|
|
19
|
-
width?: number;
|
|
20
|
-
height?: number;
|
|
21
|
-
rotate?: number;
|
|
22
|
-
hFlip?: boolean;
|
|
23
|
-
vFlip?: boolean;
|
|
24
|
-
}
|
|
25
|
-
declare const data: IconifyIcon;
|
|
26
|
-
export default data;
|
|
27
|
-
`;
|
|
28
|
-
|
|
29
|
-
const iconLegacyType = `interface LegacyIconifyIcon {
|
|
30
|
-
body: string;
|
|
31
|
-
left?: number;
|
|
32
|
-
top?: number;
|
|
33
|
-
width?: number;
|
|
34
|
-
height?: number;
|
|
35
|
-
rotate?: number;
|
|
36
|
-
hFlip?: boolean;
|
|
37
|
-
vFlip?: boolean;
|
|
38
|
-
// Legacy stuff
|
|
39
|
-
inlineTop?: number;
|
|
40
|
-
inlineHeight?: number;
|
|
41
|
-
verticalAlign?: number;
|
|
42
|
-
}
|
|
43
|
-
declare const data: LegacyIconifyIcon;
|
|
44
|
-
export default data;
|
|
45
|
-
`;
|
|
46
|
-
|
|
47
|
-
const legacyAttributes = ['inlineTop', 'inlineHeight', 'verticalAlign'];
|
|
48
|
-
|
|
49
|
-
const defaults = {
|
|
50
|
-
// True if .d.ts files should be exported
|
|
51
|
-
definitions: true,
|
|
52
|
-
|
|
53
|
-
// Export package.json, boolean or file name
|
|
54
|
-
package: true,
|
|
55
|
-
|
|
56
|
-
// Export README.md, boolean or file name
|
|
57
|
-
readme: true,
|
|
58
|
-
|
|
59
|
-
// CommonJS syntax
|
|
60
|
-
commonjs: true,
|
|
61
|
-
|
|
62
|
-
// Information for package.json and README.md:
|
|
63
|
-
// Package name
|
|
64
|
-
name: '@iconify/icons-{prefix}',
|
|
65
|
-
|
|
66
|
-
// Version number
|
|
67
|
-
version: null,
|
|
68
|
-
|
|
69
|
-
// Array of icon samples
|
|
70
|
-
samples: [],
|
|
71
|
-
|
|
72
|
-
// Collection information
|
|
73
|
-
info: null,
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const transformKeys = ['rotate', 'vFlip', 'hFlip'];
|
|
77
|
-
|
|
78
|
-
const positionAttributes = ['left', 'top'];
|
|
79
|
-
|
|
80
|
-
const inlineAttributes = ['inlineHeight', 'inlineTop', 'verticalAlign'];
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Convert icon name to camelCase with optional "Icon" suffix
|
|
84
|
-
*
|
|
85
|
-
* @param {string} name
|
|
86
|
-
* @return {string}
|
|
87
|
-
*/
|
|
88
|
-
const iconName = (name, addSuffix = true) => {
|
|
89
|
-
let parts = name.split(/[-:]/),
|
|
90
|
-
result = parts.shift();
|
|
91
|
-
|
|
92
|
-
if (name.charCodeAt(0) < 97 || name.charCodeAt(0) > 122) {
|
|
93
|
-
// Not a-z - add "icon" at start so variable doesn't start with invalid character
|
|
94
|
-
parts.unshift('icon');
|
|
95
|
-
} else if (parts.length < 1 && addSuffix) {
|
|
96
|
-
// Add "Icon" to avoid reserved keywords
|
|
97
|
-
parts.push('icon');
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
parts.forEach((part) => {
|
|
101
|
-
result += part.slice(0, 1).toUpperCase() + part.slice(1);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
return result;
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Export collection to js files
|
|
109
|
-
*
|
|
110
|
-
* @param {Collection} collection Collection to export
|
|
111
|
-
* @param {string} [dir] Target directory
|
|
112
|
-
* @param {object} [options] Options
|
|
113
|
-
* @returns {Promise}
|
|
114
|
-
*/
|
|
115
|
-
module.exports = (collection, dir, options) => {
|
|
116
|
-
return new Promise((fulfill, reject) => {
|
|
117
|
-
options = options === void 0 ? Object.create(null) : options;
|
|
118
|
-
Object.keys(defaults).forEach((key) => {
|
|
119
|
-
if (options[key] === void 0) {
|
|
120
|
-
options[key] = defaults[key];
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
let name =
|
|
125
|
-
options.info && options.info.name
|
|
126
|
-
? options.info.name
|
|
127
|
-
: collection.prefix,
|
|
128
|
-
packageName = options.name.replace('{prefix}', collection.prefix);
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Export package.json
|
|
132
|
-
*/
|
|
133
|
-
const exportPackage = () => {
|
|
134
|
-
let result = {
|
|
135
|
-
name: packageName,
|
|
136
|
-
description: 'Iconify icon components for ' + name,
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
if (typeof options.version === 'string') {
|
|
140
|
-
result.version = options.version;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (options.info) {
|
|
144
|
-
let infoBlock = {};
|
|
145
|
-
[
|
|
146
|
-
'name',
|
|
147
|
-
'version',
|
|
148
|
-
'author',
|
|
149
|
-
'url',
|
|
150
|
-
'license',
|
|
151
|
-
'licenseURL',
|
|
152
|
-
'palette',
|
|
153
|
-
].forEach((key) => {
|
|
154
|
-
if (options.info[key] !== void 0) {
|
|
155
|
-
infoBlock[key] = options.info[key];
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
if (Object.keys(infoBlock).length > 1) {
|
|
159
|
-
result.iconsSet = infoBlock;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
result.bugs = 'https://github.com/iconify/iconify/issues';
|
|
164
|
-
result.homepage = 'https://github.com/iconify/iconify';
|
|
165
|
-
|
|
166
|
-
fs.writeFileSync(
|
|
167
|
-
dir + '/package.json',
|
|
168
|
-
JSON.stringify(result, null, '\t'),
|
|
169
|
-
'utf8'
|
|
170
|
-
);
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Export README.md
|
|
175
|
-
*/
|
|
176
|
-
const exportReadme = () => {
|
|
177
|
-
const templatesDir = __dirname + '/templates';
|
|
178
|
-
const replacements = {
|
|
179
|
-
iconSetName: name,
|
|
180
|
-
packageName: packageName,
|
|
181
|
-
iconSetPrefix: collection.prefix,
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Replace all key/value pairs in text
|
|
186
|
-
*/
|
|
187
|
-
function replaceContent(content, replacements) {
|
|
188
|
-
(replacements instanceof Array ? replacements : [replacements]).forEach(
|
|
189
|
-
(list) => {
|
|
190
|
-
Object.keys(list).forEach((key) => {
|
|
191
|
-
const value = list[key];
|
|
192
|
-
|
|
193
|
-
let start = 0;
|
|
194
|
-
let pos;
|
|
195
|
-
|
|
196
|
-
while ((pos = content.indexOf(key, start)) !== -1) {
|
|
197
|
-
content =
|
|
198
|
-
content.slice(0, pos) +
|
|
199
|
-
value +
|
|
200
|
-
content.slice(pos + key.length);
|
|
201
|
-
start = pos + value.length;
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
);
|
|
206
|
-
return content;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// Find all language specific templates
|
|
210
|
-
const languages = [];
|
|
211
|
-
fs.readdirSync(templatesDir).forEach((file) => {
|
|
212
|
-
let parts = file.split('.');
|
|
213
|
-
if (parts.length !== 2 || parts.pop() !== 'md') {
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
parts = parts[0].split('-');
|
|
217
|
-
if (parts.shift() !== 'sample') {
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
const lang = parts.shift();
|
|
221
|
-
if (languages.indexOf(lang) === -1) {
|
|
222
|
-
languages.push(lang);
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
// Parse all languages
|
|
227
|
-
languages.forEach((lang) => {
|
|
228
|
-
const codeSamples = [];
|
|
229
|
-
options.samples.forEach((sample, index) => {
|
|
230
|
-
// Get sample name
|
|
231
|
-
let sampleReplacements = {
|
|
232
|
-
sampleFilename: sample,
|
|
233
|
-
sampleIconShortName: iconName(sample, false),
|
|
234
|
-
sampleIconName: iconName(sample),
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
// Get template
|
|
238
|
-
let content;
|
|
239
|
-
try {
|
|
240
|
-
content = fs.readFileSync(
|
|
241
|
-
`${templatesDir}/sample-${lang}-${index}.md`,
|
|
242
|
-
'utf8'
|
|
243
|
-
);
|
|
244
|
-
} catch (err) {
|
|
245
|
-
try {
|
|
246
|
-
content = fs.readFileSync(
|
|
247
|
-
`${templatesDir}/sample-${lang}.md`,
|
|
248
|
-
'utf8'
|
|
249
|
-
);
|
|
250
|
-
} catch (err) {
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// Replace content
|
|
256
|
-
content = replaceContent(content, [sampleReplacements, replacements]);
|
|
257
|
-
codeSamples.push(content.trim());
|
|
258
|
-
});
|
|
259
|
-
replacements['`samples.' + lang + '`'] = codeSamples.join('\n\n');
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
// Get content
|
|
263
|
-
let content = fs
|
|
264
|
-
.readFileSync(templatesDir + '/component.md', 'utf8')
|
|
265
|
-
.trim();
|
|
266
|
-
|
|
267
|
-
// Author information
|
|
268
|
-
if (
|
|
269
|
-
options.info &&
|
|
270
|
-
options.info.author !== void 0 &&
|
|
271
|
-
options.info.name !== void 0
|
|
272
|
-
) {
|
|
273
|
-
const phrases = {
|
|
274
|
-
author: 'Icons author: ',
|
|
275
|
-
url: 'Website: ',
|
|
276
|
-
license: 'License: ',
|
|
277
|
-
licenseURL: 'License URL: ',
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
const list = [];
|
|
281
|
-
|
|
282
|
-
// Author name and website
|
|
283
|
-
if (typeof options.info.author === 'object') {
|
|
284
|
-
const author = options.info.author;
|
|
285
|
-
if (typeof author.name === 'string') {
|
|
286
|
-
list.push(phrases.author + author.name);
|
|
287
|
-
if (typeof author.url === 'string') {
|
|
288
|
-
list.push(phrases.url + author.url);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
} else if (typeof options.info.author === 'string') {
|
|
292
|
-
list.push(phrases.author + options.info.author);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
// License
|
|
296
|
-
if (typeof options.info.license === 'object') {
|
|
297
|
-
const license = options.info.license;
|
|
298
|
-
if (typeof license.title === 'string') {
|
|
299
|
-
list.push(phrases.license + license.title);
|
|
300
|
-
if (typeof license.url === 'string') {
|
|
301
|
-
list.push(phrases.licenseURL + license.url);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
} else if (typeof options.info.license === 'string') {
|
|
305
|
-
list.push(phrases.license + options.info.license);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
if (list.length) {
|
|
309
|
-
const infoReplacements = {
|
|
310
|
-
iconSetInfo: list.join('\n\n'),
|
|
311
|
-
};
|
|
312
|
-
|
|
313
|
-
let info = fs.readFileSync(templatesDir + '/info.md', 'utf8');
|
|
314
|
-
content += '\n\n' + replaceContent(info, infoReplacements).trim();
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
// Replace content
|
|
319
|
-
content = replaceContent(content, replacements) + '\n';
|
|
320
|
-
|
|
321
|
-
// Check if there are missing samples
|
|
322
|
-
if (content.indexOf('`samples.') !== -1) {
|
|
323
|
-
throw new Error('Did not replace all samples in generated README.md');
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
fs.writeFileSync(dir + '/README.md', content, 'utf8');
|
|
327
|
-
};
|
|
328
|
-
|
|
329
|
-
/**
|
|
330
|
-
* Export typescript file
|
|
331
|
-
*
|
|
332
|
-
* @param {string} filename
|
|
333
|
-
* @param {boolean} isLegacy
|
|
334
|
-
*/
|
|
335
|
-
const exportTS = (filename, isLegacy = false) => {
|
|
336
|
-
fs.writeFileSync(
|
|
337
|
-
filename + '.d.ts',
|
|
338
|
-
isLegacy ? iconLegacyType : iconType
|
|
339
|
-
);
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
/**
|
|
343
|
-
* Export icon
|
|
344
|
-
*
|
|
345
|
-
* @param {string} name
|
|
346
|
-
* @param {object} data
|
|
347
|
-
*/
|
|
348
|
-
const exportIcon = (name, data) => {
|
|
349
|
-
let content = JSON.stringify(data, null, '\t'),
|
|
350
|
-
code;
|
|
351
|
-
|
|
352
|
-
// Check if data has legacy attributes
|
|
353
|
-
let isLegacy = false;
|
|
354
|
-
if (options.definitions) {
|
|
355
|
-
legacyAttributes.forEach((attr) => {
|
|
356
|
-
if (data[attr] !== void 0) {
|
|
357
|
-
isLegacy = true;
|
|
358
|
-
}
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
// Save files
|
|
363
|
-
code = 'var data = ' + content + ';\n';
|
|
364
|
-
if (options.commonjs) {
|
|
365
|
-
code += 'exports.__esModule = true;\nexports.default = data;\n';
|
|
366
|
-
} else {
|
|
367
|
-
code += 'export default data;\n';
|
|
368
|
-
}
|
|
369
|
-
fs.writeFileSync(dir + '/' + name + '.js', code, 'utf8');
|
|
370
|
-
if (options.definitions) {
|
|
371
|
-
exportTS(dir + '/' + name, isLegacy);
|
|
372
|
-
}
|
|
373
|
-
};
|
|
374
|
-
|
|
375
|
-
// Prepare output directory
|
|
376
|
-
helpers.mkdir(dir);
|
|
377
|
-
|
|
378
|
-
// Get samples
|
|
379
|
-
let samples = options.samples instanceof Array ? options.samples : [];
|
|
380
|
-
if (samples.length < 3) {
|
|
381
|
-
let icons = collection.keys(false);
|
|
382
|
-
for (let i = 0; i < 3; i++) {
|
|
383
|
-
samples[i] =
|
|
384
|
-
samples[i] === void 0
|
|
385
|
-
? icons[Math.floor((icons.length / 4) * (i + 1))]
|
|
386
|
-
: samples[i];
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
// Export all icons
|
|
391
|
-
collection.forEach((svg, key, prefix) => {
|
|
392
|
-
let json = {
|
|
393
|
-
body: svg.getBody().replace(/\s*\n\s*/g, ''),
|
|
394
|
-
width: svg.width,
|
|
395
|
-
height: svg.height,
|
|
396
|
-
};
|
|
397
|
-
|
|
398
|
-
// Add left/top
|
|
399
|
-
positionAttributes.forEach((attr) => {
|
|
400
|
-
if (svg[attr] !== 0) {
|
|
401
|
-
json[attr] = svg[attr];
|
|
402
|
-
}
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
// Add transformations
|
|
406
|
-
transformKeys.forEach((attr) => {
|
|
407
|
-
if (svg[attr] !== void 0) {
|
|
408
|
-
json[attr] = svg[attr];
|
|
409
|
-
}
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
// Include inline attributes
|
|
413
|
-
if (options.includeInline) {
|
|
414
|
-
inlineAttributes.forEach((attr) => {
|
|
415
|
-
if (svg[attr] !== void 0) {
|
|
416
|
-
json[attr] = svg[attr];
|
|
417
|
-
}
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
exportIcon(key, json);
|
|
422
|
-
|
|
423
|
-
// Export aliases
|
|
424
|
-
(svg.aliases ? svg.aliases : []).forEach((alias) => {
|
|
425
|
-
switch (typeof alias) {
|
|
426
|
-
case 'string':
|
|
427
|
-
if (collection.items[alias] === void 0) {
|
|
428
|
-
exportIcon(alias, json);
|
|
429
|
-
}
|
|
430
|
-
return;
|
|
431
|
-
|
|
432
|
-
case 'object':
|
|
433
|
-
if (
|
|
434
|
-
alias.name === void 0 ||
|
|
435
|
-
collection.items[alias.name] !== void 0
|
|
436
|
-
) {
|
|
437
|
-
return;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
let data = Object.assign({}, json);
|
|
441
|
-
|
|
442
|
-
transformKeys.forEach((key) => {
|
|
443
|
-
if (alias[key] === void 0) {
|
|
444
|
-
return;
|
|
445
|
-
}
|
|
446
|
-
if (data[key] === void 0) {
|
|
447
|
-
data[key] = alias[key];
|
|
448
|
-
return;
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
let value = data[key];
|
|
452
|
-
switch (key) {
|
|
453
|
-
case 'rotate':
|
|
454
|
-
value = (value + alias[key]) % 4;
|
|
455
|
-
break;
|
|
456
|
-
|
|
457
|
-
default:
|
|
458
|
-
value = value !== alias[key];
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
if (!value) {
|
|
462
|
-
delete data[key];
|
|
463
|
-
} else {
|
|
464
|
-
data[key] = value;
|
|
465
|
-
}
|
|
466
|
-
});
|
|
467
|
-
exportIcon(alias.name, data);
|
|
468
|
-
}
|
|
469
|
-
});
|
|
470
|
-
});
|
|
471
|
-
|
|
472
|
-
if (options.package) {
|
|
473
|
-
exportPackage();
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
if (options.readme) {
|
|
477
|
-
exportReadme();
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
fulfill(collection);
|
|
481
|
-
});
|
|
482
|
-
};
|
package/src/export/dir.js
DELETED
|
@@ -1,109 +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 Exporter = require('./svg');
|
|
14
|
-
|
|
15
|
-
const defaults = {
|
|
16
|
-
// Function to generate filename for icon
|
|
17
|
-
exportFilename: exportFilename,
|
|
18
|
-
|
|
19
|
-
// True if prefix should be included in filename
|
|
20
|
-
includePrefix: true,
|
|
21
|
-
|
|
22
|
-
// true: prefix/icon.svg, false: prefix-icon.svg
|
|
23
|
-
prefixAsDirectory: false,
|
|
24
|
-
|
|
25
|
-
// Custom prefix string to override collection prefix. False if none
|
|
26
|
-
customPrefix: false,
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Generate filename
|
|
31
|
-
*
|
|
32
|
-
* @param {string} key
|
|
33
|
-
* @param {string} prefix
|
|
34
|
-
* @param {object} options
|
|
35
|
-
* @returns {string}
|
|
36
|
-
*/
|
|
37
|
-
function exportFilename(key, prefix, options) {
|
|
38
|
-
if (prefix === '') {
|
|
39
|
-
// Check for complex prefix
|
|
40
|
-
let list = key.split(':');
|
|
41
|
-
if (list.length === 2) {
|
|
42
|
-
prefix = list[0];
|
|
43
|
-
key = list[1];
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return (
|
|
48
|
-
(options.includePrefix && prefix !== ''
|
|
49
|
-
? options.prefixAsDirectory
|
|
50
|
-
? prefix + '/'
|
|
51
|
-
: prefix + '-'
|
|
52
|
-
: '') +
|
|
53
|
-
key +
|
|
54
|
-
'.svg'
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Export collection to directory
|
|
60
|
-
*
|
|
61
|
-
* @returns {Promise}
|
|
62
|
-
*/
|
|
63
|
-
module.exports = (collection, target, options) => {
|
|
64
|
-
options = options === void 0 ? Object.create(null) : options;
|
|
65
|
-
Object.keys(defaults).forEach(key => {
|
|
66
|
-
if (options[key] === void 0) {
|
|
67
|
-
options[key] = defaults[key];
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
return new Promise((fulfill, reject) => {
|
|
72
|
-
if (target.slice(-1) === '/') {
|
|
73
|
-
target = target.slice(0, target.length - 1);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Export all files
|
|
77
|
-
Promise.all(
|
|
78
|
-
collection.keys(false).map(key =>
|
|
79
|
-
Exporter(
|
|
80
|
-
collection.items[key],
|
|
81
|
-
target +
|
|
82
|
-
'/' +
|
|
83
|
-
options.exportFilename(
|
|
84
|
-
key,
|
|
85
|
-
options.customPrefix === false
|
|
86
|
-
? collection.prefix
|
|
87
|
-
: options.customPrefix,
|
|
88
|
-
options
|
|
89
|
-
),
|
|
90
|
-
{
|
|
91
|
-
reject: false,
|
|
92
|
-
}
|
|
93
|
-
)
|
|
94
|
-
)
|
|
95
|
-
)
|
|
96
|
-
.then(results => {
|
|
97
|
-
let count = 0;
|
|
98
|
-
results.forEach(result => {
|
|
99
|
-
if (result !== null) {
|
|
100
|
-
count++;
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
fulfill(count);
|
|
104
|
-
})
|
|
105
|
-
.catch(err => {
|
|
106
|
-
reject();
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
};
|