@iconify/json 1.1.425 → 2.0.0-beta.3
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/collections.json +1328 -822
- package/collections.md +9 -9
- package/composer.json +1 -1
- package/dist/index.d.ts +49 -0
- package/dist/index.js +32 -0
- package/dist/index.mjs +32 -0
- package/json/carbon.json +7 -7
- package/json/codicon.json +3 -6
- package/json/fluent.json +72 -1312
- package/json/ic.json +1 -521
- package/json/mdi.json +43 -249
- package/json/simple-icons.json +2 -53
- package/json/tabler.json +2 -62
- package/package.json +52 -3
- package/readme.md +179 -54
- package/lib/finder.js +0 -49
package/readme.md
CHANGED
|
@@ -1,20 +1,28 @@
|
|
|
1
|
-
# Iconify
|
|
1
|
+
# Iconify icon sets in JSON format
|
|
2
2
|
|
|
3
3
|
This is collection of SVG icons created by various authors, released under various free licenses. Some collections require attribution when used for commercial purposes. See [collections.md](./collections.md) for list of collections and their licenses.
|
|
4
4
|
|
|
5
|
-
All
|
|
5
|
+
All icons have been normalized:
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- Cleaned up, removing anything that is not needed to show icon.
|
|
8
|
+
- Colors for monotone icons have been replaced with `currentColor`, making it easy to change icon color by changing text color.
|
|
9
|
+
- Icon content has been optimised to reduce its size.
|
|
8
10
|
|
|
9
|
-
Repository is updated
|
|
11
|
+
Repository is updated by fully automated script, so it always contains latest icons from various sources.
|
|
10
12
|
|
|
13
|
+
## Format and usage
|
|
14
|
+
|
|
15
|
+
Icon sets are stored in `IconifyJSON` format. TypeScript definition is available in `@iconify/types` package. Documentation is [available on Iconify Documentation website](https://docs.iconify.design/types/iconify-json.html).
|
|
16
|
+
|
|
17
|
+
To work with icon sets, use [Iconify Utils](https://docs.iconify.design/tools/utils/). Utils package works in any JavaScript environment: Node.js, Deno, browsers, isolated JavaScript environments. For PHP applications use [Iconify JSON Tools](https://docs.iconify.design/tools/json/).
|
|
18
|
+
|
|
19
|
+
To create icon sets, use [Iconify Tools](https://docs.iconify.design/tools/tools2/). Tools package works in Node.js, it can import icons from various sources, do cleanup, optimisation, export it in `IconifyJSON` format and generate NPM packages.
|
|
11
20
|
|
|
12
21
|
## How to get this repository
|
|
13
22
|
|
|
14
23
|
Instructions below are for Node.js and PHP projects.
|
|
15
24
|
|
|
16
|
-
|
|
17
|
-
#### Node.js
|
|
25
|
+
### Node.js
|
|
18
26
|
|
|
19
27
|
Run this command to add icons to your project:
|
|
20
28
|
|
|
@@ -24,17 +32,16 @@ npm install --save @iconify/json
|
|
|
24
32
|
|
|
25
33
|
Icons will be available in node_modules/@iconify/json
|
|
26
34
|
|
|
27
|
-
To resolve filename for any json file, use this:
|
|
35
|
+
To resolve filename for any json file, use this if you are using CommonJS syntax:
|
|
28
36
|
|
|
29
37
|
```js
|
|
30
|
-
|
|
38
|
+
import { locate } from '@iconify/json';
|
|
31
39
|
|
|
32
|
-
// returns location of
|
|
33
|
-
|
|
40
|
+
// returns location of mdi-light.json
|
|
41
|
+
const mdiLightFilename = locate('mdi-light');
|
|
34
42
|
```
|
|
35
43
|
|
|
36
|
-
|
|
37
|
-
#### PHP
|
|
44
|
+
### PHP
|
|
38
45
|
|
|
39
46
|
Install and initialize Composer project. See documentation at [https://getcomposer.org](https://getcomposer.org)
|
|
40
47
|
|
|
@@ -60,75 +67,191 @@ If you don't use Composer, clone GitHub repository and add necessary autoload co
|
|
|
60
67
|
To resolve filename for any json file, use this:
|
|
61
68
|
|
|
62
69
|
```php
|
|
63
|
-
//
|
|
64
|
-
$
|
|
70
|
+
// Returns location of mdi-light.json
|
|
71
|
+
$mdiLightLocation = \Iconify\IconsJSON\Finder::locate('mdi-light');
|
|
65
72
|
```
|
|
66
73
|
|
|
67
|
-
|
|
68
|
-
## Format
|
|
74
|
+
## Data format
|
|
69
75
|
|
|
70
76
|
Icons used by Iconify are in directory json, in Iconify JSON format.
|
|
71
77
|
|
|
72
|
-
Why JSON instead of SVG?
|
|
78
|
+
Why JSON instead of SVG? There are several reasons for that:
|
|
73
79
|
|
|
74
|
-
|
|
80
|
+
- Easy to store images in bulk.
|
|
81
|
+
- Contains only content of icon without SVG element, making it easy to manipulate content without doing complex parsing. It also makes it easier to create components, such as React icon component, allowing to use framework native SVG element.
|
|
82
|
+
- Data can contain additional content: aliases for icons, icon set information, categories/tags/themes.
|
|
75
83
|
|
|
84
|
+
Why not XML?
|
|
85
|
+
|
|
86
|
+
- JSON is much easier to parse without additional tools. All languages support it.
|
|
76
87
|
|
|
77
88
|
Format of json file is very simple:
|
|
78
89
|
|
|
79
|
-
```
|
|
90
|
+
```json
|
|
80
91
|
{
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
"height": default height
|
|
92
|
+
"prefix": "mdi-light",
|
|
93
|
+
"icons": {
|
|
94
|
+
"icon-name": {
|
|
95
|
+
"body": "<g />",
|
|
96
|
+
"width": 24,
|
|
97
|
+
"height": 24
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
"aliases": {
|
|
101
|
+
"icon-alias": {
|
|
102
|
+
"parent": "icon-name"
|
|
103
|
+
}
|
|
104
|
+
}
|
|
95
105
|
}
|
|
96
106
|
```
|
|
97
107
|
|
|
98
108
|
"icons" object contains list of all icons.
|
|
99
109
|
|
|
100
110
|
Each icon has following properties:
|
|
101
|
-
* body - icon body
|
|
102
|
-
* width - width in pixels
|
|
103
|
-
* height - height in pixels
|
|
104
|
-
* rotate - rotation. Default = 0. Values: 0 = 0deg, 1 = 90deg, 2 = 180deg, 3 = 270deg
|
|
105
|
-
* hFlip - horizontal flip. Boolean value, default = false
|
|
106
|
-
* vFlip - vertical flip. Boolean value, default = false
|
|
107
|
-
* hidden - If set to true, icon is hidden. That means icon was removed from collection for some reason, but it is kept in JSON file to prevent applications that rely on old icon from breaking
|
|
108
111
|
|
|
109
|
-
|
|
110
|
-
|
|
112
|
+
- body: icon body.
|
|
113
|
+
- left, top: left and top coordinates of viewBox, default is 0.
|
|
114
|
+
- width, height: dimensions of viewBox, default is 16.
|
|
115
|
+
- rotate: rotation. Default = 0. Values: 0 = 0deg, 1 = 90deg, 2 = 180deg, 3 = 270deg.
|
|
116
|
+
- hFlip: horizontal flip. Boolean value, default = false.
|
|
117
|
+
- vFlip: vertical flip. Boolean value, default = false.
|
|
118
|
+
- hidden: if set to true, icon is hidden. That means icon was removed from collection for some reason, but it is kept in JSON file to prevent applications that rely on old icon from breaking.
|
|
111
119
|
|
|
112
|
-
Optional "aliases" object contains list of aliases for icons. Format is similar to "icons" object, with additional property "parent" that points to parent icon. Any other properties overwrite properties of parent icon.
|
|
120
|
+
Optional "aliases" object contains list of aliases for icons. Format is similar to "icons" object, but without "body" property and with additional property "parent" that points to parent icon. Transformation properties (rotate, hFlip, vFlip) are merged with parent icon's properties. Any other properties overwrite properties of parent icon.
|
|
113
121
|
|
|
114
|
-
|
|
122
|
+
When multiple icons have the same value, it is moved to root object to reduce duplication:
|
|
115
123
|
|
|
124
|
+
```json
|
|
125
|
+
{
|
|
126
|
+
"prefix": "mdi-light",
|
|
127
|
+
"icons": {
|
|
128
|
+
"icon1": {
|
|
129
|
+
"body": "<g />"
|
|
130
|
+
},
|
|
131
|
+
"icon2": {
|
|
132
|
+
"body": "<g />"
|
|
133
|
+
},
|
|
134
|
+
"icon-20": {
|
|
135
|
+
"body": "<g />",
|
|
136
|
+
"width": 20,
|
|
137
|
+
"height": 20
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
"width": 24,
|
|
141
|
+
"height": 24
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
In example above, "icon1" and "icon2" are 24x24, "icon-20" is 20x20.
|
|
146
|
+
|
|
147
|
+
For more information see developer documentation on [https://docs.iconify.design/types/iconify-json.html](https://docs.iconify.design/types/iconify-json.html)
|
|
116
148
|
|
|
117
149
|
## Extracting individual SVG icons
|
|
118
150
|
|
|
119
|
-
|
|
151
|
+
For PHP use [Iconify JSON Tools](https://docs.iconify.design/tools/json/).
|
|
152
|
+
|
|
153
|
+
For JavaScript use [Iconify Utils](https://docs.iconify.design/tools/utils/), though Iconify JSON Tools are also available (but deprecated).
|
|
154
|
+
|
|
155
|
+
Example using Iconify Utils (TypeScript):
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
import { promises as fs } from 'fs';
|
|
159
|
+
|
|
160
|
+
// Function to locate JSON file
|
|
161
|
+
import { locate } from '@iconify/json';
|
|
162
|
+
|
|
163
|
+
// Various functions from Iconify Utils
|
|
164
|
+
import { parseIconSet } from '@iconify/utils/lib/icon-set/parse';
|
|
165
|
+
import { iconToSVG } from '@iconify/utils/lib/svg/build';
|
|
166
|
+
import { defaults } from '@iconify/utils/lib/customisations';
|
|
167
|
+
|
|
168
|
+
(async () => {
|
|
169
|
+
// Locate icons
|
|
170
|
+
const filename = locate('mdi');
|
|
171
|
+
|
|
172
|
+
// Load icon set
|
|
173
|
+
const icons = JSON.parse(await fs.readFile(filename, 'utf8'));
|
|
174
|
+
|
|
175
|
+
// Parse all icons
|
|
176
|
+
const exportedSVG: Record<string, string> = Object.create(null);
|
|
177
|
+
parseIconSet(icons, (iconName, iconData) => {
|
|
178
|
+
if (!iconData) {
|
|
179
|
+
// Invalid icon
|
|
180
|
+
console.error(`Error parsing icon ${iconName}`);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Render icon
|
|
185
|
+
const renderData = iconToSVG(iconData, {
|
|
186
|
+
...defaults,
|
|
187
|
+
height: 'auto',
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
// Generate attributes for SVG element
|
|
191
|
+
const svgAttributes: Record<string, string> = {
|
|
192
|
+
'xmlns': 'http://www.w3.org/2000/svg',
|
|
193
|
+
'xmlns:xlink': 'http://www.w3.org/1999/xlink',
|
|
194
|
+
...renderData.attributes,
|
|
195
|
+
};
|
|
196
|
+
const svgAttributesStr = Object.keys(svgAttributes)
|
|
197
|
+
.map(
|
|
198
|
+
(attr) =>
|
|
199
|
+
// No need to check attributes for special characters, such as quotes,
|
|
200
|
+
// they cannot contain anything that needs escaping.
|
|
201
|
+
`${attr}="${svgAttributes[attr as keyof typeof svgAttributes]}"`
|
|
202
|
+
)
|
|
203
|
+
.join(' ');
|
|
204
|
+
|
|
205
|
+
// Generate SVG
|
|
206
|
+
const svg = `<svg ${svgAttributesStr}>${renderData.body}</svg>`;
|
|
207
|
+
exportedSVG[iconName] = svg;
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
// Output directory
|
|
211
|
+
const outputDir = 'mdi-export';
|
|
212
|
+
try {
|
|
213
|
+
await fs.mkdir(outputDir, {
|
|
214
|
+
recursive: true,
|
|
215
|
+
});
|
|
216
|
+
} catch (err) {
|
|
217
|
+
//
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Save all files
|
|
221
|
+
const filenames = Object.keys(exportedSVG);
|
|
222
|
+
for (let i = 0; i < filenames.length; i++) {
|
|
223
|
+
const filename = filenames[i];
|
|
224
|
+
const svg = exportedSVG[filename];
|
|
225
|
+
await fs.writeFile(outputDir + '/' + filename + '.svg', svg, 'utf8');
|
|
226
|
+
}
|
|
227
|
+
})();
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Example using Iconify JSON Tools:
|
|
120
231
|
|
|
121
232
|
```js
|
|
122
233
|
const fs = require('fs');
|
|
123
|
-
const {SVG, Collection} = require('@iconify/json-tools');
|
|
234
|
+
const { SVG, Collection } = require('@iconify/json-tools');
|
|
235
|
+
|
|
236
|
+
const outputDir = 'mdi-export';
|
|
237
|
+
try {
|
|
238
|
+
fs.mkdirSync(outputDir, {
|
|
239
|
+
recursive: true,
|
|
240
|
+
});
|
|
241
|
+
} catch (err) {
|
|
242
|
+
//
|
|
243
|
+
}
|
|
124
244
|
|
|
125
|
-
|
|
245
|
+
const collection = new Collection();
|
|
126
246
|
collection.loadIconifyCollection('mdi');
|
|
127
|
-
collection.listIcons(true).forEach(icon => {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
247
|
+
collection.listIcons(true).forEach((icon) => {
|
|
248
|
+
let svg = new SVG(collection.getIconData(icon));
|
|
249
|
+
fs.writeFileSync(
|
|
250
|
+
outputDir + '/' + icon + '.svg',
|
|
251
|
+
svg.getSVG({
|
|
252
|
+
height: 'auto',
|
|
253
|
+
})
|
|
254
|
+
);
|
|
132
255
|
});
|
|
133
256
|
```
|
|
134
257
|
|
|
@@ -136,17 +259,19 @@ collection.listIcons(true).forEach(icon => {
|
|
|
136
259
|
use \Iconify\JSONTools\Collection;
|
|
137
260
|
use \Iconify\JSONTools\SVG;
|
|
138
261
|
|
|
262
|
+
$outputDir = 'mdi-export';
|
|
263
|
+
@mkdir($outputDir, 0777, true);
|
|
264
|
+
|
|
139
265
|
$collection = new Collection();
|
|
140
266
|
$collection->loadIconifyCollection('mdi');
|
|
141
267
|
foreach ($collection->listIcons(true) as $icon) {
|
|
142
268
|
$svg = new SVG($collection->getIconData($icon));
|
|
143
|
-
file_put_contents('
|
|
269
|
+
file_put_contents($outputDir . '/' . $icon . '.svg', $svg->getSVG([
|
|
144
270
|
'height' => 'auto'
|
|
145
271
|
]));
|
|
146
272
|
}
|
|
147
273
|
```
|
|
148
274
|
|
|
149
|
-
|
|
150
275
|
## License
|
|
151
276
|
|
|
152
277
|
This is collection of works by various authors, not original collection.
|
package/lib/finder.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the iconify.design libraries.
|
|
3
|
-
*
|
|
4
|
-
* (c) Vjacheslav Trushkin <cyberalien@gmail.com>
|
|
5
|
-
*
|
|
6
|
-
* @license MIT
|
|
7
|
-
*
|
|
8
|
-
* For the full copyright and license information, please view the license.txt
|
|
9
|
-
* file that is available in this file's directory.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
"use strict";
|
|
13
|
-
|
|
14
|
-
const path = require('path');
|
|
15
|
-
const fs = require('fs');
|
|
16
|
-
const dir = path.dirname(__dirname);
|
|
17
|
-
|
|
18
|
-
module.exports = {
|
|
19
|
-
/**
|
|
20
|
-
* Get root directory of this package
|
|
21
|
-
* (not really useful in Node.js because require can do it, but added anyway to match php code)
|
|
22
|
-
*
|
|
23
|
-
* @returns {string}
|
|
24
|
-
*/
|
|
25
|
-
rootDir: () => dir,
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Locate JSON file
|
|
29
|
-
*
|
|
30
|
-
* @param {string} name Collection name
|
|
31
|
-
* @returns {string} Path to collection json file
|
|
32
|
-
*/
|
|
33
|
-
locate: name => dir + '/json/' + name + '.json',
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Get list of collections
|
|
37
|
-
*
|
|
38
|
-
* @return {object|null}
|
|
39
|
-
*/
|
|
40
|
-
collections: () => {
|
|
41
|
-
try {
|
|
42
|
-
let data = fs.readFileSync(dir + '/collections.json', 'utf8');
|
|
43
|
-
data = JSON.parse(data);
|
|
44
|
-
return data;
|
|
45
|
-
} catch (err) {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
};
|