@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,264 +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 kappa = 0.5522847498307935;
13
-
14
- /**
15
- * Functions for converting shapes to path.
16
- *
17
- * All functions assume that attributes are valid.
18
- * Check attributes before calling functions or bad things might happen.
19
- *
20
- * @type {object}
21
- */
22
- let convert = Object.create(null);
23
-
24
- /**
25
- * Convert rectangle to path
26
- *
27
- * @param {{x, y, width, height, rx, ry}} attr
28
- */
29
- convert.rect = attr => {
30
- let path;
31
-
32
- if (attr.rx === 0 && attr.ry === 0) {
33
- // Move to left, top
34
- path = 'M ' + attr.x + ' ' + attr.y + ' ';
35
- // Horizontal line
36
- path += 'H ' + (attr.x + attr.width) + ' ';
37
- // Vertical line
38
- path += 'V ' + (attr.y + attr.height) + ' ';
39
- // Horizontal line
40
- path += 'H ' + attr.x + ' ';
41
- // Vertical line
42
- path += 'V ' + attr.y + ' ';
43
- // Close path
44
- path += 'Z';
45
- } else {
46
- let right = attr.x + attr.width,
47
- bottom = attr.y + attr.height;
48
-
49
- // Using quadratic Bezier curve commands
50
- /*
51
- // Move to left + arc width, top
52
- path = 'M ' + (attr.x + attr.rx) + ' ' + attr.y + ' ';
53
- // Horizontal line to right - arc width, top
54
- path += 'H ' + (attr.x + attr.width - attr.rx) + ' ';
55
- // Arc
56
- path += 'Q ' + right + ' ' + attr.y + ' ' + right + ' ' + (attr.y + attr.ry) + ' ';
57
- // Vertical line to right, bottom - arc height
58
- path += 'V ' + (attr.y + attr.height - attr.ry) + ' ';
59
- // Arc
60
- path += 'Q ' + right + ' ' + bottom + ' ' + (right - attr.rx) + ' ' + bottom + ' ';
61
- // Horizontal line to left + arc width, bottom
62
- path += 'H ' + (attr.x + attr.rx) + ' ';
63
- // Arc
64
- path += 'Q ' + attr.x + ' ' + bottom + ' ' + attr.x + ' ' + (bottom - attr.ry) + ' ';
65
- // Vertical line to left, top + arc height
66
- path += 'V ' + (attr.y + attr.ry) + ' ';
67
- // Arc
68
- path += 'Q ' + attr.x + ' ' + attr.y + ' ' + (attr.x + attr.rx) + ' ' + attr.y + ' ';
69
- // Close path
70
- path += 'Z';
71
- */
72
-
73
- // Using cubic Bezier curve commands
74
- let dx = attr.rx * kappa,
75
- dy = attr.ry * kappa;
76
-
77
- // Move to left + arc width, top
78
- path = 'M ' + (attr.x + attr.rx) + ' ' + attr.y + ' ';
79
- // Horizontal line to right - arc width, top
80
- path += 'H ' + (right - attr.rx) + ' ';
81
- // First arc
82
- path +=
83
- 'c ' +
84
- dx +
85
- ' 0 ' +
86
- attr.rx +
87
- ' ' +
88
- (attr.ry - dy) +
89
- ' ' +
90
- attr.rx +
91
- ' ' +
92
- attr.ry +
93
- ' ';
94
- // Vertical line to right, bottom - arc height
95
- path += 'V ' + (bottom - attr.ry) + ' ';
96
- // Second arc
97
- path +=
98
- 'c 0 ' +
99
- dy +
100
- ' ' +
101
- (0 - attr.rx + dx) +
102
- ' ' +
103
- attr.ry +
104
- ' ' +
105
- (0 - attr.rx) +
106
- ' ' +
107
- attr.ry +
108
- ' ';
109
- // Horizontal line to left + arc width, bottom
110
- path += 'H ' + (attr.x + attr.rx) + ' ';
111
- // Third arc
112
- path +=
113
- 'c ' +
114
- (0 - dx) +
115
- ' 0 ' +
116
- (0 - attr.rx) +
117
- ' ' +
118
- (0 - attr.ry + dy) +
119
- ' ' +
120
- (0 - attr.rx) +
121
- ' ' +
122
- (0 - attr.ry) +
123
- ' ';
124
- // Vertical line to left, top + arc height
125
- path += 'V ' + (attr.y + attr.ry) + ' ';
126
- // Fourth arc
127
- path +=
128
- 'c 0 ' +
129
- (0 - dy) +
130
- ' ' +
131
- (attr.rx - dx) +
132
- ' ' +
133
- (0 - attr.ry) +
134
- ' ' +
135
- attr.rx +
136
- ' ' +
137
- (0 - attr.ry) +
138
- ' ';
139
- // Close path
140
- path += 'Z';
141
- }
142
-
143
- return path;
144
- };
145
-
146
- /**
147
- * Convert ellipse to path
148
- *
149
- * @param {{cx, cy, rx, ry}} attr
150
- */
151
- convert.ellipse = attr => {
152
- let dx = attr.rx * kappa,
153
- dy = attr.ry * kappa,
154
- path;
155
-
156
- // Move to top
157
- path = 'M ' + attr.cx + ' ' + (attr.cy - attr.ry) + ' ';
158
- // First arc
159
- path +=
160
- 'C ' +
161
- (attr.cx + dx) +
162
- ' ' +
163
- (attr.cy - attr.ry) +
164
- ' ' +
165
- (attr.cx + attr.rx) +
166
- ' ' +
167
- (attr.cy - dy) +
168
- ' ' +
169
- (attr.cx + attr.rx) +
170
- ' ' +
171
- attr.cy +
172
- ' ';
173
- // Second arc
174
- path +=
175
- 'C ' +
176
- (attr.cx + attr.rx) +
177
- ' ' +
178
- (attr.cy + dy) +
179
- ' ' +
180
- (attr.cx + dx) +
181
- ' ' +
182
- (attr.cy + attr.ry) +
183
- ' ' +
184
- attr.cx +
185
- ' ' +
186
- (attr.cy + attr.ry) +
187
- ' ';
188
- // Third arc
189
- path +=
190
- 'C ' +
191
- (attr.cx - dx) +
192
- ' ' +
193
- (attr.cy + attr.ry) +
194
- ' ' +
195
- (attr.cx - attr.rx) +
196
- ' ' +
197
- (attr.cy + dy) +
198
- ' ' +
199
- (attr.cx - attr.rx) +
200
- ' ' +
201
- attr.cy +
202
- ' ';
203
- // Fourth arc
204
- path +=
205
- 'C ' +
206
- (attr.cx - attr.rx) +
207
- ' ' +
208
- (attr.cy - dy) +
209
- ' ' +
210
- (attr.cx - dx) +
211
- ' ' +
212
- (attr.cy - attr.ry) +
213
- ' ' +
214
- attr.cx +
215
- ' ' +
216
- (attr.cy - attr.ry) +
217
- ' ';
218
- // Close path
219
- path += 'Z';
220
-
221
- return path;
222
- };
223
-
224
- /**
225
- * Convert circle to path
226
- *
227
- * @param {{cx, cy, r}} attr
228
- */
229
- convert.circle = attr => {
230
- return convert.ellipse({
231
- cx: attr.cx,
232
- cy: attr.cy,
233
- rx: attr.r,
234
- ry: attr.r,
235
- });
236
- };
237
-
238
- /**
239
- * Convert polyline to path
240
- *
241
- * @param {{points}} attr
242
- */
243
- convert.polyline = attr => {
244
- let points =
245
- typeof attr.points === 'string' ? attr.points.split(/\s+/) : attr.points,
246
- path = '';
247
-
248
- points.forEach((point, index) => {
249
- path += (index ? 'L ' : 'M ') + point.replace(',', ' ') + ' ';
250
- });
251
-
252
- return path.trim();
253
- };
254
-
255
- /**
256
- * Convert polygon to path
257
- *
258
- * @param {{points}} attr
259
- */
260
- convert.polygon = attr => {
261
- return convert.polyline(attr) + ' Z';
262
- };
263
-
264
- module.exports = convert;
@@ -1,135 +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 cheerio = require('cheerio');
13
- const changeOptions = require('./options');
14
-
15
- /**
16
- * Default options. See also ./options.js
17
- *
18
- * @type {object}
19
- */
20
- const defaults = {
21
- // True if nodes should be returned instead of number of nodes
22
- returnNodes: false,
23
-
24
- // True if shapes should be checked for fill/stroke. Works only if shapeCallback is set.
25
- // fill/stroke properties are added to callback argument. Value is false if disabled, string if set
26
- checkFillStroke: false,
27
- };
28
-
29
- /**
30
- * Add shape index to tags
31
- *
32
- * Must run SVGO optimization before using this module!
33
- *
34
- * @param {SVG} svg SVG object
35
- * @param {object} options Options
36
- * @return {Promise}
37
- */
38
- module.exports = (svg, options) => {
39
- return new Promise((fulfill, reject) => {
40
- options = options === void 0 ? Object.create(null) : options;
41
- changeOptions(options, defaults);
42
-
43
- let $root = svg.$svg(':root'),
44
- shapeIndex = options.shapeStartIndex,
45
- total = 0,
46
- nodes = [];
47
-
48
- function checkChildElements($node, style) {
49
- $node.children().each((index, child) => {
50
- let $child = cheerio(child),
51
- tag = child.tagName;
52
-
53
- if (options.ignoreTags.indexOf(tag) !== -1) {
54
- return;
55
- }
56
-
57
- // Merge fill/stroke
58
- let childStyle;
59
- if (options.checkFillStroke) {
60
- childStyle = Object.create(null);
61
- ['fill', 'stroke'].forEach(attr => {
62
- if (child.attribs && child.attribs[attr] !== void 0) {
63
- let value = child.attribs[attr].toLowerCase();
64
- childStyle[attr] =
65
- value === '' || value === 'inherit'
66
- ? style[attr]
67
- : value === 'none'
68
- ? false
69
- : child.attribs[attr];
70
- } else {
71
- childStyle[attr] = style[attr];
72
- }
73
- });
74
- } else {
75
- childStyle = style;
76
- }
77
-
78
- // Check if item is a shape
79
- if (options.shapeTags.indexOf(tag) !== -1) {
80
- // Callback should add/remove attributes
81
- let callbackData;
82
- if (options.shapeCallback !== null) {
83
- callbackData = {
84
- $node: $child,
85
- node: child,
86
- svg: svg,
87
- index: shapeIndex,
88
- tag: tag,
89
- options: options,
90
- };
91
- if (options.checkFillStroke) {
92
- callbackData.fill = childStyle.fill;
93
- callbackData.stroke = childStyle.stroke;
94
- }
95
- }
96
- if (
97
- options.shapeCallback === null ||
98
- options.shapeCallback(callbackData) !== false
99
- ) {
100
- // Add/remove attribute
101
- if (options.remove) {
102
- $child.removeAttr(options.shapeAttribute);
103
- } else {
104
- $child.attr(
105
- options.shapeAttribute,
106
- options.shapeAttributeValue.replace('{index}', shapeIndex)
107
- );
108
- }
109
- }
110
-
111
- if (options.returnNodes) {
112
- nodes.push($child);
113
- }
114
- shapeIndex++;
115
- total++;
116
- }
117
-
118
- // Check child elements
119
- checkChildElements($child, childStyle);
120
- });
121
- }
122
-
123
- try {
124
- checkChildElements($root, {
125
- fill: '#000',
126
- stroke: false,
127
- });
128
- } catch (err) {
129
- reject(err);
130
- return;
131
- }
132
-
133
- fulfill(options.returnNodes ? nodes : total);
134
- });
135
- };