1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@fortawesome/fontawesome-svg-core'), require('prop-types'), require('react')) :
|
3 | typeof define === 'function' && define.amd ? define(['exports', '@fortawesome/fontawesome-svg-core', 'prop-types', 'react'], factory) :
|
4 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["react-fontawesome"] = {}, global.FontAwesome, global.PropTypes, global.React));
|
5 | })(this, (function (exports, fontawesomeSvgCore, PropTypes, React) { 'use strict';
|
6 |
|
7 | function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
8 |
|
9 | var PropTypes__default = _interopDefaultLegacy(PropTypes);
|
10 | var React__default = _interopDefaultLegacy(React);
|
11 |
|
12 | function ownKeys(object, enumerableOnly) {
|
13 | var keys = Object.keys(object);
|
14 |
|
15 | if (Object.getOwnPropertySymbols) {
|
16 | var symbols = Object.getOwnPropertySymbols(object);
|
17 | enumerableOnly && (symbols = symbols.filter(function (sym) {
|
18 | return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
19 | })), keys.push.apply(keys, symbols);
|
20 | }
|
21 |
|
22 | return keys;
|
23 | }
|
24 |
|
25 | function _objectSpread2(target) {
|
26 | for (var i = 1; i < arguments.length; i++) {
|
27 | var source = null != arguments[i] ? arguments[i] : {};
|
28 | i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
29 | _defineProperty(target, key, source[key]);
|
30 | }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
31 | Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
32 | });
|
33 | }
|
34 |
|
35 | return target;
|
36 | }
|
37 |
|
38 | function _typeof(obj) {
|
39 | "@babel/helpers - typeof";
|
40 |
|
41 | return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
42 | return typeof obj;
|
43 | } : function (obj) {
|
44 | return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
45 | }, _typeof(obj);
|
46 | }
|
47 |
|
48 | function _defineProperty(obj, key, value) {
|
49 | if (key in obj) {
|
50 | Object.defineProperty(obj, key, {
|
51 | value: value,
|
52 | enumerable: true,
|
53 | configurable: true,
|
54 | writable: true
|
55 | });
|
56 | } else {
|
57 | obj[key] = value;
|
58 | }
|
59 |
|
60 | return obj;
|
61 | }
|
62 |
|
63 | function _objectWithoutPropertiesLoose(source, excluded) {
|
64 | if (source == null) return {};
|
65 | var target = {};
|
66 | var sourceKeys = Object.keys(source);
|
67 | var key, i;
|
68 |
|
69 | for (i = 0; i < sourceKeys.length; i++) {
|
70 | key = sourceKeys[i];
|
71 | if (excluded.indexOf(key) >= 0) continue;
|
72 | target[key] = source[key];
|
73 | }
|
74 |
|
75 | return target;
|
76 | }
|
77 |
|
78 | function _objectWithoutProperties(source, excluded) {
|
79 | if (source == null) return {};
|
80 |
|
81 | var target = _objectWithoutPropertiesLoose(source, excluded);
|
82 |
|
83 | var key, i;
|
84 |
|
85 | if (Object.getOwnPropertySymbols) {
|
86 | var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
87 |
|
88 | for (i = 0; i < sourceSymbolKeys.length; i++) {
|
89 | key = sourceSymbolKeys[i];
|
90 | if (excluded.indexOf(key) >= 0) continue;
|
91 | if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
92 | target[key] = source[key];
|
93 | }
|
94 | }
|
95 |
|
96 | return target;
|
97 | }
|
98 |
|
99 | function _toConsumableArray(arr) {
|
100 | return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
101 | }
|
102 |
|
103 | function _arrayWithoutHoles(arr) {
|
104 | if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
105 | }
|
106 |
|
107 | function _iterableToArray(iter) {
|
108 | if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
109 | }
|
110 |
|
111 | function _unsupportedIterableToArray(o, minLen) {
|
112 | if (!o) return;
|
113 | if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
114 | var n = Object.prototype.toString.call(o).slice(8, -1);
|
115 | if (n === "Object" && o.constructor) n = o.constructor.name;
|
116 | if (n === "Map" || n === "Set") return Array.from(o);
|
117 | if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
118 | }
|
119 |
|
120 | function _arrayLikeToArray(arr, len) {
|
121 | if (len == null || len > arr.length) len = arr.length;
|
122 |
|
123 | for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
124 |
|
125 | return arr2;
|
126 | }
|
127 |
|
128 | function _nonIterableSpread() {
|
129 | throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
130 | }
|
131 |
|
132 |
|
133 | function classList(props) {
|
134 | var _classes;
|
135 |
|
136 | var beat = props.beat,
|
137 | fade = props.fade,
|
138 | beatFade = props.beatFade,
|
139 | bounce = props.bounce,
|
140 | shake = props.shake,
|
141 | flash = props.flash,
|
142 | spin = props.spin,
|
143 | spinPulse = props.spinPulse,
|
144 | spinReverse = props.spinReverse,
|
145 | pulse = props.pulse,
|
146 | fixedWidth = props.fixedWidth,
|
147 | inverse = props.inverse,
|
148 | border = props.border,
|
149 | listItem = props.listItem,
|
150 | flip = props.flip,
|
151 | size = props.size,
|
152 | rotation = props.rotation,
|
153 | pull = props.pull;
|
154 |
|
155 | var classes = (_classes = {
|
156 | 'fa-beat': beat,
|
157 | 'fa-fade': fade,
|
158 | 'fa-beat-fade': beatFade,
|
159 | 'fa-bounce': bounce,
|
160 | 'fa-shake': shake,
|
161 | 'fa-flash': flash,
|
162 | 'fa-spin': spin,
|
163 | 'fa-spin-reverse': spinReverse,
|
164 | 'fa-spin-pulse': spinPulse,
|
165 | 'fa-pulse': pulse,
|
166 | 'fa-fw': fixedWidth,
|
167 | 'fa-inverse': inverse,
|
168 | 'fa-border': border,
|
169 | 'fa-li': listItem,
|
170 | 'fa-flip': flip === true,
|
171 | 'fa-flip-horizontal': flip === 'horizontal' || flip === 'both',
|
172 | 'fa-flip-vertical': flip === 'vertical' || flip === 'both'
|
173 | }, _defineProperty(_classes, "fa-".concat(size), typeof size !== 'undefined' && size !== null), _defineProperty(_classes, "fa-rotate-".concat(rotation), typeof rotation !== 'undefined' && rotation !== null && rotation !== 0), _defineProperty(_classes, "fa-pull-".concat(pull), typeof pull !== 'undefined' && pull !== null), _defineProperty(_classes, 'fa-swap-opacity', props.swapOpacity), _classes);
|
174 |
|
175 |
|
176 | return Object.keys(classes).map(function (key) {
|
177 | return classes[key] ? key : null;
|
178 | }).filter(function (key) {
|
179 | return key;
|
180 | });
|
181 | }
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 | function _isNumerical(obj) {
|
188 | obj = obj - 0;
|
189 |
|
190 | return obj === obj;
|
191 | }
|
192 |
|
193 | function camelize(string) {
|
194 | if (_isNumerical(string)) {
|
195 | return string;
|
196 | }
|
197 |
|
198 |
|
199 | string = string.replace(/[\-_\s]+(.)?/g, function (match, chr) {
|
200 | return chr ? chr.toUpperCase() : '';
|
201 | });
|
202 |
|
203 | return string.substr(0, 1).toLowerCase() + string.substr(1);
|
204 | }
|
205 |
|
206 | var _excluded$1 = ["style"];
|
207 |
|
208 | function capitalize(val) {
|
209 | return val.charAt(0).toUpperCase() + val.slice(1);
|
210 | }
|
211 |
|
212 | function styleToObject(style) {
|
213 | return style.split(';').map(function (s) {
|
214 | return s.trim();
|
215 | }).filter(function (s) {
|
216 | return s;
|
217 | }).reduce(function (acc, pair) {
|
218 | var i = pair.indexOf(':');
|
219 | var prop = camelize(pair.slice(0, i));
|
220 | var value = pair.slice(i + 1).trim();
|
221 | prop.startsWith('webkit') ? acc[capitalize(prop)] = value : acc[prop] = value;
|
222 | return acc;
|
223 | }, {});
|
224 | }
|
225 |
|
226 | function convert(createElement, element) {
|
227 | var extraProps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
228 |
|
229 | if (typeof element === 'string') {
|
230 | return element;
|
231 | }
|
232 |
|
233 | var children = (element.children || []).map(function (child) {
|
234 | return convert(createElement, child);
|
235 | });
|
236 |
|
237 |
|
238 | var mixins = Object.keys(element.attributes || {}).reduce(function (acc, key) {
|
239 | var val = element.attributes[key];
|
240 |
|
241 | switch (key) {
|
242 | case 'class':
|
243 | acc.attrs['className'] = val;
|
244 | delete element.attributes['class'];
|
245 | break;
|
246 |
|
247 | case 'style':
|
248 | acc.attrs['style'] = styleToObject(val);
|
249 | break;
|
250 |
|
251 | default:
|
252 | if (key.indexOf('aria-') === 0 || key.indexOf('data-') === 0) {
|
253 | acc.attrs[key.toLowerCase()] = val;
|
254 | } else {
|
255 | acc.attrs[camelize(key)] = val;
|
256 | }
|
257 |
|
258 | }
|
259 |
|
260 | return acc;
|
261 | }, {
|
262 | attrs: {}
|
263 | });
|
264 |
|
265 | var _extraProps$style = extraProps.style,
|
266 | existingStyle = _extraProps$style === void 0 ? {} : _extraProps$style,
|
267 | remaining = _objectWithoutProperties(extraProps, _excluded$1);
|
268 |
|
269 | mixins.attrs['style'] = _objectSpread2(_objectSpread2({}, mixins.attrs['style']), existingStyle);
|
270 |
|
271 |
|
272 | return createElement.apply(void 0, [element.tag, _objectSpread2(_objectSpread2({}, mixins.attrs), remaining)].concat(_toConsumableArray(children)));
|
273 | }
|
274 |
|
275 | var PRODUCTION = false;
|
276 |
|
277 | try {
|
278 | PRODUCTION = process.env.NODE_ENV === 'production';
|
279 | } catch (e) {}
|
280 |
|
281 | function log () {
|
282 | if (!PRODUCTION && console && typeof console.error === 'function') {
|
283 | var _console;
|
284 |
|
285 | (_console = console).error.apply(_console, arguments);
|
286 | }
|
287 | }
|
288 |
|
289 | function normalizeIconArgs(icon) {
|
290 |
|
291 |
|
292 | if (icon && _typeof(icon) === 'object' && icon.prefix && icon.iconName && icon.icon) {
|
293 | return icon;
|
294 | }
|
295 |
|
296 | if (fontawesomeSvgCore.parse.icon) {
|
297 | return fontawesomeSvgCore.parse.icon(icon);
|
298 | }
|
299 |
|
300 |
|
301 | if (icon === null) {
|
302 | return null;
|
303 | }
|
304 |
|
305 |
|
306 | if (icon && _typeof(icon) === 'object' && icon.prefix && icon.iconName) {
|
307 | return icon;
|
308 | }
|
309 |
|
310 |
|
311 | if (Array.isArray(icon) && icon.length === 2) {
|
312 |
|
313 | return {
|
314 | prefix: icon[0],
|
315 | iconName: icon[1]
|
316 | };
|
317 | }
|
318 |
|
319 |
|
320 | if (typeof icon === 'string') {
|
321 | return {
|
322 | prefix: 'fas',
|
323 | iconName: icon
|
324 | };
|
325 | }
|
326 | }
|
327 |
|
328 |
|
329 |
|
330 |
|
331 | function objectWithKey(key, value) {
|
332 |
|
333 |
|
334 |
|
335 |
|
336 | return Array.isArray(value) && value.length > 0 || !Array.isArray(value) && value ? _defineProperty({}, key, value) : {};
|
337 | }
|
338 |
|
339 | var _excluded = ["forwardedRef"];
|
340 | function FontAwesomeIcon(_ref) {
|
341 | var forwardedRef = _ref.forwardedRef,
|
342 | props = _objectWithoutProperties(_ref, _excluded);
|
343 |
|
344 | var iconArgs = props.icon,
|
345 | maskArgs = props.mask,
|
346 | symbol = props.symbol,
|
347 | className = props.className,
|
348 | title = props.title,
|
349 | titleId = props.titleId,
|
350 | maskId = props.maskId;
|
351 | var iconLookup = normalizeIconArgs(iconArgs);
|
352 | var classes = objectWithKey('classes', [].concat(_toConsumableArray(classList(props)), _toConsumableArray(className.split(' '))));
|
353 | var transform = objectWithKey('transform', typeof props.transform === 'string' ? fontawesomeSvgCore.parse.transform(props.transform) : props.transform);
|
354 | var mask = objectWithKey('mask', normalizeIconArgs(maskArgs));
|
355 | var renderedIcon = fontawesomeSvgCore.icon(iconLookup, _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, classes), transform), mask), {}, {
|
356 | symbol: symbol,
|
357 | title: title,
|
358 | titleId: titleId,
|
359 | maskId: maskId
|
360 | }));
|
361 |
|
362 | if (!renderedIcon) {
|
363 | log('Could not find icon', iconLookup);
|
364 | return null;
|
365 | }
|
366 |
|
367 | var abstract = renderedIcon.abstract;
|
368 | var extraProps = {
|
369 | ref: forwardedRef
|
370 | };
|
371 | Object.keys(props).forEach(function (key) {
|
372 |
|
373 | if (!FontAwesomeIcon.defaultProps.hasOwnProperty(key)) {
|
374 | extraProps[key] = props[key];
|
375 | }
|
376 | });
|
377 | return convertCurry(abstract[0], extraProps);
|
378 | }
|
379 | FontAwesomeIcon.displayName = 'FontAwesomeIcon';
|
380 | FontAwesomeIcon.propTypes = {
|
381 | beat: PropTypes__default["default"].bool,
|
382 | border: PropTypes__default["default"].bool,
|
383 | beatFade: PropTypes__default["default"].bool,
|
384 | bounce: PropTypes__default["default"].bool,
|
385 | className: PropTypes__default["default"].string,
|
386 | fade: PropTypes__default["default"].bool,
|
387 | flash: PropTypes__default["default"].bool,
|
388 | mask: PropTypes__default["default"].oneOfType([PropTypes__default["default"].object, PropTypes__default["default"].array, PropTypes__default["default"].string]),
|
389 | maskId: PropTypes__default["default"].string,
|
390 | fixedWidth: PropTypes__default["default"].bool,
|
391 | inverse: PropTypes__default["default"].bool,
|
392 | flip: PropTypes__default["default"].oneOf([true, false, 'horizontal', 'vertical', 'both']),
|
393 | icon: PropTypes__default["default"].oneOfType([PropTypes__default["default"].object, PropTypes__default["default"].array, PropTypes__default["default"].string]),
|
394 | listItem: PropTypes__default["default"].bool,
|
395 | pull: PropTypes__default["default"].oneOf(['right', 'left']),
|
396 | pulse: PropTypes__default["default"].bool,
|
397 | rotation: PropTypes__default["default"].oneOf([0, 90, 180, 270]),
|
398 | shake: PropTypes__default["default"].bool,
|
399 | size: PropTypes__default["default"].oneOf(['2xs', 'xs', 'sm', 'lg', 'xl', '2xl', '1x', '2x', '3x', '4x', '5x', '6x', '7x', '8x', '9x', '10x']),
|
400 | spin: PropTypes__default["default"].bool,
|
401 | spinPulse: PropTypes__default["default"].bool,
|
402 | spinReverse: PropTypes__default["default"].bool,
|
403 | symbol: PropTypes__default["default"].oneOfType([PropTypes__default["default"].bool, PropTypes__default["default"].string]),
|
404 | title: PropTypes__default["default"].string,
|
405 | titleId: PropTypes__default["default"].string,
|
406 | transform: PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].object]),
|
407 | swapOpacity: PropTypes__default["default"].bool
|
408 | };
|
409 | FontAwesomeIcon.defaultProps = {
|
410 | border: false,
|
411 | className: '',
|
412 | mask: null,
|
413 | maskId: null,
|
414 | fixedWidth: false,
|
415 | inverse: false,
|
416 | flip: false,
|
417 | icon: null,
|
418 | listItem: false,
|
419 | pull: null,
|
420 | pulse: false,
|
421 | rotation: null,
|
422 | size: null,
|
423 | spin: false,
|
424 | spinPulse: false,
|
425 | spinReverse: false,
|
426 | beat: false,
|
427 | fade: false,
|
428 | beatFade: false,
|
429 | bounce: false,
|
430 | shake: false,
|
431 | symbol: false,
|
432 | title: '',
|
433 | titleId: null,
|
434 | transform: null,
|
435 | swapOpacity: false
|
436 | };
|
437 | var convertCurry = convert.bind(null, React__default["default"].createElement);
|
438 |
|
439 | exports.FontAwesomeIcon = FontAwesomeIcon;
|
440 |
|
441 | Object.defineProperty(exports, '__esModule', { value: true });
|
442 |
|
443 | }));
|