Files
Font-Awesome-Pro/js/fontawesome.js
2017-08-18 10:07:26 -05:00

1344 lines
42 KiB
JavaScript

(function () {
'use strict';
var noop = function noop() {};
var _WINDOW = {};
var _DOCUMENT = {};
var _MUTATION_OBSERVER = null;
var _PERFORMANCE = { mark: noop, measure: noop };
try {
if (typeof window !== 'undefined') _WINDOW = window;
if (typeof document !== 'undefined') _DOCUMENT = document;
if (typeof MutationObserver !== 'undefined') _MUTATION_OBSERVER = MutationObserver;
if (typeof performance !== 'undefined') _PERFORMANCE = performance;
} catch (e) {}
var WINDOW = _WINDOW;
var DOCUMENT = _DOCUMENT;
var MUTATION_OBSERVER = _MUTATION_OBSERVER;
var PERFORMANCE = _PERFORMANCE;
var NAMESPACE_IDENTIFIER = '___FONT_AWESOME___';
var UNITS_IN_GRID = 16;
var DEFAULT_FAMILY_PREFIX = 'fa';
var DEFAULT_REPLACEMENT_CLASS = 'svg-inline--fa';
var PRODUCTION = typeof process !== 'undefined' && process.env && undefined === 'production';
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]);
var ATTRIBUTES_WATCHED_FOR_MUTATION = ['data-prefix', 'data-icon', 'data-fa-transform', 'data-fa-compose'];
var RESERVED_CLASSES = ['xs', 'sm', 'lg', 'fw', 'ul', 'li', 'border', 'pull-left', 'pull-right', 'spin', 'pulse', 'rotate-90', 'rotate-180', 'rotate-270', 'flip-horizontal', 'flip-vertical', 'stack', 'stack-1x', 'stack-2x', 'inverse', 'layers', 'layers-text', 'layers-counter'].concat(oneToTen.map(function (n) {
return n + 'x';
})).concat(oneToTwenty.map(function (n) {
return 'w-' + n;
}));
var _extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
var objectWithoutProperties = function (obj, keys) {
var target = {};
for (var i in obj) {
if (keys.indexOf(i) >= 0) continue;
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
target[i] = obj[i];
}
return target;
};
var toConsumableArray = function (arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
return arr2;
} else {
return Array.from(arr);
}
};
var _default = _extends({
familyPrefix: DEFAULT_FAMILY_PREFIX,
replacementClass: DEFAULT_REPLACEMENT_CLASS,
autoReplaceSvg: true,
autoAddCss: true,
autoA11y: true,
observeMutations: true,
keepOriginalSource: true,
measurePerformance: false,
showMissingIcons: true
}, WINDOW.FontAwesomeConfig || {});
if (!_default.autoReplaceSvg) _default.observeMutations = false;
var config = _extends({}, _default);
WINDOW.FontAwesomeConfig = config;
function update(newConfig) {
var validKeys = Object.keys(config);
Object.keys(newConfig).forEach(function (configKey) {
if (~validKeys.indexOf(configKey)) {
config[configKey] = newConfig[configKey];
}
});
}
var w = WINDOW || {};
if (!w[NAMESPACE_IDENTIFIER]) w[NAMESPACE_IDENTIFIER] = {};
if (!w[NAMESPACE_IDENTIFIER].packs) w[NAMESPACE_IDENTIFIER].packs = {};
if (!w[NAMESPACE_IDENTIFIER].hooks) w[NAMESPACE_IDENTIFIER].hooks = {};
if (!w[NAMESPACE_IDENTIFIER].shims) w[NAMESPACE_IDENTIFIER].shims = [];
var namespace = w[NAMESPACE_IDENTIFIER];
function isReserved(name) {
return ~RESERVED_CLASSES.indexOf(name);
}
function bunker(fn) {
try {
fn();
} catch (e) {
if (undefined !== 'production') {
throw e;
}
}
}
function insertStyle(css) {
if (!css) {
return;
}
if (typeof DOCUMENT.createElement === 'undefined') {
return;
}
var style = DOCUMENT.createElement('style');
style.setAttribute('type', 'text/css');
style.innerHTML = css;
DOCUMENT.head.appendChild(style);
return css;
}
var _uniqueId = 0;
function nextUniqueId() {
_uniqueId++;
return _uniqueId;
}
function toArray$1(obj) {
var array = [];
for (var i = (obj || []).length >>> 0; i--;) {
array[i] = obj[i];
}
return array;
}
function getIconName(familyPrefix, cls) {
var parts = cls.split('-');
var prefix = parts[0];
var iconName = parts.slice(1).join('-');
if (prefix === familyPrefix && iconName !== '' && !isReserved(iconName)) {
return iconName;
} else {
return null;
}
}
function htmlEscape(str) {
return str.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/'/g, '&#39;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
function joinAttributes(attributes) {
return Object.keys(attributes).reduce(function (acc, attributeName) {
return acc + (attributeName + '="' + attributes[attributeName] + '" ');
}, '');
}
function joinStyles(styles) {
return Object.keys(styles).reduce(function (acc, styleName) {
return acc + (styleName + ': ' + styles[styleName] + ';');
}, '');
}
function toHtml(abstractNodes) {
var tag = abstractNodes.tag,
_abstractNodes$attrib = abstractNodes.attributes,
attributes = _abstractNodes$attrib === undefined ? {} : _abstractNodes$attrib,
_abstractNodes$childr = abstractNodes.children,
children = _abstractNodes$childr === undefined ? [] : _abstractNodes$childr;
if (typeof abstractNodes === 'string') {
return htmlEscape(abstractNodes);
} else {
return '<' + tag + ' ' + joinAttributes(attributes) + '>' + children.map(toHtml).join('') + '</' + tag + '>';
}
}
var _ref = WINDOW.navigator || {};
var _ref$userAgent = _ref.userAgent;
var userAgent = _ref$userAgent === undefined ? '' : _ref$userAgent;
var IS_BROWSER = !!WINDOW.document;
var IS_IE = ~userAgent.indexOf('MSIE') || ~userAgent.indexOf('Trident/');
function MissingIcon(error) {
this.name = 'MissingIcon';
this.message = error || 'Icon unavailable';
this.stack = new Error().stack;
}
MissingIcon.prototype = Object.create(Error.prototype);
MissingIcon.prototype.constructor = MissingIcon;
var FILL = { fill: 'currentColor' };
var ANIMATION_BASE = {
attributeType: 'XML',
repeatCount: 'indefinite',
dur: '2s'
};
var RING = {
tag: 'path',
attributes: _extends({}, FILL, {
d: 'M156.5,447.7l-12.6,29.5c-18.7-9.5-35.9-21.2-51.5-34.9l22.7-22.7C127.6,430.5,141.5,440,156.5,447.7z M40.6,272H8.5 c1.4,21.2,5.4,41.7,11.7,61.1L50,321.2C45.1,305.5,41.8,289,40.6,272z M40.6,240c1.4-18.8,5.2-37,11.1-54.1l-29.5-12.6 C14.7,194.3,10,216.7,8.5,240H40.6z M64.3,156.5c7.8-14.9,17.2-28.8,28.1-41.5L69.7,92.3c-13.7,15.6-25.5,32.8-34.9,51.5 L64.3,156.5z M397,419.6c-13.9,12-29.4,22.3-46.1,30.4l11.9,29.8c20.7-9.9,39.8-22.6,56.9-37.6L397,419.6z M115,92.4 c13.9-12,29.4-22.3,46.1-30.4l-11.9-29.8c-20.7,9.9-39.8,22.6-56.8,37.6L115,92.4z M447.7,355.5c-7.8,14.9-17.2,28.8-28.1,41.5 l22.7,22.7c13.7-15.6,25.5-32.9,34.9-51.5L447.7,355.5z M471.4,272c-1.4,18.8-5.2,37-11.1,54.1l29.5,12.6 c7.5-21.1,12.2-43.5,13.6-66.8H471.4z M321.2,462c-15.7,5-32.2,8.2-49.2,9.4v32.1c21.2-1.4,41.7-5.4,61.1-11.7L321.2,462z M240,471.4c-18.8-1.4-37-5.2-54.1-11.1l-12.6,29.5c21.1,7.5,43.5,12.2,66.8,13.6V471.4z M462,190.8c5,15.7,8.2,32.2,9.4,49.2h32.1 c-1.4-21.2-5.4-41.7-11.7-61.1L462,190.8z M92.4,397c-12-13.9-22.3-29.4-30.4-46.1l-29.8,11.9c9.9,20.7,22.6,39.8,37.6,56.9 L92.4,397z M272,40.6c18.8,1.4,36.9,5.2,54.1,11.1l12.6-29.5C317.7,14.7,295.3,10,272,8.5V40.6z M190.8,50 c15.7-5,32.2-8.2,49.2-9.4V8.5c-21.2,1.4-41.7,5.4-61.1,11.7L190.8,50z M442.3,92.3L419.6,115c12,13.9,22.3,29.4,30.5,46.1 l29.8-11.9C470,128.5,457.3,109.4,442.3,92.3z M397,92.4l22.7-22.7c-15.6-13.7-32.8-25.5-51.5-34.9l-12.6,29.5 C370.4,72.1,384.4,81.5,397,92.4z'
})
};
var OPACITY_ANIMATE = _extends({}, ANIMATION_BASE, {
attributeName: 'opacity'
});
var DOT = {
tag: 'circle',
attributes: _extends({}, FILL, {
cx: '256',
cy: '364',
r: '28'
}),
children: [{ tag: 'animate', attributes: _extends({}, ANIMATION_BASE, { attributeName: 'r', values: '28;14;28;28;14;28;' }) }, { tag: 'animate', attributes: _extends({}, OPACITY_ANIMATE, { values: '1;0;1;1;0;1;' }) }]
};
var QUESTION = {
tag: 'path',
attributes: _extends({}, FILL, {
opacity: '1',
d: 'M263.7,312h-16c-6.6,0-12-5.4-12-12c0-71,77.4-63.9,77.4-107.8c0-20-17.8-40.2-57.4-40.2c-29.1,0-44.3,9.6-59.2,28.7 c-3.9,5-11.1,6-16.2,2.4l-13.1-9.2c-5.6-3.9-6.9-11.8-2.6-17.2c21.2-27.2,46.4-44.7,91.2-44.7c52.3,0,97.4,29.8,97.4,80.2 c0,67.6-77.4,63.5-77.4,107.8C275.7,306.6,270.3,312,263.7,312z'
}),
children: [{ tag: 'animate', attributes: _extends({}, OPACITY_ANIMATE, { values: '1;0;0;0;0;1;' }) }]
};
var EXCLAMATION = {
tag: 'path',
attributes: _extends({}, FILL, {
opacity: '0',
d: 'M232.5,134.5l7,168c0.3,6.4,5.6,11.5,12,11.5h9c6.4,0,11.7-5.1,12-11.5l7-168c0.3-6.8-5.2-12.5-12-12.5h-23 C237.7,122,232.2,127.7,232.5,134.5z'
}),
children: [{ tag: 'animate', attributes: _extends({}, OPACITY_ANIMATE, { values: '0;0;1;1;0;0;' }) }]
};
var missing = { tag: 'g', children: [RING, DOT, QUESTION, EXCLAMATION] };
var ALL_SPACE = {
x: 0,
y: 0,
width: '100%',
height: '100%'
};
var makeIconComposition = function (_ref) {
var main = _ref.main,
compose = _ref.compose,
transform = _ref.transform;
var mainWidth = main.width,
mainPath = main.icon;
var composeWidth = compose.width,
composePath = compose.icon;
var groupTranslate = 'translate(' + transform.x * 32 + ', ' + transform.y * 32 + ') ';
var groupScale = 'scale(' + transform.size / 16 * (transform.flipX ? -1 : 1) + ', ' + transform.size / 16 * (transform.flipY ? -1 : 1) + ') ';
var groupRotate = 'rotate(' + transform.rotate + ' 0 0)';
var groupTransform = {
transform: groupTranslate + ' ' + groupScale + ' ' + groupRotate
};
var mainTransform = {
transform: 'translate(' + mainWidth / 2 * -1 + ' -256)'
};
var maskRect = {
tag: 'rect',
attributes: _extends({}, ALL_SPACE, {
fill: 'white'
})
};
var maskInnerGroup = {
tag: 'g',
attributes: _extends({}, groupTransform),
children: [{ tag: 'path', attributes: _extends({}, mainPath.attributes, mainTransform, { fill: 'black' }) }]
};
var maskOuterGroup = {
tag: 'g',
attributes: {
transform: 'translate(' + composeWidth / 2 + ' 256)'
},
children: [maskInnerGroup]
};
var maskId = 'mask-' + nextUniqueId();
var clipId = 'clip-' + nextUniqueId();
var mask = {
tag: 'mask',
attributes: _extends({}, ALL_SPACE, {
id: maskId,
maskUnits: 'userSpaceOnUse',
maskContentUnits: 'userSpaceOnUse'
}),
children: [maskRect, maskOuterGroup]
};
var defs = {
tag: 'defs',
children: [{ tag: 'clipPath', attributes: { id: clipId }, children: [composePath] }, mask]
};
return [defs, { tag: 'rect', attributes: _extends({ fill: 'currentColor', 'clip-path': 'url(#' + clipId + ')', mask: 'url(#' + maskId + ')' }, ALL_SPACE) }];
};
var d = UNITS_IN_GRID;
var packs$1 = namespace.packs;
var meaninglessTransform = {
size: 16,
x: 0,
y: 0,
rotate: 0,
flipX: false,
flipY: false
};
function transformIsMeaningful(transform) {
return transform.size !== meaninglessTransform.size || transform.x !== meaninglessTransform.x || transform.y !== meaninglessTransform.y || transform.rotate !== meaninglessTransform.rotate || transform.flipX || transform.flipY;
}
function transformToCss(transform) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var _options$startCentere = options.startCentered,
startCentered = _options$startCentere === undefined ? false : _options$startCentere,
_options$width = options.width,
width = _options$width === undefined ? d : _options$width,
_options$height = options.height,
height = _options$height === undefined ? d : _options$height;
var val = '';
if (startCentered && IS_IE) {
val += 'translate(' + (transform.x / d - width / 2) + 'em, ' + (transform.y / d - height / 2) + 'em) ';
} else if (startCentered) {
val += 'translate(calc(-50% + ' + transform.x / d + 'em), calc(-50% + ' + transform.y / d + 'em)) ';
} else {
val += 'translate(' + transform.x / d + 'em, ' + transform.y / d + 'em) ';
}
val += 'scale(' + transform.size / d * (transform.flipX ? -1 : 1) + ', ' + transform.size / d * (transform.flipY ? -1 : 1) + ') ';
val += 'rotate(' + transform.rotate + 'deg) ';
return val;
}
function findIcon(iconName, prefix) {
var val = {
found: false,
width: 512,
height: 512,
icon: missing
};
if (iconName && prefix && packs$1[prefix] && packs$1[prefix][iconName]) {
var icon = packs$1[prefix][iconName];
var width = icon[0];
var height = icon[1];
var vectorData = icon.slice(4);
val = {
found: true,
width: width,
height: height,
icon: { tag: 'path', attributes: { fill: 'currentColor', d: vectorData[0] } }
};
} else if (iconName && prefix && !config.showMissingIcons) {
throw new MissingIcon('Icon is missing for prefix ' + prefix + ' with icon name ' + iconName);
}
return val;
}
function makeInlineSvgAbstract(params) {
var _params$icons = params.icons,
mainIcon = _params$icons.main,
composeIcon = _params$icons.compose,
prefix = params.prefix,
iconName = params.iconName,
transform = params.transform,
title = params.title,
extra = params.extra;
var _ref = composeIcon.found ? composeIcon : mainIcon,
width = _ref.width,
height = _ref.height;
var widthClass = 'fa-w-' + Math.ceil(width / height * 16);
var attrClass = [config.replacementClass, iconName ? config.familyPrefix + '-' + iconName : '', widthClass].concat(extra.classes).join(' ');
var attributes = _extends({}, extra.attributes, {
'data-prefix': prefix,
'data-icon': iconName,
'class': attrClass,
'role': 'img',
'xmlns': 'http://www.w3.org/2000/svg',
'viewBox': '0 0 ' + width + ' ' + height
});
var children = [];
if (title) children.push({ tag: 'title', attributes: { id: attributes['aria-labelledby'] || 'title-' + nextUniqueId() }, children: [title] });
if (composeIcon.found && mainIcon.found) {
children.push.apply(children, makeIconComposition({ main: mainIcon, compose: composeIcon, transform: transform }));
} else {
var styles = _extends({}, extra.styles);
if (transformIsMeaningful(transform)) {
styles['transform'] = transformToCss(transform);
styles['-webkit-transform'] = styles['transform'];
}
var styleString = joinStyles(styles);
if (styleString.length > 0) {
attributes['style'] = styleString;
}
children.push(mainIcon.icon);
}
return [{
tag: 'svg',
attributes: attributes,
children: children
}];
}
function makeLayersTextAbstract(params) {
var content = params.content,
width = params.width,
height = params.height,
transform = params.transform,
title = params.title,
extra = params.extra;
var attributes = _extends({}, extra.attributes, title ? { 'title': title } : {}, {
'class': extra.classes.join(' ')
});
var styles = _extends({}, extra.styles);
if (transformIsMeaningful(transform)) {
styles['transform'] = transformToCss(transform, { startCentered: true, width: width, height: height });
styles['-webkit-transform'] = styles['transform'];
}
var styleString = joinStyles(styles);
if (styleString.length > 0) {
attributes['style'] = styleString;
}
var val = [];
val.push({
tag: 'span',
attributes: attributes,
children: [content]
});
if (title) {
val.push({ tag: 'span', attributes: { class: 'sr-only' }, children: [title] });
}
return val;
}
function makeInlineSvgHtml(params) {
var prefix = params.prefix,
iconName = params.iconName,
compose = params.compose;
var abstract = makeInlineSvgAbstract(_extends({}, params, {
icons: {
main: findIcon(iconName, prefix),
compose: findIcon(compose.iconName, compose.prefix)
}
}));
return abstract.map(function (a) {
return toHtml(a);
}).join('\n');
}
function makeLayersTextHtml(params) {
var abstract = makeLayersTextAbstract(params);
return abstract.map(function (a) {
return toHtml(a);
}).join('\n');
}
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 begin = function begin(name) {
p.mark(preamble + ' ' + name + ' begins');
return function () {
return end(name);
};
};
var end = function end(name) {
p.mark(preamble + ' ' + name + ' ends');
p.measure(preamble + ' ' + name, preamble + ' ' + name + ' begins', preamble + ' ' + name + ' ends');
};
var perf = { begin: begin, end: end };
function isReplaced(node) {
var nodeClass = node.getAttribute ? node.getAttribute('class') : null;
if (nodeClass) {
return ~nodeClass.toString().indexOf(config.replacementClass) || ~nodeClass.toString().indexOf('fa-layers-text');
} else {
return false;
}
}
function perform(mutations, callback) {
if (!WINDOW.requestAnimationFrame) return;
WINDOW.requestAnimationFrame(function () {
var end = perf.begin('mutate');
mutations.map(function (mutation) {
var node = mutation[0];
var newOuterHTML = mutation[1];
if (node.parentNode) node.outerHTML = newOuterHTML + (config.keepOriginalSource && node.tagName.toLowerCase() !== 'svg' ? '<!-- ' + node.outerHTML + ' -->' : '');
});
if (typeof callback === 'function') {
callback();
}
end();
});
}
function observe(options) {
if (!MUTATION_OBSERVER) return;
var treeCallback = options.treeCallback,
nodeCallback = options.nodeCallback;
var mo = new MUTATION_OBSERVER(function (objects) {
toArray$1(objects).forEach(function (mutationRecord) {
if (mutationRecord.type === 'childList' && mutationRecord.addedNodes.length > 0 && !isReplaced(mutationRecord.addedNodes[0])) {
treeCallback(mutationRecord.target);
}
if (mutationRecord.type === 'attributes' && isReplaced(mutationRecord.target) && ~ATTRIBUTES_WATCHED_FOR_MUTATION.indexOf(mutationRecord.attributeName)) {
nodeCallback(mutationRecord.target);
}
});
});
if (!DOCUMENT.getElementsByTagName) return;
mo.observe(DOCUMENT.getElementsByTagName('body')[0], {
childList: true, attributes: true, characterData: true, subtree: true
});
}
var styleParser = function (node) {
var style = node.getAttribute('style');
var val = [];
if (style) {
val = style.split(';').reduce(function (acc, style) {
var styles = style.split(':');
var prop = styles[0];
var value = styles.slice(1);
if (prop && value.length > 0) {
acc[prop] = value.join(':').trim();
}
return acc;
}, {});
}
return val;
};
/**
* Internal helper to bind a function known to have 4 arguments
* to a given context.
*/
var bindInternal4 = function bindInternal4 (func, thisContext) {
return function (a, b, c, d) {
return func.call(thisContext, a, b, c, d);
};
};
/**
* # Reduce
*
* A fast object `.reduce()` implementation.
*
* @param {Object} subject The object to reduce over.
* @param {Function} fn The reducer function.
* @param {mixed} initialValue The initial value for the reducer, defaults to subject[0].
* @param {Object} thisContext The context for the reducer.
* @return {mixed} The final result.
*/
var reduce = function fastReduceObject (subject, fn, initialValue, thisContext) {
var keys = Object.keys(subject),
length = keys.length,
iterator = thisContext !== undefined ? bindInternal4(fn, thisContext) : fn,
i, key, result;
if (initialValue === undefined) {
i = 1;
result = subject[keys[0]];
}
else {
i = 0;
result = initialValue;
}
for (; i < length; i++) {
key = keys[i];
result = iterator(result, subject[key], key, subject);
}
return result;
};
var packs$3 = namespace.packs;
var shims = namespace.shims;
var _byUnicode = {};
var _byLigature = {};
var _byOldName = {};
var build = function build() {
var lookup = function lookup(reducer) {
return reduce(packs$3, function (o, pack, prefix) {
o[prefix] = reduce(pack, reducer, {});
return o;
}, {});
};
_byUnicode = lookup(function (acc, icon, iconName) {
acc[icon[3]] = iconName;
return acc;
});
_byLigature = lookup(function (acc, icon, iconName) {
var ligatures = icon[2];
acc[iconName] = iconName;
ligatures.forEach(function (ligature) {
acc[ligature] = iconName;
});
return acc;
});
var hasRegular = 'far' in packs$3;
_byOldName = reduce(shims, function (acc, shim) {
var oldName = shim[0];
var prefix = shim[1];
var iconName = shim[2];
if (prefix === 'far' && !hasRegular) {
prefix = 'fa';
}
acc[oldName] = { prefix: prefix, iconName: iconName };
return acc;
}, {});
};
build();
function byUnicode(prefix, unicode) {
return _byUnicode[prefix][unicode];
}
function byLigature(prefix, ligature) {
return _byLigature[prefix][ligature];
}
function byOldName(name) {
return _byOldName[name] || { prefix: null, iconName: null };
}
function toHex(unicode) {
var result = '';
for (var i = 0; i < unicode.length; i++) {
var hex = unicode.charCodeAt(i).toString(16);
result += ('000' + hex).slice(-4);
}
return result;
}
var packs$4 = namespace.packs;
var emptyCanonicalIcon = function emptyCanonicalIcon() {
return { prefix: null, iconName: null, rest: [] };
};
function getCanonicalIcon(values) {
return values.reduce(function (acc, cls) {
var iconName = getIconName(config.familyPrefix, cls);
if (packs$4[cls]) {
acc.prefix = cls;
} else if (iconName) {
var shim = byOldName(iconName);
acc.iconName = shim.iconName || iconName;
acc.prefix = shim.prefix || acc.prefix;
} else if (cls !== config.replacementClass && cls.indexOf('fa-w-') !== 0) {
acc.rest.push(cls);
}
return acc;
}, emptyCanonicalIcon());
}
var classParser = function (node) {
var existingPrefix = node.getAttribute('data-prefix');
var existingIconName = node.getAttribute('data-icon');
var val = getCanonicalIcon(toArray$1(node.classList));
if (existingPrefix && existingIconName) {
val.prefix = existingPrefix;
val.iconName = existingIconName;
}
if (val.prefix && node.innerText !== undefined && node.innerText.length > 1) {
val.iconName = byLigature(val.prefix, node.innerText);
} else if (val.prefix && node.innerText !== undefined && node.innerText.length === 1) {
val.iconName = byUnicode(val.prefix, toHex(node.innerText));
}
return val;
};
var parseTransformString = function parseTransformString(transformString) {
var transform = {
size: 16,
x: 0,
y: 0,
flipX: false,
flipY: false,
rotate: 0
};
if (!transformString) {
return transform;
} else {
return transformString.toLowerCase().split(' ').reduce(function (acc, n) {
var parts = n.toLowerCase().split('-');
var first = parts[0];
var rest = parts.slice(1).join('-');
if (first && rest === 'h') {
acc.flipX = true;
return acc;
}
if (first && rest === 'v') {
acc.flipY = true;
return acc;
}
rest = parseFloat(rest);
if (isNaN(rest)) {
return acc;
}
switch (first) {
case 'grow':
acc.size = acc.size + rest;
break;
case 'shrink':
acc.size = acc.size - rest;
break;
case 'left':
acc.x = acc.x - rest;
break;
case 'right':
acc.x = acc.x + rest;
break;
case 'up':
acc.y = acc.y - rest;
break;
case 'down':
acc.y = acc.y + rest;
break;
case 'rotate':
acc.rotate = acc.rotate + rest;
break;
}
return acc;
}, transform);
}
};
var transformParser = function (node) {
return parseTransformString(node.getAttribute('data-fa-transform'));
};
var attributesParser = function (node) {
var extraAttributes = toArray$1(node.attributes).reduce(function (acc, attr) {
if (acc.name !== 'class' && acc.name !== 'style') {
acc[attr.name] = attr.value;
}
return acc;
}, {});
var title = node.getAttribute('title');
if (config.autoA11y) {
if (title) {
extraAttributes['aria-labelledby'] = config.replacementClass + '-title-' + nextUniqueId();
} else {
extraAttributes['aria-hidden'] = 'true';
}
}
return extraAttributes;
};
var composeParser = function (node) {
var compose = node.getAttribute('data-fa-compose');
if (!compose) {
return emptyCanonicalIcon();
} else {
return getCanonicalIcon(compose.split(' ').map(function (i) {
return i.trim();
}));
}
};
function parseMeta(node) {
var _classParser = classParser(node),
iconName = _classParser.iconName,
prefix = _classParser.prefix,
extraClasses = _classParser.rest;
var extraStyles = styleParser(node);
var transform = transformParser(node);
var extraAttributes = attributesParser(node);
var compose = composeParser(node);
return {
iconName: iconName,
title: node.getAttribute('title'),
prefix: prefix,
transform: transform,
compose: compose,
extra: {
classes: extraClasses,
styles: extraStyles,
attributes: extraAttributes
}
};
}
var packs = namespace.packs;
var LAYERS_TEXT_CLASSNAME = 'fa-layers-text';
function generateSvgReplacementMutation(node, nodeMeta) {
var iconName = nodeMeta.iconName,
title = nodeMeta.title,
prefix = nodeMeta.prefix,
transform = nodeMeta.transform,
compose = nodeMeta.compose,
extra = nodeMeta.extra;
return [node, makeInlineSvgHtml({
prefix: prefix,
iconName: iconName,
transform: transform,
compose: compose,
title: title,
extra: extra
})];
}
function generateLayersText(node, nodeMeta) {
var title = nodeMeta.title,
transform = nodeMeta.transform,
extra = nodeMeta.extra;
var val = null;
var width = null;
var height = null;
if (IS_IE) {
var computedFontSize = parseInt(getComputedStyle(node).fontSize, 10);
var boundingClientRect = node.getBoundingClientRect();
width = boundingClientRect.width / computedFontSize;
height = boundingClientRect.height / computedFontSize;
}
if (config.autoA11y && !title) {
extra.attributes['aria-hidden'] = 'true';
}
val = [node, makeLayersTextHtml({
content: node.innerHTML,
width: width,
height: height,
transform: transform,
title: title,
extra: extra
})];
return val;
}
function generateMutation(node) {
var nodeMeta = parseMeta(node);
if (~nodeMeta.extra.classes.indexOf(LAYERS_TEXT_CLASSNAME)) {
return generateLayersText(node, nodeMeta);
} else {
return generateSvgReplacementMutation(node, nodeMeta);
}
}
function onTree(root) {
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
var prefixes = Object.keys(packs);
var prefixesDomQuery = ['.' + LAYERS_TEXT_CLASSNAME].concat(prefixes.map(function (p) {
return '.' + p;
})).join(', ');
if (prefixesDomQuery.length === 0) {
return;
}
var end = perf.begin('onTree');
var mutations = toArray$1(root.querySelectorAll(prefixesDomQuery)).reduce(function (acc, node) {
try {
var mutation = generateMutation(node);
if (mutation) {
acc.push(mutation);
}
} catch (e) {
if (!PRODUCTION) {
if (e instanceof MissingIcon) {
console.error(e);
}
}
}
return acc;
}, []);
end();
perform(mutations, callback);
}
function onNode(node) {
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
var mutation = generateMutation(node);
if (mutation) {
perform([mutation], callback);
}
}
var functions = [];
var listener = function listener() {
DOCUMENT.removeEventListener('DOMContentLoaded', listener);
loaded = 1;
functions.map(function (fn) {
return fn();
});
};
var loaded = (DOCUMENT.documentElement.doScroll ? /^loaded|^c/ : /^loaded|^i|^c/).test(DOCUMENT.readyState);
if (!loaded) DOCUMENT.addEventListener('DOMContentLoaded', listener);
var domready = function (fn) {
if (!DOCUMENT) return;
loaded ? setTimeout(fn, 0) : functions.push(fn);
};
var baseStyles = ".svg-inline--fa {\n display: inline-block;\n font-size: inherit;\n height: 1em;\n overflow: visible;\n vertical-align: -12.5%; }\n .svg-inline--fa.fa-lg {\n vertical-align: -25%; }\n .svg-inline--fa.fa-w-1 {\n width: 0.0625em; }\n .svg-inline--fa.fa-w-2 {\n width: 0.125em; }\n .svg-inline--fa.fa-w-3 {\n width: 0.1875em; }\n .svg-inline--fa.fa-w-4 {\n width: 0.25em; }\n .svg-inline--fa.fa-w-5 {\n width: 0.3125em; }\n .svg-inline--fa.fa-w-6 {\n width: 0.375em; }\n .svg-inline--fa.fa-w-7 {\n width: 0.4375em; }\n .svg-inline--fa.fa-w-8 {\n width: 0.5em; }\n .svg-inline--fa.fa-w-9 {\n width: 0.5625em; }\n .svg-inline--fa.fa-w-10 {\n width: 0.625em; }\n .svg-inline--fa.fa-w-11 {\n width: 0.6875em; }\n .svg-inline--fa.fa-w-12 {\n width: 0.75em; }\n .svg-inline--fa.fa-w-13 {\n width: 0.8125em; }\n .svg-inline--fa.fa-w-14 {\n width: 0.875em; }\n .svg-inline--fa.fa-w-15 {\n width: 0.9375em; }\n .svg-inline--fa.fa-w-16 {\n width: 1em; }\n .svg-inline--fa.fa-w-17 {\n width: 1.0625em; }\n .svg-inline--fa.fa-w-18 {\n width: 1.125em; }\n .svg-inline--fa.fa-w-19 {\n width: 1.1875em; }\n .svg-inline--fa.fa-w-20 {\n width: 1.25em; }\n .svg-inline--fa.fa-pull-left {\n margin-right: .3em;\n width: auto; }\n .svg-inline--fa.fa-pull-right {\n margin-left: .3em;\n width: auto; }\n .svg-inline--fa.fa-border {\n height: 1.5em; }\n .svg-inline--fa.fa-li {\n top: auto;\n width: 1.875em; }\n .svg-inline--fa.fa-fw {\n width: 1.25em; }\n\n.fa-layers svg.svg-inline--fa {\n bottom: 0;\n left: 0;\n margin: auto;\n position: absolute;\n right: 0;\n top: 0; }\n\n.fa-layers {\n display: inline-block;\n height: 1em;\n position: relative;\n text-align: center;\n vertical-align: -12.5%;\n width: 1em; }\n .fa-layers svg.svg-inline--fa {\n -webkit-transform-origin: center center;\n transform-origin: center center; }\n\n.fa-layers-text, .fa-layers-counter {\n display: inline-block;\n position: absolute;\n text-align: center; }\n\n.fa-layers-text {\n left: 50%;\n top: 50%;\n -webkit-transform: translate(-50%, -50%);\n transform: translate(-50%, -50%);\n -webkit-transform-origin: center center;\n transform-origin: center center; }\n\n.fa-layers-counter {\n background-color: #ff253a;\n border-radius: 1em;\n color: #fff;\n height: 1.5em;\n line-height: 1;\n max-width: 5em;\n min-width: 1.5em;\n overflow: hidden;\n padding: .25em;\n right: 0;\n text-overflow: ellipsis;\n top: 0;\n -webkit-transform: scale(0.25);\n transform: scale(0.25);\n -webkit-transform-origin: top right;\n transform-origin: top right; }\n\n.fa-layers-bottom-right {\n bottom: 0;\n right: 0;\n top: auto;\n -webkit-transform: scale(0.25);\n transform: scale(0.25);\n -webkit-transform-origin: bottom right;\n transform-origin: bottom right; }\n\n.fa-layers-bottom-left {\n bottom: 0;\n left: 0;\n right: auto;\n top: auto;\n -webkit-transform: scale(0.25);\n transform: scale(0.25);\n -webkit-transform-origin: bottom left;\n transform-origin: bottom left; }\n\n.fa-layers-top-right {\n right: 0;\n top: 0;\n -webkit-transform: scale(0.25);\n transform: scale(0.25);\n -webkit-transform-origin: top right;\n transform-origin: top right; }\n\n.fa-layers-top-left {\n left: 0;\n right: auto;\n top: 0;\n -webkit-transform: scale(0.25);\n transform: scale(0.25);\n -webkit-transform-origin: top left;\n transform-origin: top left; }\n\n.fa-lg {\n font-size: 1.33333em;\n line-height: 0.75em;\n vertical-align: -15%; }\n\n.fa-xs {\n font-size: .75em; }\n\n.fa-sm {\n font-size: .875em; }\n\n.fa-1x {\n font-size: 1em; }\n\n.fa-2x {\n font-size: 2em; }\n\n.fa-3x {\n font-size: 3em; }\n\n.fa-4x {\n font-size: 4em; }\n\n.fa-5x {\n font-size: 5em; }\n\n.fa-6x {\n font-size: 6em; }\n\n.fa-7x {\n font-size: 7em; }\n\n.fa-8x {\n font-size: 8em; }\n\n.fa-9x {\n font-size: 9em; }\n\n.fa-10x {\n font-size: 10em; }\n\n.fa-fw {\n text-align: center;\n width: 1.25em; }\n\n.fa-ul {\n list-style-type: none;\n margin-left: 1.875em;\n padding-left: 0; }\n .fa-ul > li {\n position: relative; }\n\n.fa-li {\n left: -1.875em;\n position: absolute;\n text-align: center;\n top: 0.14286em;\n width: 1.875em; }\n .fa-li.fa-lg {\n left: -1.625em; }\n\n.fa-border {\n border: solid 0.08em #eee;\n border-radius: .1em;\n padding: .2em .25em .15em; }\n\n.fa-pull-left {\n float: left; }\n\n.fa-pull-right {\n float: right; }\n\n.fa.fa-pull-left,\n.fas.fa-pull-left,\n.far.fa-pull-left,\n.fal.fa-pull-left,\n.fab.fa-pull-left {\n margin-right: .3em; }\n\n.fa.fa-pull-right,\n.fas.fa-pull-right,\n.far.fa-pull-right,\n.fal.fa-pull-right,\n.fab.fa-pull-right {\n margin-left: .3em; }\n\n.fa-spin {\n -webkit-animation: fa-spin 2s infinite linear;\n animation: fa-spin 2s infinite linear; }\n\n.fa-pulse {\n -webkit-animation: fa-spin 1s infinite steps(8);\n animation: fa-spin 1s infinite steps(8); }\n\n@-webkit-keyframes fa-spin {\n 0% {\n -webkit-transform: rotate(0deg);\n transform: rotate(0deg); }\n 100% {\n -webkit-transform: rotate(360deg);\n transform: rotate(360deg); } }\n\n@keyframes fa-spin {\n 0% {\n -webkit-transform: rotate(0deg);\n transform: rotate(0deg); }\n 100% {\n -webkit-transform: rotate(360deg);\n transform: rotate(360deg); } }\n\n.fa-rotate-90 {\n -ms-filter: \"progid:DXImageTransform.Microsoft.BasicImage(rotation=1)\";\n -webkit-transform: rotate(90deg);\n transform: rotate(90deg); }\n\n.fa-rotate-180 {\n -ms-filter: \"progid:DXImageTransform.Microsoft.BasicImage(rotation=2)\";\n -webkit-transform: rotate(180deg);\n transform: rotate(180deg); }\n\n.fa-rotate-270 {\n -ms-filter: \"progid:DXImageTransform.Microsoft.BasicImage(rotation=3)\";\n -webkit-transform: rotate(270deg);\n transform: rotate(270deg); }\n\n.fa-flip-horizontal {\n -ms-filter: \"progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1)\";\n -webkit-transform: scale(-1, 1);\n transform: scale(-1, 1); }\n\n.fa-flip-vertical {\n -ms-filter: \"progid:DXImageTransform.Microsoft.BasicImage(rotation=2, mirror=1)\";\n -webkit-transform: scale(1, -1);\n transform: scale(1, -1); }\n\n:root .fa-rotate-90,\n:root .fa-rotate-180,\n:root .fa-rotate-270,\n:root .fa-flip-horizontal,\n:root .fa-flip-vertical {\n -webkit-filter: none;\n filter: none; }\n\n.fa-stack {\n display: inline-block;\n height: 2em;\n position: relative;\n width: 2em; }\n\n.fa-stack-1x,\n.fa-stack-2x {\n bottom: 0;\n left: 0;\n margin: auto;\n position: absolute;\n right: 0;\n top: 0; }\n\n.svg-inline--fa.fa-stack-1x {\n height: 1em;\n width: 1em; }\n\n.svg-inline--fa.fa-stack-2x {\n height: 2em;\n width: 2em; }\n\n.fa-inverse {\n color: #fff; }\n\n.sr-only {\n border: 0;\n clip: rect(0, 0, 0, 0);\n height: 1px;\n margin: -1px;\n overflow: hidden;\n padding: 0;\n position: absolute;\n width: 1px; }\n\n.sr-only-focusable:active, .sr-only-focusable:focus {\n clip: auto;\n height: auto;\n margin: 0;\n overflow: visible;\n position: static;\n width: auto; }\n";
var styles = function () {
var dfp = DEFAULT_FAMILY_PREFIX;
var drc = DEFAULT_REPLACEMENT_CLASS;
var fp = config.familyPrefix;
var rc = config.replacementClass;
var s = baseStyles;
if (fp !== dfp || rc !== drc) {
var dPatt = new RegExp('\\.' + dfp + '\\-', 'g');
var rPatt = new RegExp('\\.' + drc, 'g');
s = s.replace(dPatt, '.' + fp + '-').replace(rPatt, '.' + rc);
}
return s;
};
function prepIcon(icon) {
var width = icon[0];
var height = icon[1];
var vectorData = icon.slice(4);
return {
found: true,
width: width,
height: height,
icon: { tag: 'path', attributes: { fill: 'currentColor', d: vectorData[0] } }
};
}
var _stylesInserted = false;
function ensureStyles() {
if (!config.autoAddCss) {
return;
}
if (!_stylesInserted) {
insertStyle(styles());
}
_stylesInserted = true;
}
function apiObject(val, abstractCreator) {
Object.defineProperty(val, 'abstract', {
get: abstractCreator
});
Object.defineProperty(val, 'html', {
get: function get$$1() {
return val.abstract.map(function (a) {
return toHtml(a);
});
}
});
Object.defineProperty(val, 'node', {
get: function get$$1() {
if (!DOCUMENT.createElement) return;
var container = DOCUMENT.createElement('div');
container.innerHTML = val.html;
return container.children;
}
});
return val;
}
var api = {
dom: {
i2svg: function i2svg() {
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
ensureStyles();
var _params$node = params.node,
node = _params$node === undefined ? DOCUMENT : _params$node,
_params$callback = params.callback,
callback = _params$callback === undefined ? function () {} : _params$callback;
onTree(node, callback);
},
styles: styles,
insertStyles: function insertStyles() {
insertStyle(styles());
}
},
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]
};
}
}
},
icon: function icon(iconDefinition) {
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var _params$transform = params.transform,
transform = _params$transform === undefined ? meaninglessTransform : _params$transform,
_params$compose = params.compose,
compose = _params$compose === undefined ? null : _params$compose,
_params$title = params.title,
title = _params$title === undefined ? null : _params$title,
_params$classes = params.classes,
classes = _params$classes === undefined ? [] : _params$classes,
_params$attributes = params.attributes,
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;
return apiObject(_extends({ type: 'icon' }, iconDefinition), function () {
ensureStyles();
if (config.autoA11y) {
if (title) {
attributes['aria-labelledby'] = config.replacementClass + '-title-' + nextUniqueId();
} else {
attributes['aria-hidden'] = 'true';
}
}
return makeInlineSvgAbstract({
icons: {
main: prepIcon(icon),
compose: compose ? prepIcon(compose.icon) : { found: false, width: null, height: null, icon: {} }
},
prefix: prefix,
iconName: iconName,
transform: _extends({}, meaninglessTransform, transform),
title: title,
extra: {
attributes: attributes,
style: style,
classes: classes
}
});
});
},
text: function text(content) {
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var _params$transform2 = params.transform,
transform = _params$transform2 === undefined ? meaninglessTransform : _params$transform2,
_params$title2 = params.title,
title = _params$title2 === undefined ? null : _params$title2,
_params$classes2 = params.classes,
classes = _params$classes2 === undefined ? [] : _params$classes2,
_params$attributes2 = params.attributes,
attributes = _params$attributes2 === undefined ? {} : _params$attributes2,
_params$style2 = params.style,
style = _params$style2 === undefined ? {} : _params$style2;
return apiObject({ type: 'text', content: content }, function () {
ensureStyles();
return makeLayersTextAbstract({
content: content,
transform: _extends({}, meaninglessTransform, transform),
title: title,
extra: {
attributes: attributes,
style: style,
classes: [config.familyPrefix + '-layers-text'].concat(toConsumableArray(classes))
}
});
});
},
layer: function layer(assembler) {
return apiObject({ type: 'layer' }, function () {
ensureStyles();
var children = [];
assembler(function (args) {
Array.isArray(args) ? children = args.map(function (a) {
children = children.concat(a.abstract);
}) : children = children.concat(args.abstract);
});
return [{
tag: 'span',
attributes: { class: config.familyPrefix + '-layers' },
children: children
}];
});
}
};
Object.defineProperty(api, 'config', {
get: function get$$1() {
var autoReplaceSvg = config.autoReplaceSvg,
observeMutations = config.observeMutations,
showMissingIcons = config.showMissingIcons,
rest = objectWithoutProperties(config, ['autoReplaceSvg', 'observeMutations', 'showMissingIcons']);
return rest;
},
set: function set$$1(newConfig) {
update(newConfig);
}
});
bunker(function () {
var autoReplace = function autoReplace() {
if (config.autoReplaceSvg) api.dom.i2svg({ node: DOCUMENT });
};
if (IS_BROWSER) {
if (!WINDOW.FontAwesome) {
WINDOW.FontAwesome = api;
}
domready(function () {
if (Object.keys(namespace.packs).length > 0) {
autoReplace();
}
if (config.observeMutations && typeof MutationObserver === 'function') {
observe({ treeCallback: onTree, nodeCallback: onNode });
}
});
}
namespace.hooks = _extends({}, namespace.hooks, {
addPack: function addPack(prefix, icons) {
namespace.packs[prefix] = _extends({}, namespace.packs[prefix] || {}, icons);
build();
autoReplace();
},
addShims: function addShims(shims) {
var _namespace$shims;
(_namespace$shims = namespace.shims).push.apply(_namespace$shims, toConsumableArray(shims));
build();
autoReplace();
}
});
});
}());