@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.
Files changed (147) hide show
  1. package/.editorconfig +13 -0
  2. package/.eslintignore +2 -0
  3. package/lib/colors/attribs.d.ts +16 -0
  4. package/lib/colors/attribs.js +26 -0
  5. package/lib/colors/attribs.mjs +28 -0
  6. package/lib/colors/parse.d.ts +37 -0
  7. package/lib/colors/parse.js +261 -0
  8. package/lib/colors/parse.mjs +212 -0
  9. package/lib/css/parse.d.ts +4 -0
  10. package/lib/css/parse.js +23 -0
  11. package/lib/css/parse.mjs +20 -0
  12. package/lib/css/parser/error.d.ts +11 -0
  13. package/lib/css/parser/error.js +27 -0
  14. package/lib/css/parser/error.mjs +23 -0
  15. package/lib/css/parser/export.d.ts +5 -0
  16. package/lib/css/parser/export.js +69 -0
  17. package/lib/css/parser/export.mjs +46 -0
  18. package/lib/css/parser/strings.d.ts +13 -0
  19. package/lib/css/parser/strings.js +93 -0
  20. package/lib/css/parser/strings.mjs +74 -0
  21. package/lib/css/parser/text.d.ts +17 -0
  22. package/lib/css/parser/text.js +174 -0
  23. package/lib/css/parser/text.mjs +133 -0
  24. package/lib/css/parser/tokens.d.ts +6 -0
  25. package/lib/css/parser/tokens.js +200 -0
  26. package/lib/css/parser/tokens.mjs +186 -0
  27. package/lib/css/parser/tree.d.ts +5 -0
  28. package/lib/css/parser/tree.js +44 -0
  29. package/lib/css/parser/tree.mjs +40 -0
  30. package/lib/css/parser/types.d.ts +51 -0
  31. package/lib/css/parser/types.js +2 -0
  32. package/lib/css/parser/types.mjs +0 -0
  33. package/lib/icon-set/index.d.ts +134 -0
  34. package/lib/icon-set/index.js +776 -0
  35. package/lib/icon-set/index.mjs +617 -0
  36. package/lib/icon-set/match.d.ts +6 -0
  37. package/lib/icon-set/match.js +66 -0
  38. package/lib/icon-set/match.mjs +55 -0
  39. package/lib/icon-set/merge.d.ts +5 -0
  40. package/lib/icon-set/merge.js +91 -0
  41. package/lib/icon-set/merge.mjs +75 -0
  42. package/lib/icon-set/props.d.ts +10 -0
  43. package/lib/icon-set/props.js +33 -0
  44. package/lib/icon-set/props.mjs +25 -0
  45. package/lib/icon-set/types.d.ts +68 -0
  46. package/lib/icon-set/types.js +2 -0
  47. package/lib/icon-set/types.mjs +0 -0
  48. package/lib/import/directory.d.ts +35 -0
  49. package/lib/import/directory.js +59 -0
  50. package/lib/import/directory.mjs +47 -0
  51. package/lib/misc/keyword.d.ts +4 -0
  52. package/lib/misc/keyword.js +31 -0
  53. package/lib/misc/keyword.mjs +17 -0
  54. package/lib/misc/scan.d.ts +24 -0
  55. package/lib/misc/scan.js +48 -0
  56. package/lib/misc/scan.mjs +43 -0
  57. package/lib/optimise/flags.d.ts +5 -0
  58. package/lib/optimise/flags.js +303 -0
  59. package/lib/optimise/flags.mjs +241 -0
  60. package/lib/optimise/scale.d.ts +5 -0
  61. package/lib/optimise/scale.js +42 -0
  62. package/lib/optimise/scale.mjs +22 -0
  63. package/lib/optimise/svgo.d.ts +27 -0
  64. package/lib/optimise/svgo.js +88 -0
  65. package/lib/optimise/svgo.mjs +75 -0
  66. package/lib/svg/cleanup/attribs.d.ts +5 -0
  67. package/lib/svg/cleanup/attribs.js +43 -0
  68. package/lib/svg/cleanup/attribs.mjs +36 -0
  69. package/lib/svg/cleanup/bad-tags.d.ts +5 -0
  70. package/lib/svg/cleanup/bad-tags.js +69 -0
  71. package/lib/svg/cleanup/bad-tags.mjs +68 -0
  72. package/lib/svg/cleanup/inline-style.d.ts +5 -0
  73. package/lib/svg/cleanup/inline-style.js +77 -0
  74. package/lib/svg/cleanup/inline-style.mjs +65 -0
  75. package/lib/svg/cleanup/root-svg.d.ts +5 -0
  76. package/lib/svg/cleanup/root-svg.js +106 -0
  77. package/lib/svg/cleanup/root-svg.mjs +88 -0
  78. package/lib/svg/cleanup/svgo-style.d.ts +5 -0
  79. package/lib/svg/cleanup/svgo-style.js +35 -0
  80. package/lib/svg/cleanup/svgo-style.mjs +29 -0
  81. package/lib/svg/cleanup.d.ts +5 -0
  82. package/lib/svg/cleanup.js +24 -0
  83. package/lib/svg/cleanup.mjs +16 -0
  84. package/lib/svg/data/attributes.d.ts +71 -0
  85. package/lib/svg/data/attributes.js +403 -0
  86. package/lib/svg/data/attributes.mjs +352 -0
  87. package/lib/svg/data/tags.d.ts +89 -0
  88. package/lib/svg/data/tags.js +185 -0
  89. package/lib/svg/data/tags.mjs +136 -0
  90. package/lib/svg/index.d.ts +33 -0
  91. package/lib/svg/index.js +122 -0
  92. package/lib/svg/index.mjs +85 -0
  93. package/lib/svg/parse-style.d.ts +40 -0
  94. package/lib/svg/parse-style.js +131 -0
  95. package/lib/svg/parse-style.mjs +109 -0
  96. package/lib/svg/parse.d.ts +30 -0
  97. package/lib/svg/parse.js +49 -0
  98. package/lib/svg/parse.mjs +40 -0
  99. package/package.json +167 -13
  100. package/README.md +0 -576
  101. package/license.txt +0 -21
  102. package/sample/parse.js +0 -74
  103. package/sample/source/icon-close.svg +0 -15
  104. package/sample/source/icon-confirm.svg +0 -14
  105. package/sample/source/icon-search.svg +0 -16
  106. package/src/collection.js +0 -641
  107. package/src/colors/change_palette.js +0 -227
  108. package/src/colors/get_palette.js +0 -143
  109. package/src/colors/opacify.js +0 -195
  110. package/src/export/component.js +0 -482
  111. package/src/export/dir.js +0 -109
  112. package/src/export/json.js +0 -329
  113. package/src/export/phantomjs.js +0 -76
  114. package/src/export/phantomjs_script.js +0 -125
  115. package/src/export/png.js +0 -193
  116. package/src/export/svg.js +0 -55
  117. package/src/export/templates/component.md +0 -79
  118. package/src/export/templates/info.md +0 -3
  119. package/src/export/templates/sample-react-1.md +0 -21
  120. package/src/export/templates/sample-react-2.md +0 -15
  121. package/src/export/templates/sample-react.md +0 -11
  122. package/src/export/templates/sample-svelte.md +0 -11
  123. package/src/export/templates/sample-svelte1.md +0 -22
  124. package/src/export/templates/sample-svelte2.md +0 -13
  125. package/src/export/templates/sample-vue-0.md +0 -30
  126. package/src/export/templates/sample-vue-1.md +0 -25
  127. package/src/export/templates/sample-vue-2.md +0 -27
  128. package/src/export/templates/sample-vue.md +0 -28
  129. package/src/helpers.js +0 -43
  130. package/src/import/dir.js +0 -234
  131. package/src/import/font.js +0 -402
  132. package/src/import/json.js +0 -200
  133. package/src/import/svg.js +0 -60
  134. package/src/import/web_icons.js +0 -248
  135. package/src/modules.js +0 -50
  136. package/src/optimize/crop.js +0 -554
  137. package/src/optimize/crop_script.js +0 -525
  138. package/src/optimize/flags.js +0 -430
  139. package/src/optimize/scale.js +0 -72
  140. package/src/optimize/svgo.js +0 -161
  141. package/src/optimize/tags.js +0 -522
  142. package/src/shapes/convert.js +0 -264
  143. package/src/shapes/index.js +0 -135
  144. package/src/shapes/length.js +0 -707
  145. package/src/shapes/length_script.js +0 -105
  146. package/src/shapes/options.js +0 -60
  147. package/src/svg.js +0 -162
