Release 5.0.0-beta5
This commit is contained in:
@@ -237,10 +237,35 @@ fontawesome.parse.transform('grow-2 left-4 rotate-15')
|
||||
"rotate": 15
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `fontawesome.parse.iconFromPack(iconString)`
|
||||
### `fontawesome.library.add(...iconDefinitions)`
|
||||
|
||||
Pre-registering icon definitions so that do not have to explicitly pass them to render an icon.
|
||||
|
||||
example: explicitly passing the icon:
|
||||
|
||||
```javascript
|
||||
import brands from '@fortawesome/fontawesome-brands'
|
||||
import { faUser } from '@fortawesome/fontawesome-solid'
|
||||
|
||||
fontawesome.icon(faUser)
|
||||
fontawesome.icon(brands.faFortAwesome)
|
||||
```
|
||||
|
||||
example: using the library
|
||||
|
||||
```javascript
|
||||
import brands from '@fortawesome/fontawesome-brands'
|
||||
import { faUser } from '@fortawesome/fontawesome-solid'
|
||||
|
||||
fontawesome.library.add(brands, faUser)
|
||||
|
||||
fontawesome.icon({prefix: 'fab', iconName: 'fort-awesome'})
|
||||
```
|
||||
---
|
||||
|
||||
### `fontawesome.findIconDefinition(params)`
|
||||
|
||||
Takes the class portion of an icon's definition and fetches the icon from pack definitions.
|
||||
|
||||
@@ -249,7 +274,7 @@ Takes the class portion of an icon's definition and fetches the icon from pack d
|
||||
must be loaded for this function to return anything meaningful.
|
||||
|
||||
```javascript
|
||||
fontawesome.parse.iconFromPack('fa fa-user')
|
||||
fontawesome.findIconDefinition({iconName: 'user'})
|
||||
```
|
||||
|
||||
```javascript
|
||||
@@ -266,6 +291,26 @@ fontawesome.parse.iconFromPack('fa fa-user')
|
||||
}
|
||||
```
|
||||
|
||||
or specify the prefix as well
|
||||
|
||||
```javascript
|
||||
fontawesome.findIconDefinition({prefix: 'fab', iconName: 'fort-awesome'})
|
||||
```
|
||||
|
||||
```javascript
|
||||
{
|
||||
"prefix": "fab",
|
||||
"iconName": "fort-awesome",
|
||||
"icon": [
|
||||
448,
|
||||
512,
|
||||
[],
|
||||
"f286",
|
||||
"M412…999z"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
You can then feed this as the `iconDefinition` to other functions.
|
||||
|
||||
---
|
||||
@@ -464,7 +509,7 @@ window.FontAwesome
|
||||
You can use it just like you would the Node.js package:
|
||||
|
||||
```javascript
|
||||
faUser = FontAwesome.parse.iconFromPack('fa fa-user')
|
||||
faUser = FontAwesome.findIconDefinition({prefix: 'fa', iconName: 'user'})
|
||||
|
||||
FontAwesome.icon(faUser).html
|
||||
```
|
||||
|
||||
@@ -22,7 +22,13 @@ var UNITS_IN_GRID = 16;
|
||||
var DEFAULT_FAMILY_PREFIX = 'fa';
|
||||
var DEFAULT_REPLACEMENT_CLASS = 'svg-inline--fa';
|
||||
|
||||
var PRODUCTION = typeof process !== 'undefined' && process.env && process.env.NODE_ENV === 'production';
|
||||
var PRODUCTION = function () {
|
||||
try {
|
||||
return process.env.NODE_ENV === 'production';
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}();
|
||||
|
||||
var oneToTen = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
var oneToTwenty = oneToTen.concat([11, 12, 13, 14, 15, 16, 17, 18, 19, 20]);
|
||||
@@ -35,6 +41,36 @@ var RESERVED_CLASSES = ['xs', 'sm', 'lg', 'fw', 'ul', 'li', 'border', 'pull-left
|
||||
return 'w-' + n;
|
||||
}));
|
||||
|
||||
var classCallCheck = function (instance, Constructor) {
|
||||
if (!(instance instanceof Constructor)) {
|
||||
throw new TypeError("Cannot call a class as a function");
|
||||
}
|
||||
};
|
||||
|
||||
var createClass = function () {
|
||||
function defineProperties(target, props) {
|
||||
for (var i = 0; i < props.length; i++) {
|
||||
var descriptor = props[i];
|
||||
descriptor.enumerable = descriptor.enumerable || false;
|
||||
descriptor.configurable = true;
|
||||
if ("value" in descriptor) descriptor.writable = true;
|
||||
Object.defineProperty(target, descriptor.key, descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
return function (Constructor, protoProps, staticProps) {
|
||||
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
||||
if (staticProps) defineProperties(Constructor, staticProps);
|
||||
return Constructor;
|
||||
};
|
||||
}();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var _extends = Object.assign || function (target) {
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
var source = arguments[i];
|
||||
@@ -543,7 +579,7 @@ function makeLayersTextHtml(params) {
|
||||
|
||||
var noop$1 = function noop() {};
|
||||
var p = config.measurePerformance && PERFORMANCE ? PERFORMANCE : { mark: noop$1, measure: noop$1 };
|
||||
var preamble = 'FA "5.0.0-beta4"';
|
||||
var preamble = 'FA "5.0.0-beta5"';
|
||||
|
||||
var begin = function begin(name) {
|
||||
p.mark(preamble + ' ' + name + ' begins');
|
||||
@@ -748,6 +784,16 @@ function getCanonicalIcon(values) {
|
||||
}, emptyCanonicalIcon());
|
||||
}
|
||||
|
||||
function iconFromMapping(mapping, prefix, iconName) {
|
||||
if (mapping && mapping[prefix] && mapping[prefix][iconName]) {
|
||||
return {
|
||||
prefix: prefix,
|
||||
iconName: iconName,
|
||||
icon: mapping[prefix][iconName]
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
var classParser = function (node) {
|
||||
var existingPrefix = node.getAttribute('data-prefix');
|
||||
var existingIconName = node.getAttribute('data-icon');
|
||||
@@ -1015,6 +1061,56 @@ var styles = function () {
|
||||
return s;
|
||||
};
|
||||
|
||||
var Library = function () {
|
||||
function Library() {
|
||||
classCallCheck(this, Library);
|
||||
|
||||
this.definitions = {};
|
||||
}
|
||||
|
||||
createClass(Library, [{
|
||||
key: "add",
|
||||
value: function add() {
|
||||
var _this = this;
|
||||
|
||||
for (var _len = arguments.length, definitions = Array(_len), _key = 0; _key < _len; _key++) {
|
||||
definitions[_key] = arguments[_key];
|
||||
}
|
||||
|
||||
var additions = definitions.reduce(this._pullDefinitions, {});
|
||||
|
||||
Object.keys(additions).forEach(function (key) {
|
||||
_this.definitions[key] = _extends({}, _this.definitions[key] || {}, additions[key]);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "reset",
|
||||
value: function reset() {
|
||||
this.definitions = {};
|
||||
}
|
||||
}, {
|
||||
key: "_pullDefinitions",
|
||||
value: function _pullDefinitions(additions, definition) {
|
||||
var normalized = definition.prefix && definition.iconName && definition.icon ? { 0: definition } : definition;
|
||||
|
||||
Object.keys(normalized).map(function (key) {
|
||||
var _normalized$key = normalized[key],
|
||||
prefix = _normalized$key.prefix,
|
||||
iconName = _normalized$key.iconName,
|
||||
icon = _normalized$key.icon;
|
||||
|
||||
|
||||
if (!additions[prefix]) additions[prefix] = {};
|
||||
|
||||
additions[prefix][iconName] = icon;
|
||||
});
|
||||
|
||||
return additions;
|
||||
}
|
||||
}]);
|
||||
return Library;
|
||||
}();
|
||||
|
||||
function prepIcon(icon) {
|
||||
var width = icon[0];
|
||||
var height = icon[1];
|
||||
@@ -1068,6 +1164,19 @@ function apiObject(val, abstractCreator) {
|
||||
return val;
|
||||
}
|
||||
|
||||
function findIconDefinition(params) {
|
||||
var _params$prefix = params.prefix,
|
||||
prefix = _params$prefix === undefined ? 'fa' : _params$prefix,
|
||||
iconName = params.iconName;
|
||||
|
||||
|
||||
if (!iconName) return;
|
||||
|
||||
return iconFromMapping(library.definitions, prefix, iconName) || iconFromMapping(namespace.packs, prefix, iconName);
|
||||
}
|
||||
|
||||
var library = new Library();
|
||||
|
||||
var api$1 = {
|
||||
dom: {
|
||||
i2svg: function i2svg() {
|
||||
@@ -1091,26 +1200,16 @@ var api$1 = {
|
||||
}
|
||||
},
|
||||
|
||||
library: library,
|
||||
|
||||
parse: {
|
||||
transform: function transform(transformString) {
|
||||
return parseTransformString(transformString);
|
||||
},
|
||||
|
||||
iconFromPack: function iconFromPack(iconString) {
|
||||
var _getCanonicalIcon = getCanonicalIcon(iconString.split(' ')),
|
||||
prefix = _getCanonicalIcon.prefix,
|
||||
iconName = _getCanonicalIcon.iconName;
|
||||
|
||||
if (namespace.packs && namespace.packs[prefix] && namespace.packs[prefix][iconName]) {
|
||||
return {
|
||||
prefix: prefix,
|
||||
iconName: iconName,
|
||||
icon: namespace.packs[prefix][iconName]
|
||||
};
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
findIconDefinition: findIconDefinition,
|
||||
|
||||
icon: function icon(iconDefinition) {
|
||||
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
var _params$transform = params.transform,
|
||||
@@ -1125,10 +1224,11 @@ var api$1 = {
|
||||
attributes = _params$attributes === undefined ? {} : _params$attributes,
|
||||
_params$style = params.style,
|
||||
style = _params$style === undefined ? {} : _params$style;
|
||||
var prefix = iconDefinition.prefix,
|
||||
iconName = iconDefinition.iconName,
|
||||
icon = iconDefinition.icon;
|
||||
|
||||
var _ref = iconDefinition.icon ? iconDefinition : findIconDefinition(iconDefinition),
|
||||
prefix = _ref.prefix,
|
||||
iconName = _ref.iconName,
|
||||
icon = _ref.icon;
|
||||
|
||||
return apiObject(_extends({ type: 'icon' }, iconDefinition), function () {
|
||||
ensureStyles();
|
||||
|
||||
@@ -28,7 +28,13 @@ var UNITS_IN_GRID = 16;
|
||||
var DEFAULT_FAMILY_PREFIX = 'fa';
|
||||
var DEFAULT_REPLACEMENT_CLASS = 'svg-inline--fa';
|
||||
|
||||
var PRODUCTION = typeof process !== 'undefined' && process.env && process.env.NODE_ENV === 'production';
|
||||
var PRODUCTION = function () {
|
||||
try {
|
||||
return process.env.NODE_ENV === 'production';
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}();
|
||||
|
||||
var oneToTen = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
var oneToTwenty = oneToTen.concat([11, 12, 13, 14, 15, 16, 17, 18, 19, 20]);
|
||||
@@ -41,6 +47,36 @@ var RESERVED_CLASSES = ['xs', 'sm', 'lg', 'fw', 'ul', 'li', 'border', 'pull-left
|
||||
return 'w-' + n;
|
||||
}));
|
||||
|
||||
var classCallCheck = function (instance, Constructor) {
|
||||
if (!(instance instanceof Constructor)) {
|
||||
throw new TypeError("Cannot call a class as a function");
|
||||
}
|
||||
};
|
||||
|
||||
var createClass = function () {
|
||||
function defineProperties(target, props) {
|
||||
for (var i = 0; i < props.length; i++) {
|
||||
var descriptor = props[i];
|
||||
descriptor.enumerable = descriptor.enumerable || false;
|
||||
descriptor.configurable = true;
|
||||
if ("value" in descriptor) descriptor.writable = true;
|
||||
Object.defineProperty(target, descriptor.key, descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
return function (Constructor, protoProps, staticProps) {
|
||||
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
||||
if (staticProps) defineProperties(Constructor, staticProps);
|
||||
return Constructor;
|
||||
};
|
||||
}();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var _extends = Object.assign || function (target) {
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
var source = arguments[i];
|
||||
@@ -549,7 +585,7 @@ function makeLayersTextHtml(params) {
|
||||
|
||||
var noop$1 = function noop() {};
|
||||
var p = config.measurePerformance && PERFORMANCE ? PERFORMANCE : { mark: noop$1, measure: noop$1 };
|
||||
var preamble = 'FA "5.0.0-beta4"';
|
||||
var preamble = 'FA "5.0.0-beta5"';
|
||||
|
||||
var begin = function begin(name) {
|
||||
p.mark(preamble + ' ' + name + ' begins');
|
||||
@@ -754,6 +790,16 @@ function getCanonicalIcon(values) {
|
||||
}, emptyCanonicalIcon());
|
||||
}
|
||||
|
||||
function iconFromMapping(mapping, prefix, iconName) {
|
||||
if (mapping && mapping[prefix] && mapping[prefix][iconName]) {
|
||||
return {
|
||||
prefix: prefix,
|
||||
iconName: iconName,
|
||||
icon: mapping[prefix][iconName]
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
var classParser = function (node) {
|
||||
var existingPrefix = node.getAttribute('data-prefix');
|
||||
var existingIconName = node.getAttribute('data-icon');
|
||||
@@ -1021,6 +1067,56 @@ var styles = function () {
|
||||
return s;
|
||||
};
|
||||
|
||||
var Library = function () {
|
||||
function Library() {
|
||||
classCallCheck(this, Library);
|
||||
|
||||
this.definitions = {};
|
||||
}
|
||||
|
||||
createClass(Library, [{
|
||||
key: "add",
|
||||
value: function add() {
|
||||
var _this = this;
|
||||
|
||||
for (var _len = arguments.length, definitions = Array(_len), _key = 0; _key < _len; _key++) {
|
||||
definitions[_key] = arguments[_key];
|
||||
}
|
||||
|
||||
var additions = definitions.reduce(this._pullDefinitions, {});
|
||||
|
||||
Object.keys(additions).forEach(function (key) {
|
||||
_this.definitions[key] = _extends({}, _this.definitions[key] || {}, additions[key]);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "reset",
|
||||
value: function reset() {
|
||||
this.definitions = {};
|
||||
}
|
||||
}, {
|
||||
key: "_pullDefinitions",
|
||||
value: function _pullDefinitions(additions, definition) {
|
||||
var normalized = definition.prefix && definition.iconName && definition.icon ? { 0: definition } : definition;
|
||||
|
||||
Object.keys(normalized).map(function (key) {
|
||||
var _normalized$key = normalized[key],
|
||||
prefix = _normalized$key.prefix,
|
||||
iconName = _normalized$key.iconName,
|
||||
icon = _normalized$key.icon;
|
||||
|
||||
|
||||
if (!additions[prefix]) additions[prefix] = {};
|
||||
|
||||
additions[prefix][iconName] = icon;
|
||||
});
|
||||
|
||||
return additions;
|
||||
}
|
||||
}]);
|
||||
return Library;
|
||||
}();
|
||||
|
||||
function prepIcon(icon) {
|
||||
var width = icon[0];
|
||||
var height = icon[1];
|
||||
@@ -1074,6 +1170,19 @@ function apiObject(val, abstractCreator) {
|
||||
return val;
|
||||
}
|
||||
|
||||
function findIconDefinition(params) {
|
||||
var _params$prefix = params.prefix,
|
||||
prefix = _params$prefix === undefined ? 'fa' : _params$prefix,
|
||||
iconName = params.iconName;
|
||||
|
||||
|
||||
if (!iconName) return;
|
||||
|
||||
return iconFromMapping(library.definitions, prefix, iconName) || iconFromMapping(namespace.packs, prefix, iconName);
|
||||
}
|
||||
|
||||
var library = new Library();
|
||||
|
||||
var api$1 = {
|
||||
dom: {
|
||||
i2svg: function i2svg() {
|
||||
@@ -1097,26 +1206,16 @@ var api$1 = {
|
||||
}
|
||||
},
|
||||
|
||||
library: library,
|
||||
|
||||
parse: {
|
||||
transform: function transform(transformString) {
|
||||
return parseTransformString(transformString);
|
||||
},
|
||||
|
||||
iconFromPack: function iconFromPack(iconString) {
|
||||
var _getCanonicalIcon = getCanonicalIcon(iconString.split(' ')),
|
||||
prefix = _getCanonicalIcon.prefix,
|
||||
iconName = _getCanonicalIcon.iconName;
|
||||
|
||||
if (namespace.packs && namespace.packs[prefix] && namespace.packs[prefix][iconName]) {
|
||||
return {
|
||||
prefix: prefix,
|
||||
iconName: iconName,
|
||||
icon: namespace.packs[prefix][iconName]
|
||||
};
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
findIconDefinition: findIconDefinition,
|
||||
|
||||
icon: function icon(iconDefinition) {
|
||||
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
var _params$transform = params.transform,
|
||||
@@ -1131,10 +1230,11 @@ var api$1 = {
|
||||
attributes = _params$attributes === undefined ? {} : _params$attributes,
|
||||
_params$style = params.style,
|
||||
style = _params$style === undefined ? {} : _params$style;
|
||||
var prefix = iconDefinition.prefix,
|
||||
iconName = iconDefinition.iconName,
|
||||
icon = iconDefinition.icon;
|
||||
|
||||
var _ref = iconDefinition.icon ? iconDefinition : findIconDefinition(iconDefinition),
|
||||
prefix = _ref.prefix,
|
||||
iconName = _ref.iconName,
|
||||
icon = _ref.icon;
|
||||
|
||||
return apiObject(_extends({ type: 'icon' }, iconDefinition), function () {
|
||||
ensureStyles();
|
||||
|
||||
@@ -4,6 +4,6 @@
|
||||
"repository": "https://github.com/FortAwesome/Font-Awesome-Pro",
|
||||
"jsnext:main": "index.es.js",
|
||||
"license": "MIT",
|
||||
"version": "0.0.6",
|
||||
"version": "0.0.8",
|
||||
"name": "@fortawesome/fontawesome"
|
||||
}
|
||||
Reference in New Issue
Block a user