# Iconify Types Type definitions for using Iconify icon sets with TypeScript. ## Files structure Iconify icon sets are available in several formats: - Big JSON files that combine many icons in one file - Node.js packages split into individual icons ### Icon format Each icon is represented by the `IconifyIcon` type. It is a simple object with multiple string, number or boolean attributes. The only required attribute is: - `body`: string. Value contains inner HTML of an icon as a string, for example ``. Optional attributes are represented by type `IconifyOptional`. They are split into several types: dimensions (`IconifyDimenisons` type) and transformations (`IconifyTransformations` type). Dimensions attributes: - `width`: number. viewBox width, number. If missing, value is set to 16. - `height`: number. viewBox height, number. If missing, value is set to 16. - `left`: number. viewBox left, number. If missing, the value is set to 0. - `top`: number. viewBox top, number. If missing, the value is set to 0. Transformations: - `rotate`: number. Icon rotation. Iconify icons can be rotated in 90 degrees increments, allowing to reuse the same source icon for multiple icons, such as arrow-up being a copy of arrow-left rotated by 90 degrees. Values are 0 for 0 degrees, 1 for 90 degrees, 2 for 180 degrees, 3 for 270 degrees. The default value is 0. - `hFlip`: boolean. Horizontal flip. Similar to the rotation transformation, an icon can be flipped horizontally and vertically. It can be used to quickly create aliases, such as arrow-left being an alias of arrow-right, but with hFlip set to true. The default value is false. - `vFlip`: boolean. Vertical flip. The default value is false. Example of icon object: ```js const mdiHandIcon = { body: '', width: 24, height: 24, }; ``` ### Icon sets format Iconify icon sets format is available from multiple sources: - NPM package `@iconify/json` that includes all icon sets - API responses used by SVG framework Icon set format structure is available as the `IconifyJSON` type. It is an object with several fields: - `prefix`: string. Icon set prefix. - `icons`: object. Icons data. Value is an object that represents a set of icons, where the key is an icon name and value is `IconifyIcon` object (see "Icon format" above). - `aliases`: object. Icon aliases, similar to the `icons` object (see "Aliases" section below). Example: ```json { "prefix": "mdi", "icons": { "home": { "body": "", "width": 24, "height": 24 }, "arrow-left": { "body": "", "width": 24, "height": 24 } } } ``` All icon properties except for `body` are optional and are represented by type `IconifyOptional`. Type `IconifyJSON` also extends type `IconifyOptional`, allowing all optional properties to be placed in the root object. If an icon is missing a property, look in the root object for the default value. If the root object does not have the default value, use Iconify default value for that property (see list of properties and default values in the "Icon format" section above). Default values in the root object make it possible to reduce duplication. Example: ```json { "prefix": "mdi", "icons": { "home": { "body": "" }, "arrow-left": { "body": "" } }, "width": 24, "height": 24 } ``` In this example, both icons are 24x24, so width and height have been moved to the root object. Another example: ```json { "prefix": "fa-solid", "icons": { "arrow-left": { "body": "", "width": 448 }, "arrow-circle-left": { "body": "" }, "barcode": { "body": "" } }, "width": 512, "height": 512 } ``` In this example `arrow-circle-left` and `barcode` have width of 512, `arrow-left` has width of 448. All icons have a height of 512. #### Aliases In addition to `icons`, another important field in icon set object is `aliases`. Aliases object is similar to icons object, except that instead of icon body icons reference another icon. Each entry has the same attributes as an icon, except for `body` and has required attribute `parent` that contains the name of the parent icon. The parent icon must be present in the icon set file. Example: ```json { "prefix": "fa", "icons": { "automobile": { "body": "", "width": 2048, "height": 1600 } }, "aliases": { "car": { "parent": "automobile" } } } ``` In this example `car` is an alias of `automobile`, allowing to use the same icon by multiple names. Another example: ```json { "prefix": "fa", "icons": { "caret-left": { "body": "", "width": 576, "height": 1280 } }, "aliases": { "caret-right": { "parent": "caret-left", "hFlip": true } } } ``` In this example `caret-right` is alias of `caret-left`, but with additional `hFlip` attribute. It is identical to this: ```json { "prefix": "fa", "icons": { "caret-left": { "body": "" }, "caret-right": { "body": "", "hFlip": true } }, "width": 576, "height": 1280 } ``` ##### Merging alias attributes If both icon and alias have same attribute, following rules apply: - `rotate`: attributes are combined. For example, icon has rotate = 1, alias has rotate = 1. Result will have rotate = 2. To prevent overflow, if rotate > 3, rotate = rotate - 4. - `hFlip` and `vFlip`: attributes are combined. For example, icon has hFlip = true, alias also has hFlip = true (icon.hFlip !== alias.hFlip). Result is false. false + false = false, false + true = true, true + true = false. - other attributes are overwritten. Example: ```json { "prefix": "fa", "icons": { "caret-left": { "body": "", "hFlip": true, "width": 576, "height": 1280 } }, "aliases": { "caret-left-compact": { "parent": "caret-left", "left": 64, "width": 448 }, "caret-right": { "parent": "caret-left", "hFlip": true } } } ``` is identical to: ```json { "prefix": "fa", "icons": { "caret-left": { "body": "", "hFlip": true }, "caret-left-compact": { "body": "", "hFlip": true, // from caret-left "left": 64, // overwritten "width": 448 // overwritten }, "caret-right": { "body": "" // hFlip = false, which is default value, so it was removed } }, "width": 576, "height": 1280 } ``` #### Metadata Icon set files might also contain the metadata. That data is used for browsing icons, searching icons, exporting icon sets as fonts. Metadata is a combination of several types, represented as type `IconifyMetaData`. ##### Icon set information Icon set information is part of the metadata, it includes information about an author and license. Example: ```json { "prefix": "dashicons", "info": { "name": "Dashicons", "total": 304, "author": { "name": "WordPress", "url": "https://github.com/WordPress/dashicons" }, "license": { "title": "GPL 2.0", "spdx": "GPL-2.0-only", "url": "https://www.gnu.org/licenses/gpl-2.0.html" }, "version": "0.9.0", "samples": ["shortcode", "businessperson", "editor-expand"], "height": 20, "category": "General", "palette": false }, "icons": { // Icons here } } ``` ##### Info Information block is part of the metadata, it is used for browsing or searching icon sets. It also contains the license for icons in the icon set and information about the author. Info block is represented by the type `IconifyInfo`. You can see an example above in "info" property. IconifyInfo type has the following properties, most of them are optional: - `name`: string. Icon set name. This field is always set. - `total`: number. The total number of icons, optional. - `version`: string. The current version, optional. - `author`: object. Information about the author, always set. Author information has the following properties: - `name`: string. Author name. This field is always set. - `url`: string. Link to icon set, optional. Usually links to GitHub repository. - `license`: object. Information about the license, always set. License information has the following properties: - `title`: string. License title. This field is always set. - `spdx`: string. SPDX license identifier, optional. - `url`: string. Link to the license, optional. - `samples`: string[]. Value is an array of icon names that should be used as samples when showing the icon set in an icon sets list. - `height`: number | number[]. Value is a number or array of numbers, values are pixel grids used in the icon set. If any icons in an icon set do not match the grid, this attribute should not be set. - `displayHeight`: number. The height value that should be used for displaying samples. Value is a number between 16 and 30 (inclusive). ##### Characters map Characters map is part of the metadata, it is used for icon sets that are either imported from icon fonts or intended to be exported to icon font. Characters map allows storing characters for export as well as searching icons by character used in an icon font. It is a simple object, where the key is character code in hexadecimal form, value is an icon name. Important: each icon can have multiple characters! Example: ```json { "prefix": "fa", "icons": { // Icons here }, "chars": { "f000": "glass", "f001": "music", "f002": "search", "f003": "envelope-o", "f004": "heart", "f005": "star" // and so on... } } ``` ##### Categories Categories are part of the metadata, used to allow filtering icons when showing the entire icons set. Categories list is a simple object, where the key is category name, value is the list of icons. Important: each icon can belong to multiple categories! ```json { "prefix": "fa-solid", "icons": { // Icons here }, "categories": { "Accessibility": [ "american-sign-language-interpreting", "assistive-listening-systems", "audio-description", "blind", "braille", "closed-captioning", "deaf", "low-vision", "phone-volume", "question-circle", "sign-language", "tty", "universal-access", "wheelchair" ], "Alert": [ "bell", "bell-slash", "exclamation", "exclamation-circle", "exclamation-triangle", "radiation", "radiation-alt", "skull-crossbones" ] // and so on... } } ``` ##### Themes Themes are part of the metadata, similar to categories, but using prefixes or suffixes to identify icons that belong to a theme. This is useful when icon set has variations of icons, such as "baseline-_", "outline-_". Example: ```json { "prefix": "ic", "icons": { // Icons here }, "themes": { "baseline": { "title": "Baseline", "prefix": "baseline-" }, "outline": { "title": "Outline", "prefix": "outline-" }, "round": { "title": "Round", "prefix": "round-" }, "sharp": { "title": "Sharp", "prefix": "sharp-" }, "twotone": { "title": "Two-Tone", "prefix": "twotone-" } } } ``` Each theme can have one of the attributes: `prefix` or `suffix`. The prefix must end with `-`, suffix must start with `-`. In an example above, all icons that start with "baseline-", such as "baseline-home", are considered part of the "Baseline" theme. #### All attributes For an example of full icon set files that include metadata, look in icon set files in `@iconify/json` package or browse it at GitHub: [https://github.com/iconify/icon-sets](https://github.com/iconify/icon-sets) For an example of individual icons, look in JavaScript files in NPM packages such as `@iconify/icons-mdi`. ## Usage This repository is intended to be used with any Iconify packages. At the moment of writing, multiple Iconify packages are written without TypeScript. At the beginning of the year 2020 plan is to rewrite all of them with TypeScript to make sure data is consistent and avoid duplication, this package will be used for sharing types between Iconify packages. ## License This package is licensed under MIT license. `SPDX-License-Identifier: MIT` Previous versions of this package were dual-licensed under Apache 2.0 and GPL 2.0 licence, which was messy and confusing. This was later changed to MIT for simplicity. © 2021-PRESENT Vjacheslav Trushkin