@@ -1,248 +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 cheerio = require('cheerio');
14
- const SVGImporter = require('./svg');
15
- const SVG = require('../svg');
16
- const Collection = require('../collection');
17
- const Crop = require('../optimize/crop');
18
-
19
- const defaults = {
20
- prefix: '',
21
- keywordCallback: (key, options) =>
22
- key
23
- .toLowerCase()
24
- .replace(/_/g, '-')
25
- .replace(/[^a-zA-Z0-9\-_]/g, '')
26
- .replace(/--*/, '-'),
27
- crop: null,
28
- headless: true,
29
- minify: true,
30
- debug: false,
31
- log: console.log,
32
- };
33
-
34
- function load(source, options) {
35
- return new Promise((fulfill, reject) => {
36
- // Check if source is object
37
- if (source instanceof SVG) {
38
- fulfill(source);
39
- return;
40
- }
41
-
42
- // Source is string?
43
- if (typeof source === 'string') {
44
- // Is it svg file
45
- if (source.trim().slice(0, 1) === '<') {
46
- let svg = new SVG(source);
47
- fulfill(svg);
48
- return;
49
- }
50
-
51
- // filename
52
- SVGImporter(source, options)
53
- .then(svg => {
54
- fulfill(svg);
55
- })
56
- .catch(err => {
57
- reject(err);
58
- });
59
- return;
60
- }
61
-
62
- reject('Invalid source');
63
- });
64
- }
65
-
66
- /**
67
- * Import icons from web icon svg
68
- */
69
- module.exports = (source, options) => {
70
- options = options === void 0 ? Object.create(null) : options;
71
- Object.keys(defaults).forEach(key => {
72
- if (options[key] === void 0) {
73
- options[key] = defaults[key];
74
- }
75
- });
76
-
77
- return new Promise((fulfill, reject) => {
78
- load(source, options)
79
- .then(svg => {
80
- let $root = svg.$svg(':root');
81
- if ($root.length > 1 || $root.get(0).tagName !== 'svg') {
82
- return reject('Missing SVG element');
83
- }
84
-
85
- let $defs = $root.children('defs');
86
-
87
- if (!$defs.length) {
88
- return reject('Missing definitions');
89
- }
90
-
91
- let collection = new Collection(options.prefix);
92
-
93
- // Check each symbol
94
- $defs.children('symbol').each((index, symbol) => {
95
- let $symbol = cheerio(symbol),
96
- symbolAttributes = symbol.attribs;
97
-
98
- if (!symbolAttributes.id) {
99
- return;
100
- }
101
- let id = symbolAttributes.id;
102
-
103
- // Get dimensions
104
- let width = false,
105
- height = false,
106
- left = 0,
107
- top = 0;
108
-
109
- if (symbolAttributes.width !== void 0) {
110
- width = parseFloat(symbolAttributes.width);
111
- }
112
- if (symbolAttributes.height !== void 0) {
113
- height = parseFloat(symbolAttributes.height);
114
- }
115
- if (symbolAttributes.viewBox !== void 0) {
116
- let list = symbolAttributes.viewBox.split(' ');
117
- if (list.length === 4) {
118
- list = list.map(item => parseFloat(item));
119
- left = list[0];
120
- top = list[1];
121
- width = list[2];
122
- height = list[3];
123
- }
124
- }
125
- if (!width || !height) {
126
- if (options.debug) {
127
- options.log('Invalid dimensions for symbol ' + id);
128
- }
129
- return;
130
- }
131
- // Generate SVG
132
- let svg =
133
- '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="' +
134
- width +
135
- '" height="' +
136
- height +
137
- '" viewBox="' +
138
- left +
139
- ' ' +
140
- top +
141
- ' ' +
142
- width +
143
- ' ' +
144
- height +
145
- '">' +
146
- $symbol.html() +
147
- '</svg>';
148
-
149
- // Get keyword
150
- let keyword = options.keywordCallback(id, options);
151
- if (keyword === false || keyword === '') {
152
- return;
153
- }
154
-
155
- // Check for duplicate keyword
156
- if (collection.items[keyword] !== void 0) {
157
- options.log('Duplicate entry for ' + keyword);
158
- return;
159
- }
160
-
161
- try {
162
- let content = new SVG(svg);
163
- collection.add(keyword, content);
164
- } catch (err) {}
165
- });
166
-
167
- // Loaded
168
- if (!collection.length()) {
169
- reject('No images found.');
170
- return;
171
- }
172
- if (options.crop === null) {
173
- fulfill(collection);
174
- return;
175
- }
176
-
177
- // Crop like SVG font
178
- let rejected = false;
179
- ['ascent', 'descent'].forEach(attr => {
180
- if (!rejected && options.crop[attr] === void 0) {
181
- reject('Missing crop option: ' + attr);
182
- rejected = true;
183
- }
184
- });
185
- if (rejected) {
186
- return;
187
- }
188
-
189
- let cropQueue = [];
190
- let verticalAlign =
191
- options.crop.verticalAlign === void 0
192
- ? Math.round(
193
- (options.crop.descent /
194
- (options.crop.ascent - options.crop.descent)) *
195
- 1000
196
- ) / 1000
197
- : options.crop.verticalAlign;
198
- collection.forEach((svg, key) => {
199
- cropQueue[key] = {
200
- body: svg.getBody(),
201
- ascent: options.crop.ascent,
202
- descent: options.crop.descent,
203
- width: svg.width,
204
- originalHeight: svg.height,
205
- verticalAlign: verticalAlign,
206
- };
207
- ['width', 'originalHeight'].forEach(attr => {
208
- if (options.crop[attr] !== void 0) {
209
- cropQueue[key][attr] = options.crop[attr];
210
- }
211
- });
212
- });
213
-
214
- let cropOptions = Object.assign(
215
- {
216
- defaultRightLimit: false,
217
- defaultLeftLimit: false,
218
- },
219
- options.crop
220
- );
221
-
222
- cropOptions.multiple = true;
223
- cropOptions.format = 'svg';
224
-
225
- Crop(cropQueue, cropOptions)
226
- .then(results => {
227
- Object.keys(results).forEach(key => {
228
- let svg = results[key];
229
-
230
- // top > 0 - something was cropped above icon
231
- svg.inlineTop =
232
- svg._cropData.top <= 0 ? 0 : 0 - svg._cropData.top;
233
- svg.inlineHeight = cropQueue[key].originalHeight;
234
- svg.verticalAlign = cropQueue[key].verticalAlign;
235
-
236
- collection.items[key] = svg;
237
- });
238
- fulfill(collection);
239
- })
240
- .catch(err => {
241
- reject(err);
242
- });
243
- })
244
- .catch(err => {
245
- reject(err);
246
- });
247
- });
248
- };
package/src/modules.js DELETED
@@ -1,50 +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
- let Modules = {
13
- // Core
14
- SVG: require('./svg'),
15
- Collection: require('./collection'),
16
-
17
- // Optimizations
18
- SVGO: require('./optimize/svgo'),
19
- Tags: require('./optimize/tags'),
20
- Crop: require('./optimize/crop'),
21
-
22
- // Colors
23
- GetPalette: require('./colors/get_palette'),
24
- ChangePalette: require('./colors/change_palette'),
25
- Opacify: require('./colors/opacify'),
26
-
27
- // Export
28
- ExportSVG: require('./export/svg'),
29
- ExportDir: require('./export/dir'),
30
- ExportJSON: require('./export/json'),
31
- ExportComponent: require('./export/component'),
32
- ExportPNG: require('./export/png'),
33
-
34
- // Import
35
- ImportSVG: require('./import/svg'),
36
- ImportDir: require('./import/dir'),
37
- ImportFont: require('./import/font'),
38
- ImportWebIcon: require('./import/web_icons'),
39
- ImportJSON: require('./import/json'),
40
-
41
- // Shapes
42
- IndexShapes: require('./shapes/index'),
43
- ShapeLengths: require('./shapes/length'),
44
- ConvertShapes: require('./shapes/convert'),
45
-
46
- // Misc
47
- Scale: require('./optimize/scale'),
48
- };
49
-
50
- module.exports = Modules;